Home

Awesome

ZeroFormatter Extensions for FSharp

Build status Build Status NuGet Status

ZeroFormatter.FSharpExtensions is a ZeroFormatter extension library for F#.

Usage

open ZeroFormatter
open ZeroFormatter.FSharp

[<ZeroFormattable>]
type MyRecord = {
  [<Index(0)>]
  Age: int
  [<Index(1)>]
  FirstName: string
  [<Index(2)>]
  LastName: string
  [<Index(3)>]
  List: int list
}
with
  member this.FullName = this.FirstName + this.LastName

let mr = {
  Age = 99
  FirstName = "hoge"
  LastName = "huga"
  List = [ 1; 10; 100 ]
}

let bytes = ZeroFormatterSerializer.Serialize(mr);
let mr2 = ZeroFormatterSerializer.Deserialize<MyRecord>(bytes)
printfn "%s" mr2.FullName

type Character =
  | Human of name : string * birth : DateTime * age : int * faith : int
  | Monster of race : string * power : int * magic : int

let daemon = Monster("Demon", 9999, 1000)
let data = ZeroFormatterSerializer.Serialize(daemon)
match ZeroFormatterSerializer.Deserialize(data) with
| Human(name, birth, age, faith) ->
  ...
| Monster(race, power, magic) ->
  ...

Null safety

You can use 'T option instead of Nullable<'T> or null.

Supported types

F#WireFormatNote
RecordStructversioning is not supported.
DUUnionversioning is not supported.
'T listSequence
Map<'K, 'V>Sequence
Set<'T>Sequence
unitInt32always -1