C# Class Google.Protobuf.CodedInputStream

Readings 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.

Show file Open project: Arctium-Emulation/Project-WoW Class Usage Examples

Private Properties

Property Type Description
CheckReadEndOfStreamTag void
CodedInputStream Google.Protobuf.Collections
CodedInputStream Google.Protobuf.Collections
DecodeZigZag32 int
DecodeZigZag64 long
PopLimit void
PushLimit int
ReadRawByte byte
ReadRawBytes byte[]
ReadRawLittleEndian32 uint
ReadRawLittleEndian64 ulong
ReadRawVarint32 uint
ReadRawVarint32 uint
ReadRawVarint64 ulong
RecomputeBufferSizeAfterLimit void
RefillBuffer bool
SkipGroup void
SkipImpl void
SkipRawBytes void
SlowReadRawVarint32 uint

Public Methods

Method Description
CodedInputStream ( Stream input ) : Google.Protobuf.Collections

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 ) : Google.Protobuf.Collections

Creates a new CodedInputStream reading data from the given stream.

CodedInputStream ( byte buffer ) : Google.Protobuf.Collections

Creates a new CodedInputStream reading data from the given byte array.

CodedInputStream ( byte buffer, int offset, int length ) : Google.Protobuf.Collections

Creates a new CodedInputStream that reads from the given byte array slice.

CreateWithLimits ( Stream input, int sizeLimit, int recursionLimit ) : CodedInputStream

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.

Dispose ( ) : void

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.

MaybeConsumeTag ( uint tag ) : bool

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.

PeekTag ( ) : uint

Peeks at the next field tag. This is like calling ReadTag, but the tag is not consumed. (So a subsequent call to ReadTag will return the same value.)

ReadBool ( ) : bool

Reads a bool field from the stream.

ReadBytes ( ) : ByteString

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.

This is internally just reading a varint, but this method exists to make the calling code clearer.

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".

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.

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. 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.

Private Methods

Method Description
CheckReadEndOfStreamTag ( ) : void

Verifies that the last call to ReadTag() returned tag 0 - in other words, we've reached the end of the stream when we expected to.

CodedInputStream ( Stream input, byte buffer, int bufferPos, int bufferSize ) : Google.Protobuf.Collections

Creates a new CodedInputStream reading data from the given stream and buffer, using the default limits.

CodedInputStream ( Stream input, byte buffer, int bufferPos, int bufferSize, int sizeLimit, int recursionLimit ) : Google.Protobuf.Collections

Creates a new CodedInputStream reading data from the given stream and buffer, using the specified limits.

This chains to the version with the default limits instead of vice versa to avoid having to check that the default values are valid every time.

DecodeZigZag32 ( uint n ) : int

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.)

DecodeZigZag64 ( ulong n ) : long

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.)

PopLimit ( int oldLimit ) : void

Discards the current limit, returning the previous limit.

PushLimit ( int byteLimit ) : int

Sets currentLimit to (current position) + byteLimit. This is called when descending into a length-delimited embedded message. The previous limit is returned.

ReadRawByte ( ) : byte

Read one byte from the input.

ReadRawBytes ( int size ) : byte[]

Reads a fixed size of bytes from the input.

ReadRawLittleEndian32 ( ) : uint

Reads a 32-bit little-endian integer from the stream.

ReadRawLittleEndian64 ( ) : ulong

Reads a 64-bit little-endian integer from the stream.

ReadRawVarint32 ( ) : uint

Reads 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.

ReadRawVarint32 ( Stream input ) : uint

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.

ReadRawVarint64 ( ) : ulong

Reads a raw varint from the stream.

RecomputeBufferSizeAfterLimit ( ) : void
RefillBuffer ( bool mustSucceed ) : bool

Called when buffer is empty to read more bytes from the input. If mustSucceed 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 mustSucceed is false, RefillBuffer() returns false if no more bytes were available.

SkipGroup ( uint startGroupTag ) : void
SkipImpl ( int amountToSkip ) : void

Abstraction of skipping to cope with streams which can't really skip.

SkipRawBytes ( int size ) : void

Reads and discards size bytes.

SlowReadRawVarint32 ( ) : uint

Same code as ReadRawVarint32, but read each byte individually, checking for buffer overflow.

Method Details

CodedInputStream() public method

Creates a new CodedInputStream reading data from the given stream, which will be disposed when the returned object is disposed.
public CodedInputStream ( Stream input ) : Google.Protobuf.Collections
input Stream The stream to read from.
return Google.Protobuf.Collections

CodedInputStream() public method

Creates a new CodedInputStream reading data from the given stream.
public CodedInputStream ( Stream input, bool leaveOpen ) : Google.Protobuf.Collections
input Stream The stream to read from.
leaveOpen bool true to leave open when the returned /// is disposed; false to dispose of the given stream when the /// returned object is disposed.
return Google.Protobuf.Collections

CodedInputStream() public method

Creates a new CodedInputStream reading data from the given byte array.
public CodedInputStream ( byte buffer ) : Google.Protobuf.Collections
buffer byte
return Google.Protobuf.Collections

CodedInputStream() public method

Creates a new CodedInputStream that reads from the given byte array slice.
public CodedInputStream ( byte buffer, int offset, int length ) : Google.Protobuf.Collections
buffer byte
offset int
length int
return Google.Protobuf.Collections

CreateWithLimits() public static method

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.
public static CreateWithLimits ( Stream input, int sizeLimit, int recursionLimit ) : CodedInputStream
input Stream The input stream to read from
sizeLimit int The total limit of data to read from the stream.
recursionLimit int The maximum recursion depth to allow while reading.
return CodedInputStream

Dispose() public method

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.
public Dispose ( ) : void
return void

MaybeConsumeTag() public method

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.
public MaybeConsumeTag ( uint tag ) : bool
tag uint
return bool

PeekTag() public method

Peeks at the next field tag. This is like calling ReadTag, but the tag is not consumed. (So a subsequent call to ReadTag will return the same value.)
public PeekTag ( ) : uint
return uint

ReadBool() public method

Reads a bool field from the stream.
public ReadBool ( ) : bool
return bool

ReadBytes() public method

Reads a bytes field value from the stream.
public ReadBytes ( ) : ByteString
return ByteString

ReadDouble() public method

Reads a double field from the stream.
public ReadDouble ( ) : double
return double

ReadEnum() public method

Reads an enum field value from the stream.
public ReadEnum ( ) : int
return int

ReadFixed32() public method

Reads a fixed32 field from the stream.
public ReadFixed32 ( ) : uint
return uint

ReadFixed64() public method

Reads a fixed64 field from the stream.
public ReadFixed64 ( ) : ulong
return ulong

ReadFloat() public method

Reads a float field from the stream.
public ReadFloat ( ) : float
return float

ReadInt32() public method

Reads an int32 field from the stream.
public ReadInt32 ( ) : int
return int

ReadInt64() public method

Reads an int64 field from the stream.
public ReadInt64 ( ) : long
return long

ReadLength() public method

Reads a length for length-delimited data.
This is internally just reading a varint, but this method exists to make the calling code clearer.
public ReadLength ( ) : int
return int

ReadMessage() public method

Reads an embedded message field value from the stream.
public ReadMessage ( IMessage builder ) : void
builder IMessage
return void

ReadSFixed32() public method

Reads an sfixed32 field value from the stream.
public ReadSFixed32 ( ) : int
return int

ReadSFixed64() public method

Reads an sfixed64 field value from the stream.
public ReadSFixed64 ( ) : long
return long

ReadSInt32() public method

Reads an sint32 field value from the stream.
public ReadSInt32 ( ) : int
return int

ReadSInt64() public method

Reads an sint64 field value from the stream.
public ReadSInt64 ( ) : long
return long

ReadString() public method

Reads a string field from the stream.
public ReadString ( ) : string
return string

ReadTag() public method

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.
public ReadTag ( ) : uint
return uint

ReadUInt32() public method

Reads a uint32 field value from the stream.
public ReadUInt32 ( ) : uint
return uint

ReadUInt64() public method

Reads a uint64 field from the stream.
public ReadUInt64 ( ) : ulong
return ulong

SkipLastField() public method

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.
The last tag was an end-group tag The last read operation read to the end of the logical stream
public SkipLastField ( ) : void
return void