MessagePack.FSharpExtensions 4.0.0

MessagePack.FSharpExtensions

NuGet Status

MessagePack.FSharpExtensions is a MessagePack-CSharp extension library for F#.

Usage

open System
open System.Buffers
open MessagePack
open MessagePack.Resolvers
open MessagePack.FSharp

[<MessagePackObject>]
type UnionSample =
  | Foo of XYZ : int
  | Bar of OPQ : string list

let convertAsMemory<'T> options (value: 'T) =
  let memory = ReadOnlyMemory(MessagePackSerializer.Serialize(value, options))
  MessagePackSerializer.Deserialize<'T>(memory, options)

let convertAsSequence<'T> options (value: 'T) =
  let sequence = ReadOnlySequence(MessagePackSerializer.Serialize(value, options))
  MessagePackSerializer.Deserialize<'T>(& sequence, options)

let dump = function
| Foo x ->
  printfn "%d" x
| Bar xs ->
  printfn "%A" xs

let resolver =
  Resolvers.CompositeResolver.Create(
    FSharpResolver.Instance,
    StandardResolver.Instance
)

let options = MessagePackSerializerOptions.Standard.WithResolver(resolver)

Foo 999
|> convertAsMemory options
|> dump

Bar ["example"]
|> convertAsSequence options
|> dump

Supported types

  • option
  • voption
  • list
  • map
  • set
  • Discriminated Union
  • Struct Discriminated Union

Records, Struct Records and Anonymous Records are serialized and deserialized using DynamicObjectResolver in MessagePack-CSharp.

Showing the top 20 packages that depend on MessagePack.FSharpExtensions.

Packages Downloads
NBomber.Contracts
Public contracts for NBomber
3
NBomber.Contracts
Contracts for NBomber
3
NBomber.Contracts
Public contracts for NBomber
2

.NET Core 3.1

.NET 6.0

.NET Standard 2.0

Version Downloads Last updated
4.0.0 2 11/18/2024
3.0.0 1 11/18/2024
2.1.0 2 11/17/2024
2.0.0 1 11/18/2024
1.4.1 2 10/06/2024
1.4.0 3 10/06/2024
1.3.0 3 10/06/2024
1.2.0 1 11/18/2024
1.1.0 1 11/18/2024
1.0.0 1 11/18/2024
0.1.0 1 11/18/2024