C# Class Google.ProtocolBuffers.CodedInputStream

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.
Datei anzeigen Open project: ayende/dotnet-protobufs Class Usage Examples

Public Methods

Method Description
CreateInstance ( Stream input ) : CodedInputStream

Creates a new CodedInputStream reading data from the given stream.

CreateInstance ( byte buf ) : CodedInputStream

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

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.

ReadBool ( ) : bool

Read a bool field from the stream.

ReadBytes ( ) : ByteString

Reads a bytes field value from the stream.

ReadDouble ( ) : double

Read a double field from the stream.

ReadEnum ( ) : int

Reads an enum field value from the stream. The caller is responsible for converting the numeric value to an actual enum.

ReadFloat ( ) : float

Read a float field from the stream.

ReadGroup ( int fieldNumber, IBuilder builder, ExtensionRegistry extensionRegistry ) : void

Reads a group field value from the stream.

ReadInt32 ( ) : int

Read an int32 field from the stream.

ReadInt64 ( ) : long

Read an int64 field from the stream.

ReadMessage ( IBuilder builder, ExtensionRegistry extensionRegistry ) : void

Reads an embedded message field value from the stream.

ReadPrimitiveField ( FieldType fieldType ) : object

Reads a field of any primitive type. Enums, groups and embedded messages are not handled by this method.

ReadRawByte ( ) : byte

Read one byte from the input.

ReadRawBytes ( int size ) : System.ByteBuffer

Read a fixed size of bytes from the input.

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.

ReadUnknownGroup ( int fieldNumber, Google.ProtocolBuffers.UnknownFieldSet builder ) : void

Reads a group field value from the stream and merges it into the given UnknownFieldSet.

ResetSizeCounter ( ) : void

Resets the current size counter to zero (see SetSizeLimit).

SetRecursionLimit ( int limit ) : int

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.

SetSizeLimit ( int limit ) : int

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.

SkipMessage ( ) : void

Reads and discards an entire message. This will read either until EOF or until an endgroup tag, whichever comes first.

SkipRawBytes ( int size ) : void

Reads and discards size bytes.

Private Methods

Method Description
CheckLastTagWas ( uint value ) : void
CodedInputStream ( Stream input ) : System
CodedInputStream ( byte buffer ) : System
DecodeZigZag32 ( uint n ) : int
DecodeZigZag64 ( ulong n ) : long
ReadFixed32 ( ) : uint
ReadFixed64 ( ) : ulong
ReadRawLittleEndian32 ( ) : uint
ReadRawLittleEndian64 ( ) : ulong
ReadRawVarint32 ( ) : uint
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
ReadTag ( ) : uint
ReadUInt32 ( ) : uint
ReadUInt64 ( ) : ulong
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.

SkipField ( uint tag ) : bool
SkipImpl ( int amountToSkip ) : void

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

SlowReadRawVarint32 ( ) : uint

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

Method Details

CreateInstance() public static method

Creates a new CodedInputStream reading data from the given stream.
public static CreateInstance ( Stream input ) : CodedInputStream
input Stream
return CodedInputStream

CreateInstance() public static method

Creates a new CodedInputStream reading data from the given byte array.
public static CreateInstance ( byte buf ) : CodedInputStream
buf byte
return CodedInputStream

PopLimit() public method

Discards the current limit, returning the previous limit.
public PopLimit ( int oldLimit ) : void
oldLimit int
return void

PushLimit() public method

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

ReadBool() public method

Read 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

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

ReadEnum() public method

Reads an enum field value from the stream. The caller is responsible for converting the numeric value to an actual enum.
public ReadEnum ( ) : int
return int

ReadFloat() public method

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

ReadGroup() public method

Reads a group field value from the stream.
public ReadGroup ( int fieldNumber, IBuilder builder, ExtensionRegistry extensionRegistry ) : void
fieldNumber int
builder IBuilder
extensionRegistry ExtensionRegistry
return void

ReadInt32() public method

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

ReadInt64() public method

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

ReadMessage() public method

Reads an embedded message field value from the stream.
public ReadMessage ( IBuilder builder, ExtensionRegistry extensionRegistry ) : void
builder IBuilder
extensionRegistry ExtensionRegistry
return void

ReadPrimitiveField() public method

Reads a field of any primitive type. Enums, groups and embedded messages are not handled by this method.
public ReadPrimitiveField ( FieldType fieldType ) : object
fieldType FieldType
return object

ReadRawByte() public method

Read one byte from the input.
/// the end of the stream or the current limit was reached ///
public ReadRawByte ( ) : byte
return byte

ReadRawBytes() public method

Read a fixed size of bytes from the input.
/// the end of the stream or the current limit was reached ///
public ReadRawBytes ( int size ) : System.ByteBuffer
size int
return System.ByteBuffer

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

ReadUnknownGroup() public method

Reads a group field value from the stream and merges it into the given UnknownFieldSet.
public ReadUnknownGroup ( int fieldNumber, Google.ProtocolBuffers.UnknownFieldSet builder ) : void
fieldNumber int
builder Google.ProtocolBuffers.UnknownFieldSet
return void

ResetSizeCounter() public method

Resets the current size counter to zero (see SetSizeLimit).
public ResetSizeCounter ( ) : void
return void

SetRecursionLimit() public method

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.
public SetRecursionLimit ( int limit ) : int
limit int
return int

SetSizeLimit() public method

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.
public SetSizeLimit ( int limit ) : int
limit int
return int

SkipMessage() public method

Reads and discards an entire message. This will read either until EOF or until an endgroup tag, whichever comes first.
public SkipMessage ( ) : void
return void

SkipRawBytes() public method

Reads and discards size bytes.
the end of the stream /// or the current limit was reached
public SkipRawBytes ( int size ) : void
size int
return void