I like to hand-roll serialization so that I have full control, but this gives me an IEventCodec<'Event, string, 'Context>.
My category expects an IEventCodec<'Event, ReadOnlyMemory<byte>, 'Context> so a conversion is required.
I came up with these utilities, but perhaps they are already provided?
open FsCodec
open FsCodec.Core
type Encoder with
static member Unicode(native : IEventCodec<'Event, string, 'Context>) : IEventCodec<'Event, ReadOnlyMemory<byte>, 'Context> =
EventCodec.mapBodies
(fun (x : string) -> Encoding.Unicode.GetBytes(x) |> ReadOnlyMemory<byte>)
(fun (x : ReadOnlyMemory<byte>) -> Encoding.Unicode.GetString(x.Span))
native
static member UTF8(native : IEventCodec<'Event, string, 'Context>) : IEventCodec<'Event, ReadOnlyMemory<byte>, 'Context> =
EventCodec.mapBodies
(fun (x : string) -> Encoding.UTF8.GetBytes(x) |> ReadOnlyMemory<byte>)
(fun (x : ReadOnlyMemory<byte>) -> Encoding.UTF8.GetString(x.Span))
native
If desired can also send a PR.
Thanks!
I like to hand-roll serialization so that I have full control, but this gives me an
IEventCodec<'Event, string, 'Context>.My category expects an
IEventCodec<'Event, ReadOnlyMemory<byte>, 'Context>so a conversion is required.I came up with these utilities, but perhaps they are already provided?
If desired can also send a PR.
Thanks!