Class ValueObjectProtoSerializer<TSelf, TValue, TProfile>
Namespace: AdCodicem.ValueObjects.ProtobufNet
Assembly: AdCodicem.ValueObjects.ProtobufNet.dll
Writes a value object as protobuf-net writes its underlying type at the level TProfile names,
and reads it back through its rules unless the profile trusts the bytes.
public sealed class ValueObjectProtoSerializer<TSelf, TValue, TProfile> : ISerializer<TSelf>, ISerializer<TSelf?> where TSelf : struct, IValueObject<TSelf, TValue> where TProfile : IValueObjectProtoProfile
Type Parameters
TSelf
Value object type.
TValue
Underlying value type.
TProfile
The trust and the compatibility level, one of
Inheritance
object ← ValueObjectProtoSerializer<TSelf, TValue, TProfile>
Implements
ISerializer<TSelf>, ISerializer<TSelf?>
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
The value goes through TypeModel.GetInbuiltSerializer<TValue> at the profile's level, so a value object
writes what protobuf-net writes for the primitive it replaces at that level, but a valid zero, which it writes where
protobuf-net leaves out the primitive's, and a formatting hook of the value object never reaches the wire. protobuf-net calls a custom serializer whatever [CompatibilityLevel] a member, a
type or an assembly declares, and whatever DataFormat a member declares: the profile alone decides, and a
ZigZag, FixedSize or WellKnown member of a value object is written and read as
DataFormat.Default writes the underlying type, so such a member keeps its primitive type or its .proto
changes. A root value object, the message itself, is written at the profile's level too, where protobuf-net writes a
root primitive at
A strict read goes through TryCreate, which normalizes the value, and refuses one the value object rejects with
a CreateUnchecked. Either way, a value the inbuilt serializer cannot read, of another wire type or beyond the range
of TValue, is refused with
A write refuses, with a Create, or was read by a trusted serializer.
Properties
Features
Indicates the features (including the default wire-type) for this type/serializer
public SerializerFeatures Features { get; }
Property Value
SerializerFeatures
Exceptions
protobuf-net has no inbuilt serializer for TValue.
Methods
Read(ref State, TSelf)
Deserialize an instance from the supplied writer
public TSelf Read(ref ProtoReader.State state, TSelf value)
Parameters
state ProtoReader.State
value TSelf
Returns
TSelf
Exceptions
ProtoException
The value read is one the inbuilt serializer of the underlying type cannot read, or, unless the profile is trusted, one the value object refuses.
Write(ref State, TSelf)
Serialize an instance to the supplied writer
public void Write(ref ProtoWriter.State state, TSelf value)
Parameters
state ProtoWriter.State
value TSelf
Exceptions
ProtoException
value equals default(TSelf) and holds a value the value object rejects.