Codecs and Serialization
The Codec module registers manual encoders and decoders as one
MessagePackConverter inside a MessagePackSerializer.
Serializers are immutable, so each Codec function returns a new serializer.
The input serializer keeps its other settings.
A Manual Codec
let coordEncoder: Encoder<Coord> =
fun coord -> Encode.array [| Encode.int coord.X; Encode.int coord.Y |]
let coordDecoder: Decoder<Coord> =
fun value -> decode {
let! x = Decode.decodeAt Required.int 0 value
and! y = Decode.decodeAt Required.int 1 value
return { X = x; Y = y }
}
let serializer =
Codec.useCodec (MessagePackSerializer()) (coordEncoder, coordDecoder)
let shape = ReflectionTypeShapeProvider.Default.GetTypeShape<Coord>()
let mutable outgoing = { X = 3; Y = 4 }
let bytes: byte array = serializer.Serialize(&outgoing, shape)
let back: Coord = serializer.Deserialize(System.ReadOnlyMemory(bytes), shape)
printfn $"Coord: %A{back}"
Use Codec.useEncoder or Codec.useDecoder when only one direction needs help.
Use Codec.useCodecWithContext when a codec must read the active context.
Decoder failures raise DecodingException inside the converter.
MessagePackSerializer then wraps that error in MessagePackSerializationException.
Manual and Automatic Together
Decoding.auto delegates a whole payload to MessagePackSerializer.
Decoding.fromBytes runs one manual decoder on the decoded value.
Both return Result<'T, DecodeError>, so call sites handle both the same way.
One upstream limit applies: runtime converters do not target FSharp unions. Register codecs on records and other concrete types instead.
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
<summary> Encodes a value into a MessagePackValue. </summary>
<summary> Decodes a MessagePackValue into a value of type 'TResult. </summary>
module Decode from JDeck.MessagePack.Decode
--------------------
module Decode from JDeck.MessagePack
<summary> Required decoders fail when the value is missing or has the wrong kind. </summary>
<summary> Registers an encoder and a decoder and returns a new serializer. The input serializer keeps its other settings: only the converter collection changes, with the new converter first. Decoder failures raise DecodingException, which MessagePackSerializer wraps in MessagePackSerializationException. </summary>
--------------------
MessagePackSerializer() : MessagePackSerializer
<summary> Provides a <see cref="T:PolyType.ITypeShapeProvider" /> implementation that uses reflection. </summary>
<summary> Gets the default provider instance using configuration supported by the current platform. </summary>
ReflectionTypeShapeProvider.GetTypeShape(``type`` : System.Type) : PolyType.ITypeShape
val byte: value: 'T -> byte (requires member op_Explicit)
--------------------
type byte = System.Byte
--------------------
type byte<'Measure> = byte
(+0 other overloads)
(extension) MessagePackSerializer.Serialize<'T,'TProvider>(value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : byte array
(+0 other overloads)
MessagePackSerializer.Serialize<'T,'TProvider (requires 'TProvider :> PolyType.IShapeable<'T>)>(value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : byte array
(+0 other overloads)
MessagePackSerializer.Serialize<'T (requires 'T :> PolyType.IShapeable<'T>)>(value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : byte array
(+0 other overloads)
(extension) MessagePackSerializer.Serialize<'T>(writer: byref<MessagePackWriter>, value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : unit
(+0 other overloads)
(extension) MessagePackSerializer.Serialize<'T>(writer: System.Buffers.IBufferWriter<byte>, value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : unit
(+0 other overloads)
(extension) MessagePackSerializer.Serialize<'T>(stream: System.IO.Stream, value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : unit
(+0 other overloads)
(extension) MessagePackSerializer.Serialize<'T,'TProvider>(writer: byref<MessagePackWriter>, value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : unit
(+0 other overloads)
(extension) MessagePackSerializer.Serialize<'T,'TProvider>(writer: System.Buffers.IBufferWriter<byte>, value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : unit
(+0 other overloads)
(extension) MessagePackSerializer.Serialize<'T,'TProvider>(stream: System.IO.Stream, value: inref<'T>, ?cancellationToken: System.Threading.CancellationToken) : unit
(+0 other overloads)
(+0 other overloads)
(extension) MessagePackSerializer.Deserialize<'T>(bytes: System.ReadOnlyMemory<byte>, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
(extension) MessagePackSerializer.Deserialize<'T>(bytes: inref<System.Buffers.ReadOnlySequence<byte>>, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
(extension) MessagePackSerializer.Deserialize<'T>(stream: System.IO.Stream, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
(extension) MessagePackSerializer.Deserialize<'T,'TProvider>(reader: byref<MessagePackReader>, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
(extension) MessagePackSerializer.Deserialize<'T,'TProvider>(bytes: System.ReadOnlyMemory<byte>, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
(extension) MessagePackSerializer.Deserialize<'T,'TProvider>(bytes: inref<System.Buffers.ReadOnlySequence<byte>>, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
(extension) MessagePackSerializer.Deserialize<'T,'TProvider>(stream: System.IO.Stream, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
MessagePackSerializer.Deserialize<'T,'TProvider (requires 'TProvider :> PolyType.IShapeable<'T>)>(stream: System.IO.Stream, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
MessagePackSerializer.Deserialize<'T,'TProvider (requires 'TProvider :> PolyType.IShapeable<'T>)>(bytes: inref<System.Buffers.ReadOnlySequence<byte>>, ?cancellationToken: System.Threading.CancellationToken) : 'T
(+0 other overloads)
type ReadOnlyMemory<'T> = new: array: 'T array -> unit + 1 overload member CopyTo: destination: Memory<'T> -> unit member Equals: obj: obj -> bool + 1 overload member GetHashCode: unit -> int member Pin: unit -> MemoryHandle member Slice: start: int -> ReadOnlyMemory<'T> + 1 overload member ToArray: unit -> 'T array member ToString: unit -> string member TryCopyTo: destination: Memory<'T> -> bool static member op_Implicit: segment: ArraySegment<'T> -> ReadOnlyMemory<'T> + 1 overload ...
<summary>Represents a contiguous region of memory, similar to <see cref="T:System.ReadOnlySpan`1" />. Unlike <see cref="T:System.ReadOnlySpan`1" />, it is not a byref-like type.</summary>
<typeparam name="T">The object type from which the contiguous region of memory will be read.</typeparam>
--------------------
System.ReadOnlyMemory ()
System.ReadOnlyMemory(array: 'T array) : System.ReadOnlyMemory<'T>
System.ReadOnlyMemory(array: 'T array, start: int, length: int) : System.ReadOnlyMemory<'T>
JDeck