Class ValueObjectFormatter<TSelf, TValue>
Namespace: AdCodicem.ValueObjects.MessagePack
Assembly: AdCodicem.ValueObjects.MessagePack.dll
Writes a value object as the bare value the options' formatter of its underlying type writes, and reads it back through the value object's rules.
public sealed class ValueObjectFormatter<TSelf, TValue> : IMessagePackFormatter<TSelf> where TSelf : struct, IValueObject<TSelf, TValue>
Type Parameters
TSelf
Value object type.
TValue
Underlying value type.
Inheritance
object ← ValueObjectFormatter<TSelf, TValue>
Implements
IMessagePackFormatter<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 the formatter the options' resolver holds for TValue, so a value object
writes exactly what the primitive it replaces writes under the same options: a StandardResolver and as 16 bytes under NativeGuidResolver, a Native* resolvers placed in the chain write them. A formatting hook of the value
object never reaches the wire.
A read is strict unless the formatter is trusted: the value read goes through TryCreate, which normalizes it,
and one the value object refuses throws a CreateUnchecked, for bytes the
application alone wrote, a cache among them. Either way, a nil is refused with
TSelf?, which MessagePack's own NullableFormatter reads as null without asking this
formatter; and a value the formatter of TValue cannot read, a value of another MessagePack
type, one beyond the range of TValue, text it cannot parse, truncated bytes, with
A write refuses, with a Create, or was read by a trusted formatter, and is written
as it is, without being validated again.
Constructors
ValueObjectFormatter(bool)
Initializes the formatter.
public ValueObjectFormatter(bool trusted = false)
Parameters
trusted bool
Whether a read skips validation, for bytes the application alone wrote; false, the default, reads through the value object's rules.
Methods
Deserialize(ref MessagePackReader, MessagePackSerializerOptions)
Deserializes a value.
public TSelf Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
Parameters
reader MessagePackReader
The reader to deserialize from.
options MessagePackSerializerOptions
The serialization settings to use, including the resolver to use to obtain formatters for types that make up the composite type T.
Returns
TSelf
The deserialized value.
Exceptions
options is null.
MessagePackSerializationException
The value read is a nil, which a value object cannot hold, a value the formatter of the underlying value
cannot read, or, unless the formatter is trusted, a value the value object refuses.
FormatterNotRegisteredException
The options' resolver holds no formatter for TValue.
Serialize(ref MessagePackWriter, TSelf, MessagePackSerializerOptions)
Serializes a value.
public void Serialize(ref MessagePackWriter writer, TSelf value, MessagePackSerializerOptions options)
Parameters
writer MessagePackWriter
The writer to use when serializing the value.
value TSelf
The value to be serialized.
options MessagePackSerializerOptions
The serialization settings to use, including the resolver to use to obtain formatters for types that make up the composite type T.
Exceptions
options is null.
MessagePackSerializationException
value equals default(TSelf) and holds a value the value object rejects.
FormatterNotRegisteredException
The options' resolver holds no formatter for TValue.