Google.Protobuf.FieldCodec< T >

Summary

An encode/decode pair for a single field. This effectively encapsulates all the information needed to read or write the field value from/to a coded stream.

This class is public and has to be as it is used by generated code, but its public API is very limited - just what the generated code needs to call directly.

This never writes default values to the stream, and does not address "packedness" in repeated fields itself, other than to know whether or not the field should be packed.

Properties

DefaultValue
T
Default value for this codec.
FixedSize
int
Returns the fixed size for an entry, or 0 if sizes vary.
PackedRepeatedField
bool
Tag
uint
Gets the tag of the codec.
ValueReader
Func< CodedInputStream, T >
Returns a delegate to read a value from a coded input stream.
ValueSizeCalculator
Func< T, int >
Returns the size calculator for just a value.
ValueWriter
Action< CodedOutputStream, T >
Returns a delegate to write a value (unconditionally) to a coded output stream.

Public functions

CalculateSizeWithTag(T value)
int
Calculates the size required to write the given value, with a tag, if the value is not the default.
Read(CodedInputStream input)
T
Reads a value of the codec type from the given CodedInputStream.
WriteTagAndValue(CodedOutputStream output, T value)
void
Write a tag and the given value, if the value is not the default.

Properties

DefaultValue

T DefaultValue

Default value for this codec.

Usually the same for every instance of the same type, but for string/ByteString wrapper fields the codec's default value is null, whereas for other string/ByteString fields it's "" or ByteString.Empty.

The default value of the codec's type.

FixedSize

int FixedSize

Returns the fixed size for an entry, or 0 if sizes vary.

PackedRepeatedField

bool PackedRepeatedField

Tag

uint Tag

Gets the tag of the codec.

The tag of the codec.

ValueReader

Func< CodedInputStream, T > ValueReader

Returns a delegate to read a value from a coded input stream.

It is assumed that the stream is already positioned on the appropriate tag.

ValueSizeCalculator

Func< T, int > ValueSizeCalculator

Returns the size calculator for just a value.

ValueWriter

Action< CodedOutputStream, T > ValueWriter

Returns a delegate to write a value (unconditionally) to a coded output stream.

Public functions

CalculateSizeWithTag

int CalculateSizeWithTag(
  T value
)

Calculates the size required to write the given value, with a tag, if the value is not the default.

Read

T Read(
  CodedInputStream input
)

Reads a value of the codec type from the given CodedInputStream.

Details
Parameters
input
The input stream to read from.
Returns
The value read from the stream.

WriteTagAndValue

void WriteTagAndValue(
  CodedOutputStream output,
  T value
)

Write a tag and the given value, if the value is not the default.