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.
|
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.
int FixedSize
Returns the fixed size for an entry, or 0 if sizes vary.
bool PackedRepeatedField
uint Tag
Gets the tag of the codec.
The tag of the codec.
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.
Func< T, int > ValueSizeCalculator
Returns the size calculator for just a value.
Action< CodedOutputStream, T > ValueWriter
Returns a delegate to write a value (unconditionally) to a coded output stream.
int CalculateSizeWithTag( T value )
Calculates the size required to write the given value, with a tag, if the value is not the default.
T Read( CodedInputStream input )
Reads a value of the codec type from the given CodedInputStream.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
The value read from the stream.
|
void WriteTagAndValue( CodedOutputStream output, T value )
Write a tag and the given value, if the value is not the default.