Reads and decodes protocol message fields.
This class is generally used by generated code to read appropriate primitives from the stream. It effectively encapsulates the lowest levels of protocol buffer format.
Repeated fields and map fields are not handled by this class; use RepeatedField{T} and MapField{TKey, TValue} to serialize such fields.
Constructors and Destructors |
|
---|---|
CodedInputStream(byte[] buffer)
Creates a new CodedInputStream reading data from the given byte array.
|
|
CodedInputStream(byte[] buffer, int offset, int length)
Creates a new CodedInputStream that reads from the given byte array slice.
|
|
CodedInputStream(Stream input)
Creates a new CodedInputStream reading data from the given stream, which will be disposed when the returned object is disposed.
|
|
CodedInputStream(Stream input, bool leaveOpen)
Creates a new CodedInputStream reading data from the given stream.
|
Properties |
|
---|---|
IsAtEnd
|
bool
Returns true if the stream has reached the end of the input.
|
LastTag
|
uint
Returns the last tag read, or 0 if no tags have been read or we've read beyond the end of the stream.
|
Position
|
long
Returns the current position in the input stream, or the position in the input buffer
|
ReachedLimit
|
bool
Returns whether or not all the data before the limit has been read.
|
RecursionLimit
|
int
Returns the recursion limit for this stream.
|
SizeLimit
|
int
Returns the size limit for this stream.
|
Public functions |
|
---|---|
Dispose()
|
void
Disposes of this instance, potentially closing any underlying stream.
|
MaybeConsumeTag(uint tag)
|
bool
Peeks at the next tag in the stream.
|
PeekTag()
|
uint
Peeks at the next field tag.
|
ReadBool()
|
bool
Reads a bool field from the stream.
|
ReadBytes()
|
Reads a bytes field value from the stream.
|
ReadDouble()
|
double
Reads a double field from the stream.
|
ReadEnum()
|
int
Reads an enum field value from the stream.
|
ReadFixed32()
|
uint
Reads a fixed32 field from the stream.
|
ReadFixed64()
|
ulong
Reads a fixed64 field from the stream.
|
ReadFloat()
|
float
Reads a float field from the stream.
|
ReadInt32()
|
int
Reads an int32 field from the stream.
|
ReadInt64()
|
long
Reads an int64 field from the stream.
|
ReadLength()
|
int
Reads a length for length-delimited data.
|
ReadMessage(IMessage builder)
|
void
Reads an embedded message field value from the stream.
|
ReadSFixed32()
|
int
Reads an sfixed32 field value from the stream.
|
ReadSFixed64()
|
long
Reads an sfixed64 field value from the stream.
|
ReadSInt32()
|
int
Reads an sint32 field value from the stream.
|
ReadSInt64()
|
long
Reads an sint64 field value from the stream.
|
ReadString()
|
string
Reads a string field from the stream.
|
ReadTag()
|
uint
Reads a field tag, returning the tag of 0 for "end of stream".
|
ReadUInt32()
|
uint
Reads a uint32 field value from the stream.
|
ReadUInt64()
|
ulong
Reads a uint64 field from the stream.
|
SkipLastField()
|
void
Skips the data for the field with the tag we've just read.
|
Public static functions |
|
---|---|
CreateWithLimits(Stream input, int sizeLimit, int recursionLimit)
|
Creates a CodedInputStream with the specified size and recursion limits, reading from an input stream.
|
bool IsAtEnd
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.
uint LastTag
Returns the last tag read, or 0 if no tags have been read or we've read beyond the end of the stream.
long Position
Returns the current position in the input stream, or the position in the input buffer
bool ReachedLimit
Returns whether or not all the data before the limit has been read.
Details | |
---|---|
Returns |
int RecursionLimit
Returns the recursion limit for this stream.
This limit is applied whilst reading messages, to avoid maliciously-recursive data.
The default limit is 64.
The recursion limit for this stream.
int SizeLimit
Returns the size limit for this stream.
This limit is applied when reading from the underlying stream, as a sanity check. It is not applied when reading from a byte array data source without an underlying stream. The default value is 64MB.
The size limit.
CodedInputStream( byte[] buffer )
Creates a new CodedInputStream reading data from the given byte array.
CodedInputStream( byte[] buffer, int offset, int length )
Creates a new CodedInputStream that reads from the given byte array slice.
CodedInputStream( Stream input )
Creates a new CodedInputStream reading data from the given stream, which will be disposed when the returned object is disposed.
Details | |||
---|---|---|---|
Parameters |
|
CodedInputStream( Stream input, bool leaveOpen )
Creates a new CodedInputStream reading data from the given stream.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
void Dispose()
Disposes of this instance, potentially closing any underlying stream.
As there is no flushing to perform here, disposing of a CodedInputStream which was constructed with the leaveOpen
option parameter set to true
(or one which was constructed to read from a byte array) has no effect.
bool MaybeConsumeTag( uint tag )
Peeks at the next tag in the stream.
If it matches tag , the tag is consumed and the method returns true
; otherwise, the stream is left in the original position and the method returns false
.
uint PeekTag()
bool ReadBool()
Reads a bool field from the stream.
double ReadDouble()
Reads a double field from the stream.
int ReadEnum()
Reads an enum field value from the stream.
uint ReadFixed32()
Reads a fixed32 field from the stream.
ulong ReadFixed64()
Reads a fixed64 field from the stream.
float ReadFloat()
Reads a float field from the stream.
int ReadInt32()
Reads an int32 field from the stream.
long ReadInt64()
Reads an int64 field from the stream.
int ReadLength()
Reads a length for length-delimited data.
This is internally just reading a varint, but this method exists to make the calling code clearer.
void ReadMessage( IMessage builder )
Reads an embedded message field value from the stream.
int ReadSFixed32()
Reads an sfixed32 field value from the stream.
long ReadSFixed64()
Reads an sfixed64 field value from the stream.
int ReadSInt32()
Reads an sint32 field value from the stream.
long ReadSInt64()
Reads an sint64 field value from the stream.
string ReadString()
Reads a string field from the stream.
uint ReadTag()
Reads a field tag, returning the tag of 0 for "end of stream".
If this method returns 0, it doesn't necessarily mean the end of all the data in this CodedInputStream; it may be the end of the logical stream for an embedded message, for example.
Details | |
---|---|
Returns |
The next field tag, or 0 for end of stream. (0 is never a valid tag.)
|
uint ReadUInt32()
Reads a uint32 field value from the stream.
ulong ReadUInt64()
Reads a uint64 field from the stream.
void SkipLastField()
Skips the data for the field with the tag we've just read.
This should be called directly after ReadTag, when the caller wishes to skip an unknown field.
This method throws InvalidProtocolBufferException if the last-read tag was an end-group tag. If a caller wishes to skip a group, they should skip the whole group, by calling this method after reading the start-group tag. This behavior allows callers to call this method on any field they don't understand, correctly resulting in an error if an end-group tag has not been paired with an earlier start-group tag.
Details | |||||
---|---|---|---|---|---|
Exceptions |
|
CodedInputStream CreateWithLimits( Stream input, int sizeLimit, int recursionLimit )
Creates a CodedInputStream with the specified size and recursion limits, reading from an input stream.
This method exists separately from the constructor to reduce the number of constructor overloads. It is likely to be used considerably less frequently than the constructors, as the default limits are suitable for most use cases.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Returns |
A
CodedInputStream reading from input with the specified size and recursion limits. |