Space Engineers
Public Member Functions | Static Public Member Functions | Properties | List of all members
ProtoBuf.ProtoReader Class Reference

A stateful reader, used to read a protobuf stream. Typical usage would be (sequentially) to call ReadFieldHeader and (after matching the field) an appropriate Read* method. More...

Inheritance diagram for ProtoBuf.ProtoReader:

Public Member Functions

 ProtoReader (Stream source, TypeModel model, SerializationContext context)
 Creates a new reader against a stream More...
 
 ProtoReader (Stream source, TypeModel model, SerializationContext context, int length)
 Creates a new reader against a stream More...
 
void Dispose ()
 Releases resources used by the reader, but importantly does not Dispose the underlying stream; in many typical use-cases the stream is used for different processes, so it is assumed that the consumer will Dispose their stream separately. More...
 
uint ReadUInt32 ()
 Reads an unsigned 32-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64 More...
 
short ReadInt16 ()
 Reads a signed 16-bit integer from the stream: Variant, Fixed32, Fixed64, SignedVariant More...
 
ushort ReadUInt16 ()
 Reads an unsigned 16-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64 More...
 
byte ReadByte ()
 Reads an unsigned 8-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64 More...
 
sbyte ReadSByte ()
 Reads a signed 8-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant More...
 
int ReadInt32 ()
 Reads a signed 32-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant More...
 
long ReadInt64 ()
 Reads a signed 64-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant More...
 
string ReadString ()
 Reads a string from the stream (using UTF8); supported wire-types: String More...
 
void ThrowEnumException (System.Type type, int value)
 Throws an exception indication that the given value cannot be mapped to an enum. More...
 
unsafe double ReadDouble ()
 Reads a double-precision number from the stream; supported wire-types: Fixed32, Fixed64 More...
 
int ReadFieldHeader ()
 Reads a field header from the stream, setting the wire-type and retuning the field number. If no more fields are available, then 0 is returned. This methods respects sub-messages. More...
 
bool TryReadFieldHeader (int field)
 Looks ahead to see whether the next field in the stream is what we expect (typically; what we've just finished reading - for example ot read successive list items) More...
 
void Hint (WireType wireType)
 Compares the streams current wire-type to the hinted wire-type, updating the reader if necessary; for example, a Variant may be updated to SignedVariant. If the hinted wire-type is unrelated then no change is made. More...
 
void Assert (WireType wireType)
 Verifies that the stream's current wire-type is as expected, or a specialized sub-type (for example, SignedVariant) - in which case the current wire-type is updated. Otherwise an exception is thrown. More...
 
void SkipField ()
 Discards the data for the current field. More...
 
ulong ReadUInt64 ()
 Reads an unsigned 64-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64 More...
 
unsafe float ReadSingle ()
 Reads a single-precision number from the stream; supported wire-types: Fixed32, Fixed64 More...
 
bool ReadBoolean ()
 Reads a boolean value from the stream; supported wire-types: Variant, Fixed32, Fixed64 More...
 
void AppendExtensionData (IExtensible instance)
 Copies the current field into the instance as extension data More...
 
System.Type ReadType ()
 Reads a Type from the stream, using the model's DynamicTypeFormatting if appropriate; supported wire-types: String More...
 

Static Public Member Functions

static object ReadObject (object value, int key, ProtoReader reader)
 Reads (merges) a sub-message from the stream, internally calling StartSubItem and EndSubItem, and (in between) parsing the message in accordance with the model associated with the reader More...
 
static void EndSubItem (SubItemToken token, ProtoReader reader)
 Makes the end of consuming a nested message in the stream; the stream must be either at the correct EndGroup marker, or all fields of the sub-message must have been consumed (in either case, this means ReadFieldHeader should return zero) More...
 
static SubItemToken StartSubItem (ProtoReader reader)
 Begins consuming a nested message in the stream; supported wire-types: StartGroup, String More...
 
static byte[] AppendBytes (byte[] value, ProtoReader reader)
 Reads a byte-sequence from the stream, appending them to an existing byte-sequence (which can be null); supported wire-types: String More...
 
static int ReadLengthPrefix (Stream source, bool expectHeader, PrefixStyle style, out int fieldNumber)
 Reads the length-prefix of a message from a stream without buffering additional data, allowing a fixed-length reader to be created. More...
 
static int DirectReadLittleEndianInt32 (Stream source)
 Reads a little-endian encoded integer. An exception is thrown if the data is not all available. More...
 
static int DirectReadBigEndianInt32 (Stream source)
 Reads a big-endian encoded integer. An exception is thrown if the data is not all available. More...
 
static int DirectReadVarintInt32 (Stream source)
 Reads a varint encoded integer. An exception is thrown if the data is not all available. More...
 
static void DirectReadBytes (Stream source, byte[] buffer, int offset, int count)
 Reads a string (of a given lenth, in bytes) directly from the source into a pre-existing buffer. An exception is thrown if the data is not all available. More...
 
static byte[] DirectReadBytes (Stream source, int count)
 Reads a given number of bytes directly from the source. An exception is thrown if the data is not all available. More...
 
static string DirectReadString (Stream source, int length)
 Reads a string (of a given lenth, in bytes) directly from the source. An exception is thrown if the data is not all available. More...
 
static int ReadLengthPrefix (Stream source, bool expectHeader, PrefixStyle style, out int fieldNumber, out int bytesRead)
 Reads the length-prefix of a message from a stream without buffering additional data, allowing a fixed-length reader to be created. More...
 
static bool HasSubValue (ProtoBuf.WireType wireType, ProtoReader source)
 Indicates whether the reader still has data remaining in the current sub-item, additionally setting the wire-type for the next field if there is more data. This is used when decoding packed data. More...
 
static void NoteObject (object value, ProtoReader reader)
 Utility method, not intended for public use; this helps maintain the root object is complex scenarios More...
 
static object Merge (ProtoReader parent, object from, object to)
 Merge two objects using the details from the current reader; this is used to change the type of objects when an inheritance relationship is discovered later than usual during deserilazation. More...
 

Properties

int FieldNumber [get]
 Gets the number of the field being processed. More...
 
WireType WireType [get]
 Indicates the underlying proto serialization format on the wire. More...
 
bool InternStrings [get, set]
 Gets / sets a flag indicating whether strings should be checked for repetition; if true, any repeated UTF-8 byte sequence will result in the same String instance, rather than a second instance of the same string. Enabled by default. Note that this uses a custom interner - the system-wide string interner is not used. More...
 
SerializationContext Context [get]
 Addition information about this deserialization operation. More...
 
int Position [get]
 Returns the position of the current reader (note that this is not necessarily the same as the position in the underlying stream, if multiple readers are used on the same stream) More...
 
TypeModel Model [get]
 Get the TypeModel associated with this reader More...
 

Detailed Description

A stateful reader, used to read a protobuf stream. Typical usage would be (sequentially) to call ReadFieldHeader and (after matching the field) an appropriate Read* method.

Definition at line 24 of file ProtoReader.cs.

Constructor & Destructor Documentation

ProtoBuf.ProtoReader.ProtoReader ( Stream  source,
TypeModel  model,
SerializationContext  context 
)
inline

Creates a new reader against a stream

Parameters
sourceThe source stream
modelThe model to use for serialization; this can be null, but this will impair the ability to deserialize sub-objects
contextAdditional context about this serialization operation

Definition at line 47 of file ProtoReader.cs.

ProtoBuf.ProtoReader.ProtoReader ( Stream  source,
TypeModel  model,
SerializationContext  context,
int  length 
)
inline

Creates a new reader against a stream

Parameters
sourceThe source stream
modelThe model to use for serialization; this can be null, but this will impair the ability to deserialize sub-objects
contextAdditional context about this serialization operation
lengthThe number of bytes to read, or -1 to read until the end of the stream

Definition at line 71 of file ProtoReader.cs.

Member Function Documentation

static byte [] ProtoBuf.ProtoReader.AppendBytes ( byte[]  value,
ProtoReader  reader 
)
inlinestatic

Reads a byte-sequence from the stream, appending them to an existing byte-sequence (which can be null); supported wire-types: String

Definition at line 861 of file ProtoReader.cs.

void ProtoBuf.ProtoReader.AppendExtensionData ( IExtensible  instance)
inline

Copies the current field into the instance as extension data

Definition at line 1174 of file ProtoReader.cs.

void ProtoBuf.ProtoReader.Assert ( WireType  wireType)
inline

Verifies that the stream's current wire-type is as expected, or a specialized sub-type (for example, SignedVariant) - in which case the current wire-type is updated. Otherwise an exception is thrown.

Definition at line 704 of file ProtoReader.cs.

static int ProtoBuf.ProtoReader.DirectReadBigEndianInt32 ( Stream  source)
inlinestatic

Reads a big-endian encoded integer. An exception is thrown if the data is not all available.

Definition at line 953 of file ProtoReader.cs.

static void ProtoBuf.ProtoReader.DirectReadBytes ( Stream  source,
byte[]  buffer,
int  offset,
int  count 
)
inlinestatic

Reads a string (of a given lenth, in bytes) directly from the source into a pre-existing buffer. An exception is thrown if the data is not all available.

Definition at line 973 of file ProtoReader.cs.

static byte [] ProtoBuf.ProtoReader.DirectReadBytes ( Stream  source,
int  count 
)
inlinestatic

Reads a given number of bytes directly from the source. An exception is thrown if the data is not all available.

Definition at line 986 of file ProtoReader.cs.

static int ProtoBuf.ProtoReader.DirectReadLittleEndianInt32 ( Stream  source)
inlinestatic

Reads a little-endian encoded integer. An exception is thrown if the data is not all available.

Definition at line 943 of file ProtoReader.cs.

static string ProtoBuf.ProtoReader.DirectReadString ( Stream  source,
int  length 
)
inlinestatic

Reads a string (of a given lenth, in bytes) directly from the source. An exception is thrown if the data is not all available.

Definition at line 995 of file ProtoReader.cs.

static int ProtoBuf.ProtoReader.DirectReadVarintInt32 ( Stream  source)
inlinestatic

Reads a varint encoded integer. An exception is thrown if the data is not all available.

Definition at line 963 of file ProtoReader.cs.

void ProtoBuf.ProtoReader.Dispose ( )
inline

Releases resources used by the reader, but importantly does not Dispose the underlying stream; in many typical use-cases the stream is used for different processes, so it is assumed that the consumer will Dispose their stream separately.

Definition at line 96 of file ProtoReader.cs.

static void ProtoBuf.ProtoReader.EndSubItem ( SubItemToken  token,
ProtoReader  reader 
)
inlinestatic

Makes the end of consuming a nested message in the stream; the stream must be either at the correct EndGroup marker, or all fields of the sub-message must have been consumed (in either case, this means ReadFieldHeader should return zero)

Definition at line 577 of file ProtoReader.cs.

static bool ProtoBuf.ProtoReader.HasSubValue ( ProtoBuf.WireType  wireType,
ProtoReader  source 
)
inlinestatic

Indicates whether the reader still has data remaining in the current sub-item, additionally setting the wire-type for the next field if there is more data. This is used when decoding packed data.

Definition at line 1229 of file ProtoReader.cs.

void ProtoBuf.ProtoReader.Hint ( WireType  wireType)
inline

Compares the streams current wire-type to the hinted wire-type, updating the reader if necessary; for example, a Variant may be updated to SignedVariant. If the hinted wire-type is unrelated then no change is made.

Definition at line 690 of file ProtoReader.cs.

static object ProtoBuf.ProtoReader.Merge ( ProtoReader  parent,
object  from,
object  to 
)
inlinestatic

Merge two objects using the details from the current reader; this is used to change the type of objects when an inheritance relationship is discovered later than usual during deserilazation.

Definition at line 1307 of file ProtoReader.cs.

static void ProtoBuf.ProtoReader.NoteObject ( object  value,
ProtoReader  reader 
)
inlinestatic

Utility method, not intended for public use; this helps maintain the root object is complex scenarios

Definition at line 1268 of file ProtoReader.cs.

bool ProtoBuf.ProtoReader.ReadBoolean ( )
inline

Reads a boolean value from the stream; supported wire-types: Variant, Fixed32, Fixed64

Returns

Definition at line 847 of file ProtoReader.cs.

byte ProtoBuf.ProtoReader.ReadByte ( )
inline

Reads an unsigned 8-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64

Definition at line 257 of file ProtoReader.cs.

unsafe double ProtoBuf.ProtoReader.ReadDouble ( )
inline

Reads a double-precision number from the stream; supported wire-types: Fixed32, Fixed64

Definition at line 517 of file ProtoReader.cs.

int ProtoBuf.ProtoReader.ReadFieldHeader ( )
inline

Reads a field header from the stream, setting the wire-type and retuning the field number. If no more fields are available, then 0 is returned. This methods respects sub-messages.

Definition at line 632 of file ProtoReader.cs.

short ProtoBuf.ProtoReader.ReadInt16 ( )
inline

Reads a signed 16-bit integer from the stream: Variant, Fixed32, Fixed64, SignedVariant

Definition at line 242 of file ProtoReader.cs.

int ProtoBuf.ProtoReader.ReadInt32 ( )
inline

Reads a signed 32-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant

Definition at line 273 of file ProtoReader.cs.

long ProtoBuf.ProtoReader.ReadInt64 ( )
inline

Reads a signed 64-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant

Definition at line 312 of file ProtoReader.cs.

static int ProtoBuf.ProtoReader.ReadLengthPrefix ( Stream  source,
bool  expectHeader,
PrefixStyle  style,
out int  fieldNumber 
)
inlinestatic

Reads the length-prefix of a message from a stream without buffering additional data, allowing a fixed-length reader to be created.

Definition at line 935 of file ProtoReader.cs.

static int ProtoBuf.ProtoReader.ReadLengthPrefix ( Stream  source,
bool  expectHeader,
PrefixStyle  style,
out int  fieldNumber,
out int  bytesRead 
)
inlinestatic

Reads the length-prefix of a message from a stream without buffering additional data, allowing a fixed-length reader to be created.

Definition at line 1006 of file ProtoReader.cs.

static object ProtoBuf.ProtoReader.ReadObject ( object  value,
int  key,
ProtoReader  reader 
)
inlinestatic

Reads (merges) a sub-message from the stream, internally calling StartSubItem and EndSubItem, and (in between) parsing the message in accordance with the model associated with the reader

Definition at line 539 of file ProtoReader.cs.

sbyte ProtoBuf.ProtoReader.ReadSByte ( )
inline

Reads a signed 8-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64, SignedVariant

Definition at line 265 of file ProtoReader.cs.

unsafe float ProtoBuf.ProtoReader.ReadSingle ( )
inline

Reads a single-precision number from the stream; supported wire-types: Fixed32, Fixed64

Definition at line 814 of file ProtoReader.cs.

string ProtoBuf.ProtoReader.ReadString ( )
inline

Reads a string from the stream (using UTF8); supported wire-types: String

Definition at line 466 of file ProtoReader.cs.

System.Type ProtoBuf.ProtoReader.ReadType ( )
inline

Reads a Type from the stream, using the model's DynamicTypeFormatting if appropriate; supported wire-types: String

Definition at line 1280 of file ProtoReader.cs.

ushort ProtoBuf.ProtoReader.ReadUInt16 ( )
inline

Reads an unsigned 16-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64

Definition at line 249 of file ProtoReader.cs.

uint ProtoBuf.ProtoReader.ReadUInt32 ( )
inline

Reads an unsigned 32-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64

Definition at line 177 of file ProtoReader.cs.

ulong ProtoBuf.ProtoReader.ReadUInt64 ( )
inline

Reads an unsigned 64-bit integer from the stream; supported wire-types: Variant, Fixed32, Fixed64

Definition at line 782 of file ProtoReader.cs.

void ProtoBuf.ProtoReader.SkipField ( )
inline

Discards the data for the current field.

Definition at line 720 of file ProtoReader.cs.

static SubItemToken ProtoBuf.ProtoReader.StartSubItem ( ProtoReader  reader)
inlinestatic

Begins consuming a nested message in the stream; supported wire-types: StartGroup, String

The token returned must be help and used when callining EndSubItem

Definition at line 607 of file ProtoReader.cs.

void ProtoBuf.ProtoReader.ThrowEnumException ( System.Type  type,
int  value 
)
inline

Throws an exception indication that the given value cannot be mapped to an enum.

Definition at line 497 of file ProtoReader.cs.

bool ProtoBuf.ProtoReader.TryReadFieldHeader ( int  field)
inline

Looks ahead to see whether the next field in the stream is what we expect (typically; what we've just finished reading - for example ot read successive list items)

Definition at line 661 of file ProtoReader.cs.

Property Documentation

SerializationContext ProtoBuf.ProtoReader.Context
get

Addition information about this deserialization operation.

Definition at line 90 of file ProtoReader.cs.

int ProtoBuf.ProtoReader.FieldNumber
get

Gets the number of the field being processed.

Definition at line 35 of file ProtoReader.cs.

bool ProtoBuf.ProtoReader.InternStrings
getset

Gets / sets a flag indicating whether strings should be checked for repetition; if true, any repeated UTF-8 byte sequence will result in the same String instance, rather than a second instance of the same string. Enabled by default. Note that this uses a custom interner - the system-wide string interner is not used.

Definition at line 62 of file ProtoReader.cs.

TypeModel ProtoBuf.ProtoReader.Model
get

Get the TypeModel associated with this reader

Definition at line 684 of file ProtoReader.cs.

int ProtoBuf.ProtoReader.Position
get

Returns the position of the current reader (note that this is not necessarily the same as the position in the underlying stream, if multiple readers are used on the same stream)

Definition at line 203 of file ProtoReader.cs.

WireType ProtoBuf.ProtoReader.WireType
get

Indicates the underlying proto serialization format on the wire.

Definition at line 39 of file ProtoReader.cs.


The documentation for this class was generated from the following file: