Show / Hide Table of Contents

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
System.Object
FieldCodec<T>
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Protobuf
Assembly: Google.Protobuf.dll
Syntax
public sealed class FieldCodec<T>
Type Parameters
Name Description
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)

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

Declaration
public int CalculateSizeWithTag(T value)
Parameters
Type Name Description
T value
Returns
Type Description
System.Int32

Read(CodedInputStream)

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

Declaration
public T Read(CodedInputStream input)
Parameters
Type Name Description
CodedInputStream input

The input stream to read from.

Returns
Type Description
T

The value read from the stream.

WriteTagAndValue(CodedOutputStream, T)

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

Declaration
public void WriteTagAndValue(CodedOutputStream output, T value)
Parameters
Type Name Description
CodedOutputStream output
T value
Back to top