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.
Afficher le fichier Open project: ayende/dotnet-protobufs Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

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

CreateInstance() public static méthode

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

PopLimit() public méthode

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

PushLimit() public méthode

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
Résultat int

ReadBool() public méthode

Read a bool field from the stream.
public ReadBool ( ) : bool
Résultat bool

ReadBytes() public méthode

Reads a bytes field value from the stream.
public ReadBytes ( ) : ByteString
Résultat ByteString

ReadDouble() public méthode

Read a double field from the stream.
public ReadDouble ( ) : double
Résultat double

ReadEnum() public méthode

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

ReadFloat() public méthode

Read a float field from the stream.
public ReadFloat ( ) : float
Résultat float

ReadGroup() public méthode

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

ReadInt32() public méthode

Read an int32 field from the stream.
public ReadInt32 ( ) : int
Résultat int

ReadInt64() public méthode

Read an int64 field from the stream.
public ReadInt64 ( ) : long
Résultat long

ReadMessage() public méthode

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

ReadPrimitiveField() public méthode

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
Résultat object

ReadRawByte() public méthode

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

ReadRawBytes() public méthode

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
Résultat System.ByteBuffer

ReadSFixed32() public méthode

Reads an sfixed32 field value from the stream.
public ReadSFixed32 ( ) : int
Résultat int

ReadSFixed64() public méthode

Reads an sfixed64 field value from the stream.
public ReadSFixed64 ( ) : long
Résultat long

ReadSInt32() public méthode

Reads an sint32 field value from the stream.
public ReadSInt32 ( ) : int
Résultat int

ReadSInt64() public méthode

Reads an sint64 field value from the stream.
public ReadSInt64 ( ) : long
Résultat long

ReadString() public méthode

Reads a string field from the stream.
public ReadString ( ) : String
Résultat String

ReadUnknownGroup() public méthode

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
Résultat void

ResetSizeCounter() public méthode

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

SetRecursionLimit() public méthode

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
Résultat int

SetSizeLimit() public méthode

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
Résultat int

SkipMessage() public méthode

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

SkipRawBytes() public méthode

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