Class FieldCodec<T> (3.23.0)

public sealed class FieldCodec<T>

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.

Inheritance

object > FieldCodec<T>

Namespace

Google.Protobuf

Assembly

Google.Protobuf.dll

Type Parameter

NameDescription
T

Remarks

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.

Methods

CalculateSizeWithTag(T)

public int CalculateSizeWithTag(T value)

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

Parameter
NameDescription
valueT
Returns
TypeDescription
int

Read(CodedInputStream)

public T Read(CodedInputStream input)

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

Parameter
NameDescription
inputCodedInputStream

The input stream to read from.

Returns
TypeDescription
T

The value read from the stream.

Read(ref ParseContext)

public T Read(ref ParseContext ctx)

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

Parameter
NameDescription
ctxParseContext

The parse context to read from.

Returns
TypeDescription
T

The value read.

WriteTagAndValue(CodedOutputStream, T)

public void WriteTagAndValue(CodedOutputStream output, T value)

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

Parameters
NameDescription
outputCodedOutputStream
valueT

WriteTagAndValue(ref WriteContext, T)

public void WriteTagAndValue(ref WriteContext ctx, T value)

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

Parameters
NameDescription
ctxWriteContext
valueT