Google.ProtocolBuffersLite
Implementation of the non-generic IMessage interface as far as possible.
Interface implemented by Protocol Message builders.
TODO(jonskeet): Consider "SetXXX" methods returning the builder, as well as the properties.
Type of message
Type of builder
Non-generic interface for all members whose signatures don't require knowledge of
the type being built. The generic interface extends this one. Some methods return
either an IBuilder or an IMessage; in these cases the generic interface redeclares
the same method with a type-specific signature. Implementations are encouraged to
use explicit interface implemenation for the non-generic form. This mirrors
how IEnumerable and IEnumerable<T> work.
Returns true iff all required fields in the message and all
embedded messages are set.
Resets all fields to their default values.
Merge the specified other message which may be a different implementation of
the same message descriptor.
Constructs the final message. Once this is called, this Builder instance
is no longer valid, and calling any other method may throw a
NullReferenceException. If you need to continue working with the builder
after calling Build, call Clone first.
the message
is missing one or more required fields; use BuildPartial to bypass
this check
Like Build(), but does not throw an exception if the message is missing
required fields. Instead, a partial message is returned.
Clones this builder.
TODO(jonskeet): Explain depth of clone.
Like MergeFrom(ICodedInputStream), but also parses extensions.
The extensions that you want to be able to parse must be registered
in . Extensions not in the registry
will be treated as unknown fields.
Like MergeFrom(Stream), but does not read until the end of the file.
Instead, the size of the message (encoded as a varint) is read first,
then the message data. Use Message.WriteDelimitedTo(Stream) to
write messages in this format.
Like MergeDelimitedFrom(Stream) but supporting extensions.
Parse as a message of this type and merge
it with the message being built. This is just a small wrapper around
MergeFrom(ICodedInputStream).
Parse as a message of this type and merge
it with the message being built. This is just a small wrapper around
MergeFrom(ICodedInputStream, ExtensionRegistry).
Parse as a message of this type and merge
it with the message being built. This is just a small wrapper around
MergeFrom(ICodedInputStream).
Parse as a message of this type and merge
it with the message being built. This is just a small wrapper around
MergeFrom(ICodedInputStream, ExtensionRegistry).
Parse as a message of this type and merge
it with the message being built. This is just a small wrapper around
MergeFrom(ICodedInputStream). Note that this method always reads
the entire input (unless it throws an exception). If you want it to
stop earlier, you will need to wrap the input in a wrapper
stream which limits reading. Or, use IMessage.WriteDelimitedTo(Stream)
to write your message and MmergeDelimitedFrom(Stream) to read it.
Despite usually reading the entire stream, this method never closes the stream.
Parse as a message of this type and merge
it with the message being built. This is just a small wrapper around
MergeFrom(ICodedInputStream, ExtensionRegistry).
Get's the message's type's default instance.
Stream implementation which proxies another stream, only allowing a certain amount
of data to be read. Note that this is only used to read delimited streams, so it
doesn't attempt to implement everything.
Implementation of the non-generic IMessage interface as far as possible.
Type-safe interface for all generated messages to implement.
Non-generic interface used for all parts of the API which don't require
any type knowledge.
Serializes the message and writes it to the given output stream.
This does not flush or close the stream.
Protocol Buffers are not self-delimiting. Therefore, if you write
any more data to the stream after the message, you must somehow ensure
that the parser on the receiving end does not interpret this as being
part of the protocol message. One way of doing this is by writing the size
of the message before the data, then making sure you limit the input to
that size when receiving the data. Alternatively, use WriteDelimitedTo(Stream).
Like WriteTo(Stream) but writes the size of the message as a varint before
writing the data. This allows more data to be written to the stream after the
message without the need to delimit the message data yourself. Use
IBuilder.MergeDelimitedFrom(Stream) or the static method
YourMessageType.ParseDelimitedFrom(Stream) to parse messages written by this method.
Compares the specified object with this message for equality.
Returns true iff the given object is a message of the same type
(as defined by DescriptorForType) and has identical values
for all its fields.
Returns the hash code value for this message.
TODO(jonskeet): Specify the hash algorithm, but better than the Java one!
Converts the message to a string in protocol buffer text format.
This is just a trivial wrapper around TextFormat.PrintToString.
Converts the message to a string.
Serializes the message to a ByteString. This is a trivial wrapper
around WriteTo(ICodedOutputStream).
Serializes the message to a byte array. This is a trivial wrapper
around WriteTo(ICodedOutputStream).
Serializes the message and writes it to the given stream.
This is just a wrapper around WriteTo(ICodedOutputStream). This
does not flush or close the stream.
Creates a builder for the type, but in a weakly typed manner. This
is typically implemented by strongly typed messages by just returning
the result of CreateBuilderForType.
Creates a builder with the same contents as this message. This
is typically implemented by strongly typed messages by just returning
the result of ToBuilder.
Returns true iff all required fields in the message and all embedded
messages are set.
Returns the number of bytes required to encode this message.
The result is only computed on the first call and memoized after that.
Returns an instance of this message type with all fields set to
their default values. This may or may not be a singleton. This differs
from the DefaultInstance property of each generated message class in that this
method is an abstract method of IMessage whereas DefaultInstance is
a static property of a specific class. They return the same thing.
Constructs a new builder for a message of the same type as this message.
Creates a builder with the same contents as this current instance.
This is typically implemented by strongly typed messages by just
returning the result of ToBuilder().
Serializes the message to a ByteString. This is a trivial wrapper
around WriteTo(ICodedOutputStream).
Serializes the message to a byte array. This is a trivial wrapper
around WriteTo(ICodedOutputStream).
Serializes the message and writes it to the given stream.
This is just a wrapper around WriteTo(CodedOutputStream). This
does not flush or close the stream.
Like WriteTo(Stream) but writes the size of the message as a varint before
writing the data. This allows more data to be written to the stream after the
message without the need to delimit the message data yourself. Use
IBuilder.MergeDelimitedFrom(Stream) or the static method
YourMessageType.ParseDelimitedFrom(Stream) to parse messages written by this method.
Provides a utility routine to copy small arrays much more quickly than Buffer.BlockCopy
The threshold above which you should use Buffer.BlockCopy rather than ByteArray.Copy
Determines which copy routine to use based on the number of bytes to be copied.
Copy the bytes provided with a for loop, faster when there are only a few bytes to copy
Reverses the order of bytes in the array
Encodes and writes protocol message fields.
This class contains two kinds of methods: methods that write specific
protocol message constructs and field types (e.g. WriteTag and
WriteInt32) and methods that write low-level values (e.g.
WriteRawVarint32 and WriteRawBytes). If you are writing encoded protocol
messages, you should use the former methods, but if you are writing some
other format of your own design, use the latter. The names of the former
methods are taken from the protocol buffer type names, not .NET types.
(Hence WriteFloat instead of WriteSingle, and WriteBool instead of WriteBoolean.)
Provides an interface that is used write a message. Most often proto buffers are written
in their binary form by creating a instance via the CodedOutputStream.CreateInstance
static factory.
Writes any message initialization data needed to the output stream
This is primarily used by text formats and unnecessary for protobuffers' own
binary format. The API for MessageStart/End was added for consistent handling
of output streams regardless of the actual writer implementation.
Writes any message finalization data needed to the output stream
This is primarily used by text formats and unnecessary for protobuffers' own
binary format. The API for MessageStart/End was added for consistent handling
of output streams regardless of the actual writer implementation.
Indicates that all temporary buffers be written to the final output.
Writes an unknown message as a group
Writes an unknown field value of bytes
Writes an unknown field of a primitive type
Writes an extension as a message-set group
Writes an unknown extension as a message-set group
Writes a field value, including tag, to the stream.
Writes a double field value, including tag, to the stream.
Writes a float field value, including tag, to the stream.
Writes a uint64 field value, including tag, to the stream.
Writes an int64 field value, including tag, to the stream.
Writes an int32 field value, including tag, to the stream.
Writes a fixed64 field value, including tag, to the stream.
Writes a fixed32 field value, including tag, to the stream.
Writes a bool field value, including tag, to the stream.
Writes a string field value, including tag, to the stream.
Writes a group field value, including tag, to the stream.
Writes a message field value, including tag, to the stream.
Writes a byte array field value, including tag, to the stream.
Writes a UInt32 field value, including tag, to the stream.
Writes an enum field value, including tag, to the stream.
Writes a fixed 32-bit field value, including tag, to the stream.
Writes a signed fixed 64-bit field value, including tag, to the stream.
Writes a signed 32-bit field value, including tag, to the stream.
Writes a signed 64-bit field value, including tag, to the stream.
Writes a repeated field value, including tag(s), to the stream.
Writes a repeated group value, including tag(s), to the stream.
Writes a repeated message value, including tag(s), to the stream.
Writes a repeated string value, including tag(s), to the stream.
Writes a repeated ByteString value, including tag(s), to the stream.
Writes a repeated boolean value, including tag(s), to the stream.
Writes a repeated Int32 value, including tag(s), to the stream.
Writes a repeated SInt32 value, including tag(s), to the stream.
Writes a repeated UInt32 value, including tag(s), to the stream.
Writes a repeated Fixed32 value, including tag(s), to the stream.
Writes a repeated SFixed32 value, including tag(s), to the stream.
Writes a repeated Int64 value, including tag(s), to the stream.
Writes a repeated SInt64 value, including tag(s), to the stream.
Writes a repeated UInt64 value, including tag(s), to the stream.
Writes a repeated Fixed64 value, including tag(s), to the stream.
Writes a repeated SFixed64 value, including tag(s), to the stream.
Writes a repeated Double value, including tag(s), to the stream.
Writes a repeated Float value, including tag(s), to the stream.
Writes a repeated enumeration value of type T, including tag(s), to the stream.
Writes a packed repeated primitive, including tag and length, to the stream.
Writes a packed repeated boolean, including tag and length, to the stream.
Writes a packed repeated Int32, including tag and length, to the stream.
Writes a packed repeated SInt32, including tag and length, to the stream.
Writes a packed repeated UInt32, including tag and length, to the stream.
Writes a packed repeated Fixed32, including tag and length, to the stream.
Writes a packed repeated SFixed32, including tag and length, to the stream.
Writes a packed repeated Int64, including tag and length, to the stream.
Writes a packed repeated SInt64, including tag and length, to the stream.
Writes a packed repeated UInt64, including tag and length, to the stream.
Writes a packed repeated Fixed64, including tag and length, to the stream.
Writes a packed repeated SFixed64, including tag and length, to the stream.
Writes a packed repeated Double, including tag and length, to the stream.
Writes a packed repeated Float, including tag and length, to the stream.
Writes a packed repeated enumeration of type T, including tag and length, to the stream.
Compute the number of bytes that would be needed to encode a
double field, including the tag.
Compute the number of bytes that would be needed to encode a
float field, including the tag.
Compute the number of bytes that would be needed to encode a
uint64 field, including the tag.
Compute the number of bytes that would be needed to encode an
int64 field, including the tag.
Compute the number of bytes that would be needed to encode an
int32 field, including the tag.
Compute the number of bytes that would be needed to encode a
fixed64 field, including the tag.
Compute the number of bytes that would be needed to encode a
fixed32 field, including the tag.
Compute the number of bytes that would be needed to encode a
bool field, including the tag.
Compute the number of bytes that would be needed to encode a
string field, including the tag.
Compute the number of bytes that would be needed to encode a
group field, including the tag.
Compute the number of bytes that would be needed to encode a
group field represented by an UnknownFieldSet, including the tag.
Compute the number of bytes that would be needed to encode an
embedded message field, including the tag.
Compute the number of bytes that would be needed to encode a
bytes field, including the tag.
Compute the number of bytes that would be needed to encode a
uint32 field, including the tag.
Compute the number of bytes that would be needed to encode a
enum field, including the tag. The caller is responsible for
converting the enum value to its numeric value.
Compute the number of bytes that would be needed to encode an
sfixed32 field, including the tag.
Compute the number of bytes that would be needed to encode an
sfixed64 field, including the tag.
Compute the number of bytes that would be needed to encode an
sint32 field, including the tag.
Compute the number of bytes that would be needed to encode an
sint64 field, including the tag.
Compute the number of bytes that would be needed to encode a
double field, including the tag.
Compute the number of bytes that would be needed to encode a
float field, including the tag.
Compute the number of bytes that would be needed to encode a
uint64 field, including the tag.
Compute the number of bytes that would be needed to encode an
int64 field, including the tag.
Compute the number of bytes that would be needed to encode an
int32 field, including the tag.
Compute the number of bytes that would be needed to encode a
fixed64 field, including the tag.
Compute the number of bytes that would be needed to encode a
fixed32 field, including the tag.
Compute the number of bytes that would be needed to encode a
bool field, including the tag.
Compute the number of bytes that would be needed to encode a
string field, including the tag.
Compute the number of bytes that would be needed to encode a
group field, including the tag.
Compute the number of bytes that would be needed to encode a
group field represented by an UnknownFieldSet, including the tag.
Compute the number of bytes that would be needed to encode an
embedded message field, including the tag.
Compute the number of bytes that would be needed to encode a
bytes field, including the tag.
Compute the number of bytes that would be needed to encode a
uint32 field, including the tag.
Compute the number of bytes that would be needed to encode a
enum field, including the tag. The caller is responsible for
converting the enum value to its numeric value.
Compute the number of bytes that would be needed to encode an
sfixed32 field, including the tag.
Compute the number of bytes that would be needed to encode an
sfixed64 field, including the tag.
Compute the number of bytes that would be needed to encode an
sint32 field, including the tag.
Compute the number of bytes that would be needed to encode an
sint64 field, including the tag.
Compute the number of bytes that would be needed to encode a
MessageSet extension to the stream. For historical reasons,
the wire format differs from normal fields.
Compute the number of bytes that would be needed to encode an
unparsed MessageSet extension field to the stream. For
historical reasons, the wire format differs from normal fields.
Compute the number of bytes that would be needed to encode a varint.
Compute the number of bytes that would be needed to encode a varint.
Compute the number of bytes that would be needed to encode a
field of arbitrary type, including the tag, to the stream.
Compute the number of bytes that would be needed to encode a
field of arbitrary type, excluding the tag, to the stream.
Compute the number of bytes that would be needed to encode a tag.
The buffer size used by CreateInstance(Stream).
Creates a new CodedOutputStream which write to the given stream.
Creates a new CodedOutputStream which write to the given stream and uses
the specified buffer size.
Creates a new CodedOutputStream that writes directly to the given
byte array. If more bytes are written than fit in the array,
OutOfSpaceException will be thrown.
Creates a new CodedOutputStream that writes directly to the given
byte array slice. If more bytes are written than fit in the array,
OutOfSpaceException will be thrown.
Writes a double field value, including tag, to the stream.
Writes a float field value, including tag, to the stream.
Writes a uint64 field value, including tag, to the stream.
Writes an int64 field value, including tag, to the stream.
Writes an int32 field value, including tag, to the stream.
Writes a fixed64 field value, including tag, to the stream.
Writes a fixed32 field value, including tag, to the stream.
Writes a bool field value, including tag, to the stream.
Writes a string field value, including tag, to the stream.
Writes a group field value, including tag, to the stream.
Writes a double field value, including tag, to the stream.
Writes a float field value, without a tag, to the stream.
Writes a uint64 field value, without a tag, to the stream.
Writes an int64 field value, without a tag, to the stream.
Writes an int32 field value, without a tag, to the stream.
Writes a fixed64 field value, without a tag, to the stream.
Writes a fixed32 field value, without a tag, to the stream.
Writes a bool field value, without a tag, to the stream.
Writes a string field value, without a tag, to the stream.
Writes a group field value, without a tag, to the stream.
Encodes and writes a tag.
Writes a 32 bit value as a varint. The fast route is taken when
there's enough buffer space left to whizz through without checking
for each byte; otherwise, we resort to calling WriteRawByte each time.
Writes out an array of bytes.
Writes out part of an array of bytes.
Encode a 32-bit value with ZigZag encoding.
ZigZag encodes signed integers into values that can be efficiently
encoded with varint. (Otherwise, negative values must be
sign-extended to 64 bits to be varint encoded, thus always taking
10 bytes on the wire.)
Encode a 64-bit value with ZigZag encoding.
ZigZag encodes signed integers into values that can be efficiently
encoded with varint. (Otherwise, negative values must be
sign-extended to 64 bits to be varint encoded, thus always taking
10 bytes on the wire.)
Verifies that SpaceLeft returns zero. It's common to create a byte array
that is exactly big enough to hold a message, then write to it with
a CodedOutputStream. Calling CheckNoSpaceLeft after writing verifies that
the message was actually as big as expected, which can help bugs.
If writing to a flat array, returns the space left in the array. Otherwise,
throws an InvalidOperationException.
Indicates that a CodedOutputStream wrapping a flat byte array
ran out of space.
Utility class for dictionaries.
Compares two dictionaries for equality. Each value is compared with equality using Equals
for non-IEnumerable implementations, and using EnumerableEquals otherwise.
TODO(jonskeet): This is clearly pretty slow, and involves lots of boxing/unboxing...
Creates a hashcode for a dictionary by XORing the hashcodes of all the fields
and values. (By XORing, we avoid ordering issues.)
TODO(jonskeet): Currently XORs other stuff too, and assumes non-null values.
Determines the hash of a value by either taking it directly or hashing all the elements
for IEnumerable implementations.
Utility class for IEnumerable (and potentially the generic version in the future).
A list which has an Add method which accepts an IEnumerable[T].
This allows whole collections to be added easily using collection initializers.
It causes a potential overload confusion if T : IEnumerable[T], but in
practice that won't happen in protocol buffers.
This is only currently implemented by PopsicleList, and it's likely
to stay that way - hence the name. More genuinely descriptive names are
horribly ugly. (At least, the ones the author could think of...)
The element type of the list
Used to efficiently cast the elements of enumerations
Utility non-generic class for calling into Lists{T} using type inference.
Returns a read-only view of the specified list.
Utility class for dealing with lists.
Returns either the original reference if it's already read-only,
or a new ReadOnlyCollection wrapping the original list.
Returns an immutable empty list.
Proxies calls to a , but allows the list
to be made read-only (with the method),
after which any modifying methods throw .
Makes this list read-only ("freezes the popsicle"). From this
point on, mutating methods (Clear, Add etc) will throw a
NotSupportedException. There is no way of "defrosting" the list afterwards.
Read-only wrapper around another dictionary.
All generated protocol message classes extend this class. It implements
most of the IMessage interface using reflection. Users
can ignore this class as an implementation detail.
PrintTo() helper methods for Lite Runtime
PrintTo() helper methods for Lite Runtime
COPIED from TextFormat
Escapes bytes in the format used in protocol buffer text format, which
is the same as the format used for C string literals. All bytes
that are not printable 7-bit ASCII characters are escaped, as well as
backslash, single-quote, and double-quote characters. Characters for
which no defined short-hand escape sequence is defined will be escaped
using 3-digit octal sequences.
The returned value is guaranteed to be entirely ASCII.
writes the extensions to the text stream
Checks if a singular extension is present.
Returns the number of elements in a repeated extension.
Returns the value of an extension.
Returns one element of a repeated extension.
Access for the builder.
Called to check if all extensions are initialized.
Called by subclasses to compute the size of extensions.
Used by subclasses to serialize extensions. Extension ranges may be
interleaves with field numbers, but we must write them in canonical
(sorted by field number) order. This class helps us to write individual
ranges of extensions at once.
TODO(jonskeet): See if we can improve this in terms of readability.
All generated protocol message builder classes extend this class. It implements
most of the IBuilder interface using reflection. Users can ignore this class
as an implementation detail.
Called by derived classes to parse an unknown field.
true unless the tag is an end-group tag
Like Build(), but will wrap UninitializedMessageException in
InvalidProtocolBufferException.
Implementation of .
Returns the message being built at the moment.
Checks if a singular extension is present
Returns the number of elements in a repeated extension.
Returns the value of an extension.
Returns one element of a repeated extension.
Sets the value of an extension.
Sets the value of one element of a repeated extension.
Appends a value to a repeated extension.
Clears an extension.
Called by subclasses to parse an unknown field or an extension.
true unless the tag is an end-group tag
Defined specifically for the enumeration,
this allows each field type to specify the mapped type and wire type.
Immutable mapping from field type to mapped type. Built using the attributes on
FieldType values.
Enumeration of all the possible field types. The odd formatting is to make it very clear
which attribute applies to which value, while maintaining a compact format.
Type as it's mapped onto a .NET type.
Interface for an enum value or value descriptor, to be used in FieldSet.
The lite library stores enum values directly in FieldSets but the full
library stores EnumValueDescriptors in order to better support reflection.
Interface for an object which maps integers to {@link EnumLite}s.
{@link Descriptors.EnumDescriptor} implements this interface by mapping
numbers to {@link Descriptors.EnumValueDescriptor}s. Additionally,
every generated enum type has a static method internalGetValueMap() which
returns an implementation of this type that maps numbers to enum values.
A class which represents an arbitrary set of fields of some message type.
This is used to implement DynamicMessage, and also to represent extensions
in GeneratedMessage. This class is internal, since outside users should probably
be using DynamicMessage.
As in the Java implementation, this class goes against the rest of the framework
in terms of mutability. Instead of having a mutable Builder class and an immutable
FieldSet class, FieldSet just has a MakeImmutable() method. This is safe so long as
all callers are careful not to let a mutable FieldSet escape into the open. This would
be impossible to guarantee if this were a public class, of course.
All repeated fields are stored as IList[object] even
TODO(jonskeet): Finish this comment!
Makes this FieldSet immutable, and returns it for convenience. Any
mutable repeated fields are made immutable, as well as the map itself.
See .
Clears all fields.
See
Returns an enumerator for the field map. Used to write the fields out.
Verifies whether all the required fields in the specified message
descriptor are present in this field set, as well as whether
all the embedded messages are themselves initialized.
See
See
Implementation of both MergeFrom methods.
See .
Writes a single field to a CodedOutputStream.
Verifies that the given object is of the correct type to be a valid
value for the given field.
For repeated fields, this checks if the object is of the right
element type, not whether it's a list.
The value is not of the right type.
The value is null.
Returns the default, immutable instance with no fields defined.
Returns an immutable mapping of fields. Note that although the mapping itself
is immutable, the entries may not be (i.e. any repeated values are represented by
mutable lists). The behaviour is not specified if the contents are mutated.
See
If the field is not set, the behaviour when fetching this property varies by field type:
- For singular message values, null is returned.
- For singular non-message values, the default value of the field is returned.
- For repeated values, an empty immutable list is returned. This will be compatible
with IList[object], regardless of the type of the repeated item.
This method returns null if the field is a singular message type
and is not set; in this case it is up to the caller to fetch the
message's default instance. For repeated fields of message types,
an empty collection is returned. For repeated fields of non-message
types, null is returned.
When setting this property, any list values are copied, and each element is checked
to ensure it is of an appropriate type.
See
See
Since FieldSet itself does not have any way of knowing about
required fields that aren't actually present in the set, it is up
to the caller to check for genuinely required fields. This property
merely checks that any messages present are themselves initialized.
See . It's up to the caller to
cache the resulting size if desired.
Class containing helpful workarounds for various platform compatibility
This is not supported and assertions are made to ensure this does not exist on extensions of Lite types
For use by generated code only.
Repeating fields: For use by generated code only.
Converts from the type used by the native accessors to the type
used by reflection accessors. For example, the reflection accessors
for enums use EnumValueDescriptors but the native accessors use
the generated enum type.
Like ToReflectionType(object) but for a single element.
Returns information about this extension
Returns the default value for this extension
used for the extension registry
Default instance of the type being extended, used to identify that type.
Get the field number.
If the extension is an embedded message, this is the default instance of
that type.
Reads any message initialization data expected from the input stream
This is primarily used by text formats and unnecessary for protobuffers' own
binary format. The API for MessageStart/End was added for consistent handling
of output streams regardless of the actual writer implementation.
Reads any message finalization data expected from the input stream
This is primarily used by text formats and unnecessary for protobuffers' own
binary format. The API for MessageStart/End was added for consistent handling
of output streams regardless of the actual writer implementation.
Attempt to read a field tag, returning false if we have reached the end
of the input data.
If fieldTag is non-zero and ReadTag returns true then the value in fieldName
may or may not be populated. However, if fieldTag is zero and ReadTag returns
true, then fieldName should be populated with a non-null field name.
In other words if ReadTag returns true then either fieldTag will be non-zero OR
fieldName will be non-zero. In some cases both may be populated, however the
builders will always prefer the fieldTag over fieldName.
Read a double field from the stream.
Read a float field from the stream.
Read a uint64 field from the stream.
Read an int64 field from the stream.
Read an int32 field from the stream.
Read a fixed64 field from the stream.
Read a fixed32 field from the stream.
Read a bool field from the stream.
Reads a string field from the stream.
Reads a group field value from the stream.
Reads a group field value from the stream and merges it into the given
UnknownFieldSet.
Reads an embedded message field value from the stream.
Reads a bytes field value from the stream.
Reads a uint32 field value from the stream.
Reads an enum field value from the stream. The caller is responsible
for converting the numeric value to an actual enum.
Reads an enum field value from the stream. If the enum is valid for type T,
then the ref value is set and it returns true. Otherwise the unkown output
value is set and this method returns false.
Reads an sfixed32 field value from the stream.
Reads an sfixed64 field value from the stream.
Reads an sint32 field value from the stream.
Reads an sint64 field value from the stream.
Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed and the
type is numeric, it will read a packed array.
Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed, it will
read a packed array.
Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed, it will
read a packed array.
Reads a set of messages using the as a template. T is not guaranteed to be
the most derived type, it is only the type specifier for the collection.
Reads a set of messages using the as a template.
Reads a field of any primitive type. Enums, groups and embedded
messages are not handled by this method.
Reads and discards a single field, given its tag value.
false if the tag is an end-group tag, in which case
nothing is skipped. Otherwise, returns true.
Reads one or more repeated string field values from the stream.
Reads one or more repeated ByteString field values from the stream.
Reads one or more repeated boolean field values from the stream.
Reads one or more repeated Int32 field values from the stream.
Reads one or more repeated SInt32 field values from the stream.
Reads one or more repeated UInt32 field values from the stream.
Reads one or more repeated Fixed32 field values from the stream.
Reads one or more repeated SFixed32 field values from the stream.
Reads one or more repeated Int64 field values from the stream.
Reads one or more repeated SInt64 field values from the stream.
Reads one or more repeated UInt64 field values from the stream.
Reads one or more repeated Fixed64 field values from the stream.
Reads one or more repeated SFixed64 field values from the stream.
Reads one or more repeated Double field values from the stream.
Reads one or more repeated Float field values from the stream.
Returns true if the stream has reached the end of the input. This is the
case if either the end of the underlying input source has been reached or
the stream has reached a limit created using PushLimit.
Provides an entry-point for transport listeners to call a specified method on a service
Calls the method identified by methodName and returns the message
The method name on the service descriptor (case-sensitive)
The ICodedInputStream to deserialize the call parameter from
The extension registry to use when deserializing the call parameter
The message that was returned from the service's method
Used to forward an invocation of a service method to a transport sender implementation
Calls the service member on the endpoint connected. This is generally done by serializing
the message, sending the bytes over a transport, and then deserializing the call parameter
to invoke the service's actual implementation via IRpcServerStub. Once the call has
completed the result message is serialized and returned to the originating endpoint.
The type of the response message
The type of of the response builder
The name of the method on the service
The message instance provided to the service call
The builder used to deserialize the response
The resulting message of the service call
Immutable array of bytes.
TODO(jonskeet): Implement the common collection interfaces?
Internal use only. Ensure that the provided array is not mutated and belongs to this instance.
Constructs a new ByteString from the given byte array. The array is
*not* copied, and must not be modified after this constructor is called.
Constructs a ByteString from the Base64 Encoded String.
Constructs a ByteString from the given array. The contents
are copied, so further modifications to the array will not
be reflected in the returned ByteString.
Constructs a ByteString from a portion of a byte array.
Creates a new ByteString by encoding the specified text with
the given encoding.
Creates a new ByteString by encoding the specified text in UTF-8.
Creates a CodedInputStream from this ByteString's data.
Used internally by CodedOutputStream to avoid creating a copy for the write
Copies the entire byte array to the destination array provided at the offset specified.
Writes the entire byte array to the provided stream
Returns an empty ByteString.
Returns the length of this ByteString in bytes.
Retuns the byte at the given index.
Unsafe operations that can cause IO Failure and/or other catestrophic side-effects.
Constructs a new ByteString from the given byte array. The array is
*not* copied, and must not be modified after this constructor is called.
Provides direct, unrestricted access to the bytes contained in this instance.
You must not modify or resize the byte array returned by this method.
Builder for ByteStrings which allows them to be created without extra
copying being involved. This has to be a nested type in order to have access
to the private ByteString constructor.
Readings and decodes protocol message fields.
This class contains two kinds of methods: methods that read specific
protocol message constructs and field types (e.g. ReadTag and
ReadInt32) and methods that read low-level values (e.g.
ReadRawVarint32 and ReadRawBytes). If you are reading encoded protocol
messages, you should use the former methods, but if you are reading some
other format of your own design, use the latter. The names of the former
methods are taken from the protocol buffer type names, not .NET types.
(Hence ReadFloat instead of ReadSingle, and ReadBool instead of ReadBoolean.)
TODO(jonskeet): Consider whether recursion and size limits shouldn't be readonly,
set at construction time.
The total number of bytes read before the current buffer. The
total bytes read up to the current position can be computed as
totalBytesRetired + bufferPos.
The absolute position of the end of the current message.
Creates a new CodedInputStream reading data from the given
stream.
Creates a new CodedInputStream reading data from the given
stream and a pre-allocated memory buffer.
Creates a new CodedInputStream reading data from the given
byte array.
Creates a new CodedInputStream that reads from the given
byte array slice.
Verifies that the last call to ReadTag() returned the given tag value.
This is used to verify that a nested group ended with the correct
end tag.
The last
tag read was not the one specified
Attempt to peek at the next field tag.
Attempt to read a field tag, returning false if we have reached the end
of the input data.
The 'tag' of the field (id * 8 + wire-format)
Not Supported - For protobuffer streams, this parameter is always null
true if the next fieldTag was read
Read a double field from the stream.
Read a float field from the stream.
Read a uint64 field from the stream.
Read an int64 field from the stream.
Read an int32 field from the stream.
Read a fixed64 field from the stream.
Read a fixed32 field from the stream.
Read a bool field from the stream.
Reads a string field from the stream.
Reads a group field value from the stream.
Reads a group field value from the stream and merges it into the given
UnknownFieldSet.
Reads an embedded message field value from the stream.
Reads a bytes field value from the stream.
Reads a uint32 field value from the stream.
Reads an enum field value from the stream. The caller is responsible
for converting the numeric value to an actual enum.
Reads an enum field value from the stream. If the enum is valid for type T,
then the ref value is set and it returns true. Otherwise the unkown output
value is set and this method returns false.
Reads an sfixed32 field value from the stream.
Reads an sfixed64 field value from the stream.
Reads an sint32 field value from the stream.
Reads an sint64 field value from the stream.
Returns true if the next tag is also part of the same unpacked array.
Returns true if the next tag is also part of the same array, which may or may not be packed.
Reads a field of any primitive type. Enums, groups and embedded
messages are not handled by this method.
Same code as ReadRawVarint32, but read each byte individually, checking for
buffer overflow.
Read a raw Varint from the stream. If larger than 32 bits, discard the upper bits.
This method is optimised for the case where we've got lots of data in the buffer.
That means we can check the size just once, then just read directly from the buffer
without constant rechecking of the buffer length.
Reads a varint from the input one byte at a time, so that it does not
read any bytes after the end of the varint. If you simply wrapped the
stream in a CodedInputStream and used ReadRawVarint32(Stream)}
then you would probably end up reading past the end of the varint since
CodedInputStream buffers its input.
Read a raw varint from the stream.
Read a 32-bit little-endian integer from the stream.
Read a 64-bit little-endian integer from the stream.
Decode a 32-bit value with ZigZag encoding.
ZigZag encodes signed integers into values that can be efficiently
encoded with varint. (Otherwise, negative values must be
sign-extended to 64 bits to be varint encoded, thus always taking
10 bytes on the wire.)
Decode a 32-bit value with ZigZag encoding.
ZigZag encodes signed integers into values that can be efficiently
encoded with varint. (Otherwise, negative values must be
sign-extended to 64 bits to be varint encoded, thus always taking
10 bytes on the wire.)
Set the maximum message recursion depth.
In order to prevent malicious
messages from causing stack overflows, CodedInputStream limits
how deeply messages may be nested. The default limit is 64.
Set the maximum message size.
In order to prevent malicious messages from exhausting memory or
causing integer overflows, CodedInputStream limits how large a message may be.
The default limit is 64MB. You should set this limit as small
as you can without harming your app's functionality. Note that
size limits only apply when reading from an InputStream, not
when constructed around a raw byte array (nor with ByteString.NewCodedInput).
If you want to read several messages from a single CodedInputStream, you
can call ResetSizeCounter() after each message to avoid hitting the
size limit.
Resets the current size counter to zero (see SetSizeLimit).
Sets currentLimit to (current position) + byteLimit. This is called
when descending into a length-delimited embedded message. The previous
limit is returned.
The old limit.
Discards the current limit, returning the previous limit.
Called when buffer is empty to read more bytes from the
input. If is true, RefillBuffer() gurantees that
either there will be at least one byte in the buffer when it returns
or it will throw an exception. If is false,
RefillBuffer() returns false if no more bytes were available.
Read one byte from the input.
the end of the stream or the current limit was reached
Read a fixed size of bytes from the input.
the end of the stream or the current limit was reached
Reads and discards a single field, given its tag value.
false if the tag is an end-group tag, in which case
nothing is skipped. Otherwise, returns true.
Reads and discards an entire message. This will read either until EOF
or until an endgroup tag, whichever comes first.
Reads and discards bytes.
the end of the stream
or the current limit was reached
Abstraction of skipping to cope with streams which can't really skip.
Returns the current position in the input stream, or the position in the input buffer
Returns whether or not all the data before the limit has been read.
Returns true if the stream has reached the end of the input. This is the
case if either the end of the underlying input source has been reached or
the stream has reached a limit created using PushLimit.
A table of known extensions, searchable by name or field number. When
parsing a protocol message that might have extensions, you must provide
an in which you have registered any extensions
that you want to be able to parse. Otherwise, those extensions will just
be treated like unknown fields.
For example, if you had the .proto file:
option java_class = "MyProto";
message Foo {
extensions 1000 to max;
}
extend Foo {
optional int32 bar;
}
Then you might write code like:
extensionRegistry registry = extensionRegistry.CreateInstance();
registry.Add(MyProto.Bar);
MyProto.Foo message = MyProto.Foo.ParseFrom(input, registry);
You might wonder why this is necessary. Two alternatives might come to
mind. First, you might imagine a system where generated extensions are
automatically registered when their containing classes are loaded. This
is a popular technique, but is bad design; among other things, it creates a
situation where behavior can change depending on what classes happen to be
loaded. It also introduces a security vulnerability, because an
unprivileged class could cause its code to be called unexpectedly from a
privileged class by registering itself as an extension of the right type.
Another option you might consider is lazy parsing: do not parse an
extension until it is first requested, at which point the caller must
provide a type to use. This introduces a different set of problems. First,
it would require a mutex lock any time an extension was accessed, which
would be slow. Second, corrupt data would not be detected until first
access, at which point it would be much harder to deal with it. Third, it
could violate the expectation that message objects are immutable, since the
type provided could be any arbitrary message class. An unprivileged user
could take advantage of this to inject a mutable object into a message
belonging to privileged code and create mischief.
Construct a new, empty instance.
Add an extension from a generated file to the registry.
Get the unmodifiable singleton empty instance.
Finds an extension by containing type and field number.
A null reference is returned if the extension can't be found.
Nested type just used to represent a pair of MessageDescriptor and int, as
the key into the "by number" map.
Thrown when a protocol message being parsed is invalid in some way,
e.g. it contains a malformed varint or a negative byte length.
Helper methods for throwing exceptions
Throws an ArgumentNullException if the given value is null.
Throws an ArgumentNullException if the given value is null.
Throws an ArgumentNullException if the given value or any element within it is null.
TODO(jonskeet): Write summary text.
Converts this exception into an InvalidProtocolBufferException.
When a parsed message is missing required fields, this should be thrown
instead of UninitializedMessageException.
Constructs the description string for a given list of missing fields.
For Lite exceptions that do not known how to enumerate missing fields
Returns a read-only list of human-readable names of
required fields missing from this message. Each name
is a full path to a field, e.g. "foo.bar[5].baz"
This class is used internally by the Protocol Buffer Library and generated
message implementations. It is public only for the sake of those generated
messages. Others should not use this class directly.
This class contains constants and helper functions useful for dealing with
the Protocol Buffer wire format.
Given a tag value, determines the wire type (lower 3 bits).
Given a tag value, determines the field number (the upper 29 bits).
Makes a tag value given a field number and wire type.
TODO(jonskeet): Should we just have a Tag structure?
Converts a field type to its wire type. Done with a switch for the sake
of speed - this is significantly faster than a dictionary lookup.