Google.ProtocolBuffers Implementation of the non-generic IMessage interface as far as possible. 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. 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. Only present in the nongeneric interface - useful for tests, but not as much in real life. Only present in the nongeneric interface - useful for tests, but not as much in real life. Create a builder for messages of the appropriate type for the given field. Messages built with this can then be passed to the various mutation properties and methods. Returns true iff all required fields in the message and all embedded messages are set. Behaves like the equivalent property in IMessage<T>. The returned map may or may not reflect future changes to the builder. Either way, the returned map is unmodifiable. Allows getting and setting of a field. Get the message's type descriptor. Allows getting and setting of a repeated field value. 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. Clears the field. This is exactly equivalent to calling the generated Clear method corresponding to the field. Appends the given value as a new element for the specified repeated field. the field is not a repeated field, the field does not belong to this builder's type, or the value is of the incorrect type Merge some unknown fields into the set for this message. 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. Merge the specified other message into the message being built. Merging occurs as follows. For each field: For singular primitive fields, if the field is set in , then 's value overwrites the value in this message. For singular message fields, if the field is set in , it is merged into the corresponding sub-message of this message using the same merging rules. For repeated fields, the elements in are concatenated with the elements in this message. Implementation of the non-generic IMessage interface as far as possible. 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. 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. Returns true if the given field is set. This is exactly equivalent to calling the generated "Has" property corresponding to the field. the field is a repeated field, or it's not a field of this type Returns the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" property corresponding to the field. the field is not a repeated field, or it's not a field of this type 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. 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 the message's type's descriptor. This differs from the Descriptor property of each generated message class in that this method is an abstract method of IMessage whereas Descriptor is a static property of a specific class. They return the same thing. Returns a collection of all the fields in this message which are set and their corresponding values. A singular ("required" or "optional") field is set iff HasField() returns true for that field. A "repeated" field is set iff GetRepeatedFieldSize() is greater than zero. The values are exactly what would be returned by calling GetField(FieldDescriptor) for each field. The map is guaranteed to be a sorted map, so iterating over it will return fields in order by field number. Obtains the value of the given field, or the default value if it isn't set. For value type fields, the boxed value is returned. For enum fields, the EnumValueDescriptor for the enum is returned. For embedded message fields, the sub-message is returned. For repeated fields, an IList<T> is returned. Gets an element of a repeated field. For value type fields excluding enums, the boxed value is returned. For embedded message fields, the sub-message is returned. For enums, the relevant EnumValueDescriptor is returned. the field is not a repeated field, or it's not a field of this type the index is out of range for the repeated field's value Returns the unknown fields for this message. 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(). The serialized size if it's already been computed, or null if we haven't computed it yet. 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). 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! 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. 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 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. 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 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. 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. 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 classes extend this class. It implements most of the IMessage interface using reflection. Users can ignore this class as an implementation detail. Replaces the set of unknown fields for this message. This should only be used before a message is built, by the builder. (In the Java code it is private, but the builder is nested so has access to it.) Returns the message as a TMessage. 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 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 An implementation of IMessage that can represent arbitrary types, given a MessageaDescriptor. Creates a DynamicMessage with the given FieldSet. Returns a DynamicMessage representing the default instance of the given type. Parses a message of the given type from the given stream. Parse a message of the given type from the given stream and extension registry. Parses a message of the given type from the given stream. Parse a message of the given type from the given stream and extension registry. Parse as a message of the given type and return it. Parse as a message of the given type and return it. Parse as a message of the given type and return it. Parse as a message of the given type and return it. Constructs a builder for the given type. Constructs a builder for a message of the same type as , and initializes it with the same contents. Verifies that the field is a field of this message. Builder for dynamic messages. Instances are created with DynamicMessage.CreateBuilder. Helper for DynamicMessage.ParseFrom() methods to call. Throws InvalidProtocolBufferException Verifies that the field is a field of this message. Delegate to return a stream when asked, used by MessageStreamIterator. 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. 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. 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. 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 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. Read-only wrapper around another dictionary. Interface implemented by all DescriptorProtos. The generator doesn't emit the interface implementation claim, so PartialClasses.cs contains partial class declarations for each of them. The associated options protocol buffer type The brief name of the descriptor's target. The options for this descriptor. Base class for nearly all descriptors, providing common functionality. Type of the protocol buffer form of this descriptor Type of the options protocol buffer for this descriptor Strongly-typed form of the IDescriptor interface. Protocol buffer type underlying this descriptor type The non-generic form of the IDescriptor interface. Useful for describing a general descriptor. Returns the protocol buffer form of this descriptor. The fully qualified name of the descriptor's target. The brief name of the descriptor's target. The file this descriptor was declared in. Contains lookup tables containing all the descriptors defined in a particular file. Finds a symbol of the given name within the pool. The type of symbol to look for Fully-qualified name to look up The symbol with the given name and type, or null if the symbol doesn't exist or has the wrong type Adds a package to the symbol tables. If a package by the same name already exists, that is fine, but if some other kind of symbol exists under the same name, an exception is thrown. If the package has multiple components, this also adds the parent package(s). Adds a symbol to the symbol table. The symbol already existed in the symbol table. Verifies that the descriptor's name is valid (i.e. it contains only letters, digits and underscores, and does not start with a digit). Returns the field with the given number in the given descriptor, or null if it can't be found. Adds a field to the fieldsByNumber table. A field with the same containing type and number already exists. Adds an enum value to the enumValuesByNumber table. If an enum value with the same type and number already exists, this method does nothing. (This is allowed; the first value defined with the number takes precedence.) Looks up a descriptor by name, relative to some other descriptor. The name may be fully-qualified (with a leading '.'), partially-qualified, or unqualified. C++-like name lookup semantics are used to search for the matching descriptor. Struct used to hold the keys for the fieldByNumber table. Internal class containing utility methods when working with descriptors. Converts the given array into a read-only list, applying the specified conversion to each input element. Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert arrays. Thrown when building descriptors fails because the source DescriptorProtos are not valid. The full name of the descriptor where the error occurred. The protocol message representation of the invalid descriptor. A human-readable description of the error. (The Message property is made up of the descriptor's name and this description.) Descriptor for an enum type in a .proto file. Base class for descriptors which are also indexed. This is all of them other than . The index of this descriptor within its parent descriptor. This returns the index of this descriptor within its parent, for this descriptor's type. (There can be duplicate values for different types, e.g. one enum type with index 0 and one message type with index 0.) 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. Logic moved from FieldSet to continue current behavior Finds an enum value by number. If multiple enum values have the same number, this returns the first defined value with that number. Finds an enum value by name. The unqualified name of the value (e.g. "FOO"). The value's descriptor, or null if not found. If this is a nested type, get the outer descriptor, otherwise null. An unmodifiable list of defined value descriptors for this enum. Descriptor for a single enum value within an enum in a .proto file. 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. Descriptor for a field or extension within a message in a .proto file. Maps a field type as included in the .proto file to a FieldType. Returns the default value for a mapped type. Compares this descriptor with another one, ordering in "canonical" order which simply means ascending order by field number. must be a field of the same type, i.e. the of both fields must be the same. Compares this descriptor with another one, ordering in "canonical" order which simply means ascending order by field number. must be a field of the same type, i.e. the of both fields must be the same. Immutable mapping from field type to mapped type. Built using the attributes on FieldType values. Look up and cross-link all field types etc. The field's default value. Valid for all types except messages and groups. For all other types, the object returned is of the same class that would be returned by IMessage[this]. For repeated fields this will always be an empty immutable list compatible with IList[object]. For message fields it will always be null. For singular values, it will depend on the descriptor. Indicates whether or not this field is an extension. Get the field's containing type. For extensions, this is the type being extended, not the location where the extension was defined. See . Returns the C#-specific options for this field descriptor. This will always be completely filled in. For extensions defined nested within message types, gets the outer type. Not valid for non-extension fields. message Foo { extensions 1000 to max; } extend Foo { optional int32 baz = 1234; } message Bar { extend Foo { optional int32 qux = 4321; } } The containing type for both baz and qux is Foo. However, the extension scope for baz is null while the extension scope for qux is Bar. For enum fields, returns the field's type. For embedded message and group fields, returns the field's type. 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. Describes a .proto file, including everything defined within. IDescriptor is implemented such that the File property returns this descriptor, and the FullName is the same as the Name. Allows a file descriptor to be configured with a set of external options, e.g. from the command-line arguments to protogen. Finds a type (message, enum, service or extension) in the file by name. Does not find nested types. The unqualified type name to look for. The type of descriptor to look for (or ITypeDescriptor for any) The type's descriptor, or null if not found. Builds a FileDescriptor from its protocol buffer representation. The protocol message form of the FileDescriptor. FileDescriptors corresponding to all of the file's dependencies, in the exact order listed in the .proto file. May be null, in which case it is treated as an empty array. If is not a valid descriptor. This can occur for a number of reasons, such as a field having an undefined type or because two messages were defined with the same name. This method is to be called by generated code only. It is equivalent to BuildFrom except that the FileDescriptorProto is encoded in protocol buffer wire format. This overload is maintained for backward compatibility with source code generated before the custom options were available (and working). Replace our FileDescriptorProto with the given one, which is identical except that it might contain extensions that weren't present in the original. This method is needed for bootstrapping when a file defines custom options. The options may be defined in the file itself, so we can't actually parse them until we've constructed the descriptors, but to construct the decsriptors we have to have parsed the descriptor protos. So, we have to parse the descriptor protos a second time after constructing the descriptors. The descriptor in its protocol message representation. The defined in descriptor.proto. Returns the C#-specific options for this file descriptor. This will always be completely filled in. The file name. The package as declared in the .proto file. This may or may not be equivalent to the .NET namespace of the generated classes. Unmodifiable list of top-level message types declared in this file. Unmodifiable list of top-level enum types declared in this file. Unmodifiable list of top-level services declared in this file. Unmodifiable list of top-level extensions declared in this file. Unmodifiable list of this file's dependencies (imports). Implementation of IDescriptor.FullName - just returns the same as Name. Implementation of IDescriptor.File - just returns this descriptor. Protocol buffer describing this descriptor. Pool containing symbol descriptors. This delegate should be used by generated code only. When calling FileDescriptor.InternalBuildGeneratedFileFrom, the caller can provide a callback which assigns the global variables defined in the generated code which point at parts of the FileDescriptor. The callback returns an Extension Registry which contains any extensions which might be used in the descriptor - that is, extensions of the various "Options" messages defined in descriptor.proto. The callback may also return null to indicate that no extensions are used in the descriptor. Type as it's mapped onto a .NET type. Describes a message type. Determines if the given field number is an extension. Finds a field by field name. The unqualified name of the field (e.g. "foo"). The field's descriptor, or null if not found. Finds a field by field number. The field number within this message type. The field's descriptor, or null if not found. Finds a field by its property name, as it would be generated by protogen. The property name within this message type. The field's descriptor, or null if not found. Finds a nested descriptor by name. The is valid for fields, nested message types and enums. The unqualified name of the descriptor, e.g. "Foo" The descriptor, or null if not found. Looks up and cross-links all fields, nested types, and extensions. See FileDescriptor.ReplaceProto If this is a nested type, get the outer descriptor, otherwise null. An unmodifiable list of this message type's fields. An unmodifiable list of this message type's extensions. An unmodifiable list of this message type's nested types. An unmodifiable list of this message type's enum types. Returns a pre-computed result as to whether this message has required fields. This includes optional fields which are message types which in turn have required fields, and any extension fields. Describes a single method in a service. The service this method belongs to. The method's input type. The method's input type. Represents a package in the symbol table. We use PackageDescriptors just as placeholders so that someone cannot define, say, a message type that has the same name as an existing package. Describes a service type. Finds a method by name. The unqualified name of the method (e.g. "Foo"). The method's decsriptor, or null if not found. An unmodifiable list of methods in this service. The extension's descriptor A default instance of the extensions's type, if it has a message type, or null otherwise. 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. 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. Add an extension from a generated file to the registry. Adds a non-message-type extension to the registry by descriptor. Adds a message-type-extension to the registry by descriptor. Construct a new, empty instance. Add an extension from a generated file to the registry. Finds an extension by fully-qualified field name, in the proto namespace, i.e. result.Descriptor.FullName will match if a match is found. A null reference is returned if the extension can't be found. Finds an extension by containing type and field number. A null reference is returned if the extension can't be found. 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. The methods in this class are somewhat evil, and should not be tampered with lightly. Basically they allow the creation of relatively weakly typed delegates from MethodInfos which are more strongly typed. They do this by creating an appropriate strongly typed delegate from the MethodInfo, and then calling that within an anonymous method. Mind-bending stuff (at least to your humble narrator) but the resulting delegates are very fast compared with calling Invoke later on. Empty Type[] used when calling GetProperty to force property instead of indexer fetching. Creates a delegate which will execute the given method and then return the result as an object. Method used solely for implementing CreateUpcastDelegate. Public to avoid trust issues in low-trust scenarios. Creates a delegate which will execute the given method after casting the parameter down from object to the required parameter type. Creates a delegate which will execute the given method after casting the parameter down from object to the required parameter type. Creates a delegate which will execute the given static method and cast the result up to IBuilder. Accessor for fields representing a non-repeated enum value. Access for a non-repeated field of a "primitive" type (i.e. not another message or an enum). Allows fields to be reflectively accessed in a smart manner. The property descriptors for each field are created once and then cached. In addition, this interface holds knowledge of repeated fields, builders etc. Indicates whether the specified message contains the field. Gets the count of the repeated field in the specified message. Clears the field in the specified builder. Creates a builder for the type of this field (which must be a message field). Accessor for single fields Mutator for single fields Accessor for repeated fields Mutator for repeated fields Adds the specified value to the field in the given builder. Returns a read-only wrapper around the value of a repeated field. Only valid for message types - this implementation throws InvalidOperationException. The CLR type of the field (int, the enum type, ByteString, the message etc). As declared by the property. Returns an EnumValueDescriptor representing the value in the builder. Note that if an enum has multiple values for the same number, the descriptor for the first value with that number will be returned. Sets the value as an enum (via an int) in the builder, from an EnumValueDescriptor parameter. Accessor for fields representing a non-repeated message value. The static method to create a builder for the property type. For example, in a message type "Foo", a field called "bar" might be of type "Baz". This method is Baz.CreateBuilder. Creates a message of the appropriate CLR type from the given value, which may already be of the right type or may be a dynamic message. Accessor for a repeated field of type int, ByteString etc. The builder class's accessor already builds a read-only wrapper for us, which is exactly what we want. The CLR type of the field (int, the enum type, ByteString, the message etc). This is taken from the return type of the method used to retrieve a single value. Accessor for a repeated enum field. Provides access to fields in generated messages via reflection. This type is public to allow it to be used by generated messages, which create appropriate instances in the .proto file description class. TODO(jonskeet): See if we can hide it somewhere... Constructs a FieldAccessorTable for a particular message class. Only one FieldAccessorTable should be constructed per class. The property names should all actually correspond with the field descriptor's CSharpOptions.PropertyName property, but bootstrapping issues currently prevent us from using that. This may be addressed at a future time, in which case we can keep this constructor for backwards compatibility, just ignoring the parameter. TODO(jonskeet): Make it so. The type's descriptor The Pascal-case names of all the field-based properties in the message. Creates an accessor for a single field Accessor for a repeated message field. TODO(jonskeet): Try to extract the commonality between this and SingleMessageAccessor. We almost want multiple inheritance... The static method to create a builder for the property type. For example, in a message type "Foo", a field called "bar" might be of type "Baz". This method is Baz.CreateBuilder. Creates a message of the appropriate CLR type from the given value, which may already be of the right type or may be a dynamic message. 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 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. Force coercion to full descriptor dictionary. 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. Class used to represent repeat extensions in generated classes. Base type for all generated extensions. The protocol compiler generates a static singleton instance of this class for each extension. For exmaple, imagine a .proto file with: message Foo { extensions 1000 to max } extend Foo { optional int32 bar; } Then MyProto.Foo.Bar has type GeneratedExtensionBase<MyProto.Foo,int>. In general, users should ignore the details of this type, and simply use the static singletons as parameters to the extension accessors in ExtendableMessage and ExtendableBuilder. The interface implemented by both GeneratedException and GeneratedRepeatException, to make it easier to cope with repeats separately. 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 the default message instance for extensions which are message types. Converts the list to the right type. TODO(jonskeet): Check where this is used, and whether we need to convert for primitive types. Thrown when a protocol message being parsed is invalid in some way, e.g. it contains a malformed varint or a negative byte length. Interface for an RPC channel. A channel represents a communication line to a service (IService implementation) which can be used to call that service's methods. The service may be running on another machine. Normally, you should not call an IRpcChannel directly, but instead construct a stub wrapping it. Generated service classes contain a CreateStub method for precisely this purpose. Calls the given method of the remote service. This method is similar to with one important difference: the caller decides the types of the IMessage objects, not the implementation. The request may be of any type as long as request.Descriptor == method.InputType. The response passed to the callback will be of the same type as (which must be such that responsePrototype.Descriptor == method.OutputType). Mediates a single method call. The primary purpose of the controller is to provide a way to manipulate settings specific to the RPC implementation and to find out about RPC-level errors. The methods provided by this interface are intended to be a "least common denominator" set of features which we expect all implementations to support. Specific implementations may provide more advanced features, (e.g. deadline propagation). Resets the controller to its initial state so that it may be reused in a new call. This can be called from the client side only. It must not be called while an RPC is in progress. Advises the RPC system that the caller desires that the RPC call be canceled. The RPC system may cancel it immediately, may wait awhile and then cancel it, or may not even cancel the call at all. If the call is canceled, the "done" callback will still be called and the RpcController will indicate that the call failed at that time. Causes Failed to return true on the client side. will be incorporated into the message returned by ErrorText. If you find you need to return machine-readable information about failures, you should incorporate it into your response protocol buffer and should *not* call SetFailed. If true, indicates that the client canceled the RPC, so the server may as well give up on replying to it. This method must be called on the server side only. The server should still call the final "done" callback. Requests that the given callback be called when the RPC is canceled. The parameter passed to the callback will always be null. The callback will be called exactly once. If the RPC completes without being canceled, the callback will be called after completion. If the RPC has already been canceled when NotifyOnCancel is called, the callback will be called immediately. NotifyOnCancel must be called no more than once per request. It must be called on the server side only. After a call has finished, returns true if the call failed. The possible reasons for failure depend on the RPC implementation. Failed must only be called on the client side, and must not be called before a call has finished. If Failed is true, ErrorText returns a human-readable description of the error. 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 Base interface for protocol-buffer-based RPC services. Services themselves are abstract classes (implemented either by servers or as stubs) but they implement this itnerface. The methods of this interface can be used to call the methods of the service without knowing its exact type at compile time (analagous to the IMessage interface). Call a method of the service specified by MethodDescriptor. This is normally implemented as a simple switch that calls the standard definitions of the service's methods. Preconditions method.Service == DescriptorForType request is of the exact same class as the object returned by GetRequestPrototype(method) controller is of the correct type for the RPC implementation being used by this service. For stubs, the "correct type" depends on the IRpcChannel which the stub is using. Server-side implementations are expected to accept whatever type of IRpcController the server-side RPC implementation uses. Postconditions will be called when the method is complete. This may before CallMethod returns or it may be at some point in the future. The parameter to is the response. It will be of the exact same type as would be returned by . If the RPC failed, the parameter to will be null. Further details about the failure can be found by querying . CallMethod requires that the request passed in is of a particular implementation of IMessage. This method gets the default instance of this type of a given method. You can then call WeakCreateBuilderForType to create a builder to build an object which you can then pass to CallMethod. Like GetRequestPrototype, but returns a prototype of the response message. This is generally not needed because the IService implementation contructs the response message itself, but it may be useful in some cases to know ahead of time what type of object will be returned. The ServiceDescriptor describing this service and its methods. Iterates over data created using a . Unlike MessageStreamWriter, this class is not usually constructed directly with a stream; instead it is provided with a way of opening a stream when iteration is started. The stream is closed when the iteration is completed or the enumerator is disposed. (This occurs naturally when using foreach.) The default instance of TMessage type used to construct builders while reading Any exception (within reason) thrown in type ctor is caught and rethrown in the constructor. This makes life a lot simpler for the caller. Vastly simplified the reflection to simply obtain the default instance and use it to construct the weak builder while simply casting the result. Ideally this class should have required a TBuilder type argument with a new() constraint to construct the initial instance thereby the reflection could be eliminated. Creates a new instance which uses the same stream provider as this one, but the specified extension registry. Creates a new instance which uses the same stream provider and extension registry as this one, but with the specified size limit. Note that this must be big enough for the largest message and the tag and size preceding it. Writes multiple messages to the same stream. Each message is written as if it were an element of a repeated field 1 in a larger protocol buffer. This class takes no ownership of the stream it is given; it never closes the stream. Creates an instance which writes to the given stream. Stream to write messages to. Utilities for arbitrary messages of an unknown type. This class does not use generics precisely because it is designed for dynamically discovered types. Returns the default message for the given type. If an exception is thrown (directly from this code), the message will be suitable to be displayed to a user. The type parameter is null. The type doesn't implement IMessage, or doesn't have a static DefaultMessage property of the same type, or is generic or abstract. Returns the default message for the type with the given name. This is just a convenience wrapper around calling Type.GetType and then GetDefaultMessage. If an exception is thrown, the message will be suitable to be displayed to a user. The typeName parameter is null. The type doesn't implement IMessage, or doesn't have a static DefaultMessage property of the same type, or can't be found. Helpers for converting names to pascal case etc. All characters that are not alpha-numeric Matches lower-case character that follow either an underscore, or a number Removes non alpha numeric characters while capitalizing letters that follow a number or underscore. The first letter is always upper case. Removes non alpha numeric characters while capitalizing letters that follow a number or underscore. The first letter is always lower case. Capitalizes any characters following an '_' or a number '0' - '9' and removes all non alpha-numeric characters. If the resulting string begins with a number an '_' will be prefixed. Attempts to strip a suffix from a string, returning whether or not the suffix was actually present. Grab-bag of utility functions useful when dealing with RPCs. Converts an Action[IMessage] to an Action[T]. Converts an Action[T] to an Action[IMessage]. The generalized action will accept any message object which has the same descriptor, and will convert it to the correct class before calling the original action. However, if the generalized callback is given a message with a different descriptor, an exception will be thrown. Provides ASCII text formatting support for messages. TODO(jonskeet): Support for alternative line endings. (Easy to print, via TextGenerator. Not sure about parsing.) Outputs a textual representation of the Protocol Message supplied into the parameter output. Outputs a textual representation of to . Parses an integer in hex (leading 0x), decimal (no prefix) or octal (leading 0). Only a negative sign is permitted, and it must come before the radix indicator. Tests a character to see if it's an octal digit. Tests a character to see if it's a hex digit. Interprets a character as a digit (in any base up to 36) and returns the numeric value. Unescapes a text string as escaped using . Two-digit hex escapes (starting with "\x" are also recognised. Like but escapes a text string. The string is first encoded as UTF-8, then each byte escaped individually. The returned value is guaranteed to be entirely ASCII. 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. Performs string unescaping from C style (octal, hex, form feeds, tab etc) into a byte string. Parses a single field from the specified tokenizer and merges it into the builder. Helper class to control indentation. Used for TextFormat and by ProtoGen. The string to use at the end of each line. We assume that "Print" is only called using \n to indicate a line break; that's what we use to detect when we need to indent etc, and *just* the \n is replaced with the contents of lineBreak. Writer to write formatted text to. Keeps track of whether the next piece of text should be indented Keeps track of the current level of indentation Creates a generator writing to the given writer. The writer is not closed by this class. Indents text by two spaces. After calling Indent(), two spaces will be inserted at the beginning of each line of text. Indent() may be called multiple times to produce deeper indents. Reduces the current indent level by two spaces. Prints the given text to the output stream, indenting at line boundaries. Represents a stream of tokens parsed from a string. The character index within the text to perform the next regex match at. The character index within the text at which the current token begins. The line number of the current token. The column number of the current token. The line number of the previous token. The column number of the previous token. Construct a tokenizer that parses tokens from the given text. Advances to the next token. Skip over any whitespace so that matchPos starts at the next token. If the next token exactly matches the given token, consume it and return true. Otherwise, return false without doing anything. If the next token exactly matches the specified one, consume it. Otherwise, throw a FormatException. Returns true if the next token is an integer, but does not consume it. If the next token is an identifier, consume it and return its value. Otherwise, throw a FormatException. If the next token is a 32-bit signed integer, consume it and return its value. Otherwise, throw a FormatException. If the next token is a 32-bit unsigned integer, consume it and return its value. Otherwise, throw a FormatException. If the next token is a 64-bit signed integer, consume it and return its value. Otherwise, throw a FormatException. If the next token is a 64-bit unsigned integer, consume it and return its value. Otherwise, throw a FormatException. If the next token is a double, consume it and return its value. Otherwise, throw a FormatException. If the next token is a float, consume it and return its value. Otherwise, throw a FormatException. If the next token is a Boolean, consume it and return its value. Otherwise, throw a FormatException. If the next token is a string, consume it and return its (unescaped) value. Otherwise, throw a FormatException. If the next token is a string, consume it, unescape it as a ByteString and return it. Otherwise, throw a FormatException. Returns a format exception with the current line and column numbers in the description, suitable for throwing. Returns a format exception with the line and column numbers of the previous token in the description, suitable for throwing. Constructs an appropriate FormatException for the given existing exception when trying to parse an integer. Constructs an appropriate FormatException for the given existing exception when trying to parse a float or double. Are we at the end of the input? 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 list of the full "paths" of missing required fields in the specified message. Recursive helper implementing FindMissingFields. 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" Represents a single field in an UnknownFieldSet. An UnknownField consists of five lists of values. The lists correspond to the five "wire types" used in the protocol buffer binary format. The wire type of each field can be determined from the encoded form alone, without knowing the field's declared type. So, we are able to parse unknown values at least this far and separate them. Normally, only one of the five lists will contain any values, since it is impossible to define a valid message type that declares two different types for the same field number. However, the code is designed to allow for the case where the same unknown field number is encountered using multiple different wire types. UnknownField is an immutable class. To construct one, you must use an UnknownField.Builder. Constructs a new Builder. Constructs a new Builder and initializes it to a copy of . Serializes the field, including the field number, and writes it to . Computes the number of bytes required to encode this field, including field number. Serializes the length-delimited values of the field, including field number, and writes them to using the MessageSet wire format. Get the number of bytes required to encode this field, incuding field number, using the MessageSet wire format. The list of varint values for this field. The list of fixed32 values for this field. The list of fixed64 values for this field. The list of length-delimited values for this field. The list of embedded group values for this field. These are represented using UnknownFieldSets rather than Messages since the group's type is presumably unknown. Used to build instances of UnknownField. Builds the field. After building, the builder is reset to an empty state. (This is actually easier than making it unusable.) Merge the values in into this field. For each list of values, 's values are append to the ones in this field. Returns a new list containing all of the given specified values from both the and lists. If is null and is empty, null is returned. Otherwise, either a new list is created (if is null) or the elements of are added to . Clears the contents of this builder. Adds a varint value. Adds a fixed32 value. Adds a fixed64 value. Adds a length-delimited value. Adds an embedded group. Adds to the , creating a new list if is null. The list is returned - either the original reference or the new list. Returns a read-only version of the given IList, and clears the field used for . If the value is null, an empty list is produced using Lists.Empty. Used to keep track of fields which were seen when parsing a protocol message but whose field numbers or types are unrecognized. This most frequently occurs when new fields are added to a message type and then messages containing those fields are read by old software that was built before the new types were added. Every message contains an UnknownFieldSet. Most users will never need to use this class directly. Creates a new unknown field set builder. Creates a new unknown field set builder and initialize it from . Checks whether or not the given field number is present in the set. Serializes the set and writes it to . Converts the set to a string in protocol buffer text format. This is just a trivial wrapper around TextFormat.PrintToString. Converts the set to a string in protocol buffer text format. This is just a trivial wrapper around TextFormat.PrintToString. Serializes the message to a ByteString and returns it. This is just a trivial wrapper around WriteTo(ICodedOutputStream). Serializes the message to a byte array and returns it. This is just a trivial wrapper around WriteTo(ICodedOutputStream). Serializes the message and writes it to . This is just a trivial wrapper around WriteTo(ICodedOutputStream). Serializes the set and writes it to using the MessageSet wire format. Parses an UnknownFieldSet from the given input. Parses an UnknownFieldSet from the given data. Parses an UnknownFieldSet from the given data. Parses an UnknownFieldSet from the given input. Returns a read-only view of the mapping from field numbers to values. Fetches a field by number, returning an empty field if not present. Never returns null. Gets the number of bytes required to encode this set. Gets the number of bytes required to encode this set using the MessageSet wire format. Builder for UnknownFieldSets. Mapping from number to field. Note that by using a SortedList we ensure that the fields will be serialized in ascending order. Returns a field builder for the specified field number, including any values which already exist. Build the UnknownFieldSet and return it. Once this method has been called, this instance will no longer be usable. Calling any method after this will throw a NullReferenceException. Adds a field to the set. If a field with the same number already exists, it is replaced. Resets the builder to an empty set. Parse an entire message from and merge its fields into this set. Parse a single field from and merge it into this set. The field's tag number, which was already parsed. The coded input stream containing the field false if the tag is an "end group" tag, true otherwise Parses as an UnknownFieldSet and merge it with the set being built. This is just a small wrapper around MergeFrom(ICodedInputStream). Parses as an UnknownFieldSet and merge it with the set being built. This is just a small wrapper around MergeFrom(ICodedInputStream). Parses as an UnknownFieldSet and merge it with the set being built. This is just a small wrapper around MergeFrom(ICodedInputStream). Convenience method for merging a new field containing a single varint value. This is used in particular when an unknown enum value is encountered. Merges the fields from into this set. If a field number exists in both sets, the values in will be appended to the values in this set. Checks if the given field number is present in the set. Adds a field to the unknown field set. If a field with the same number already exists, the two are merged. Like but parses a single field. The input to read the field from Registry to use when an extension field is encountered Builder to merge field into, if it's a known field The tag, which should already have been read from the input true unless the tag is an end-group tag Called by MergeFieldFrom to parse a MessageSet extension. 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? Returns the wire type for the given field descriptor. This differs from GetWireType(FieldType) for packed repeated fields. 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.