Codec
type Codec<'t> =
{
Encoder: Encoder<'t>
Decoder: Decoder<'t>
}| Assembly | Ranvier.Wire |
| Attributes | [<NoComparison>] [<NoEquality>] |
An encoder and a decoder for the same type.
Building both from one description keeps them in step. See objectCodec and variantCodec.
Declared inside
Enum |
Fields
Encoder: Encoder<'t>Decoder: Decoder<'t>Functions and values
at<'t> (fieldNames: string list) (x: Codec<'t>) : Codec<'t>
at<'t> (fieldNames: string list) (x: Codec<'t>) : Codec<'t>Move a codec under a path of property names. Decoding reads the value there, encoding wraps it back in nested objects.
bigint: Codec<bigint>
bigint: Codec<bigint>A codec for bigint, using the same representation as Encode.bigint and Decode.bigint.
datetimeOffset: Codec<DateTimeOffset>
datetimeOffset: Codec<DateTimeOffset>A codec for DateTimeOffset, using the same representation as Encode.datetimeOffset and Decode.datetimeOffset.
decimal: Codec<decimal>
decimal: Codec<decimal>A codec for decimal, using the same representation as Encode.decimal and Decode.decimal.
decoder<'t> (c: Codec<'t>) : Decoder<'t>
decoder<'t> (c: Codec<'t>) : Decoder<'t>The decoder half of a codec.
encoder<'t> (c: Codec<'t>) : Encoder<'t>
encoder<'t> (c: Codec<'t>) : Encoder<'t>The encoder half of a codec.
fix<'t> (make: Codec<'t> -> Codec<'t>) : Codec<'t>
fix<'t> (make: Codec<'t> -> Codec<'t>) : Codec<'t>Build a codec which can refer to itself, for a recursive type such as a tree.
type Tree = Tree of value: int * children: Tree list
let codec : Codec<Tree> =
Codec.fix (fun self ->
objectCodec {
let! value =
Codec.field "value" (fun (Tree(v, _)) -> v) Codec.int
and! children =
Codec.field
"children"
(fun (Tree(_, c)) -> c)
(Codec.list self)
return Tree(value, children)
}
)
float: Codec<float>
float: Codec<float>A codec for float, using the same representation as Encode.float and Decode.float.
float32: Codec<float32>
float32: Codec<float32>A codec for float32, using the same representation as Encode.float32 and Decode.float32.
int16: Codec<int16>
int16: Codec<int16>A codec for int16, using the same representation as Encode.int16 and Decode.int16.
int64: Codec<int64>
int64: Codec<int64>A codec for int64, using the same representation as Encode.int64 and Decode.int64.
keyValuePairs<'t> (x: Codec<'t>) : Codec<(string * 't) list>
keyValuePairs<'t> (x: Codec<'t>) : Codec<(string * 't) list>A codec for a list of properties, as a JSON object.
lazily<'t> (codec: Lazy<Codec<'t>>) : Codec<'t>
lazily<'t> (codec: Lazy<Codec<'t>>) : Codec<'t>Defer the construction of a codec until it is first used, for mutually recursive types.
losslessOption<'t> (x: Codec<'t>) : Codec<'t option>
losslessOption<'t> (x: Codec<'t>) : Codec<'t option>A codec for an option, writing an object which carries the case.
Round-trips at any nesting depth, at the cost of a heavier representation.
lossyOption<'t> (x: Codec<'t>) : Codec<'t option>
lossyOption<'t> (x: Codec<'t>) : Codec<'t option>A codec for an option, writing Some x as x and None as null.
Lossy: a nested option does not round-trip. Use losslessOption when you need the distinction.
map<'t, 'u> (decoder: 't -> 'u) (encoder: 'u -> 't) (codec: Codec<'t>) : Codec<'u>
map<'t, 'u> (decoder: 't -> 'u) (encoder: 'u -> 't) (codec: Codec<'t>) : Codec<'u>Turn a codec into one for another type, given a conversion for each direction.
map'<'key, 'value when 'key: comparison> (key: Codec<'key>) (value: Codec<'value>) : Codec<Map<'key,'value>>
map'<'key, 'value when 'key: comparison> (key: Codec<'key>) (value: Codec<'value>) : Codec<Map<'key,'value>>A codec for a map, as an array of [ key, value ] pairs. Use it when the key is not a string.
nil<'a> (output: 'a) : Codec<'a>
nil<'a> (output: 'a) : Codec<'a>Encode any value as null, and decode null back to the given constant.
Every input encodes to the same null, so only the given value round-trips. Use it as a branch of oneOf to represent an absent value.
oneOf<'t> (codecs: Codec<'t> list) : Codec<'t>
oneOf<'t> (codecs: Codec<'t> list) : Codec<'t>Decode with the first codec of the list that succeeds, and always encode with the first one.
A value read through a fallback codec is written back with the first one, so it is not a round-trip. Use it to accept an old representation while writing the new one.
sbyte: Codec<sbyte>
sbyte: Codec<sbyte>A codec for sbyte, using the same representation as Encode.sbyte and Decode.sbyte.
string: Codec<string>
string: Codec<string>A codec for string, using the same representation as Encode.string and Decode.string.
timespan: Codec<TimeSpan>
timespan: Codec<TimeSpan>A codec for TimeSpan, using the same representation as Encode.timespan and Decode.timespan.
tuple2<'a, 'b> (a: Codec<'a>) (b: Codec<'b>) : Codec<'a * 'b>
tuple2<'a, 'b> (a: Codec<'a>) (b: Codec<'b>) : Codec<'a * 'b>A codec for a tuple of 2 elements, as a JSON array.
tuple3<'a, 'b, 'c> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) : Codec<'a * 'b * 'c>
tuple3<'a, 'b, 'c> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) : Codec<'a * 'b * 'c>A codec for a tuple of 3 elements, as a JSON array.
tuple4<'a, 'b, 'c, 'd> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) : Codec<'a * 'b * 'c * 'd>
tuple4<'a, 'b, 'c, 'd> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) : Codec<'a * 'b * 'c * 'd>A codec for a tuple of 4 elements, as a JSON array.
tuple5<'a, 'b, 'c, 'd, 'e> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) (e: Codec<'e>) : Codec<'a * 'b * 'c * 'd * 'e>
tuple5<'a, 'b, 'c, 'd, 'e> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) (e: Codec<'e>) : Codec<'a * 'b * 'c * 'd * 'e>A codec for a tuple of 5 elements, as a JSON array.
tuple6<'a, 'b, 'c, 'd, 'e, 'f> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) (e: Codec<'e>) (f: Codec<'f>) : Codec<'a * 'b * 'c * 'd * 'e * 'f>
tuple6<'a, 'b, 'c, 'd, 'e, 'f> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) (e: Codec<'e>) (f: Codec<'f>) : Codec<'a * 'b * 'c * 'd * 'e * 'f>A codec for a tuple of 6 elements, as a JSON array.
tuple7<'a, 'b, 'c, 'd, 'e, 'f, 'g> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) (e: Codec<'e>) (f: Codec<'f>) (g: Codec<'g>) : Codec<'a * 'b * 'c * 'd * 'e * 'f * 'g>
tuple7<'a, 'b, 'c, 'd, 'e, 'f, 'g> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) (e: Codec<'e>) (f: Codec<'f>) (g: Codec<'g>) : Codec<'a * 'b * 'c * 'd * 'e * 'f * 'g>A codec for a tuple of 7 elements, as a JSON array.
tuple8<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) (e: Codec<'e>) (f: Codec<'f>) (g: Codec<'g>) (h: Codec<'h>) : Codec<'a * 'b * 'c * 'd * 'e * 'f * 'g * 'h>
tuple8<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h> (a: Codec<'a>) (b: Codec<'b>) (c: Codec<'c>) (d: Codec<'d>) (e: Codec<'e>) (f: Codec<'f>) (g: Codec<'g>) (h: Codec<'h>) : Codec<'a * 'b * 'c * 'd * 'e * 'f * 'g * 'h>A codec for a tuple of 8 elements, as a JSON array.
uint16: Codec<uint16>
uint16: Codec<uint16>A codec for uint16, using the same representation as Encode.uint16 and Decode.uint16.
uint32: Codec<uint32>
uint32: Codec<uint32>A codec for uint32, using the same representation as Encode.uint32 and Decode.uint32.
uint64: Codec<uint64>
uint64: Codec<uint64>A codec for uint64, using the same representation as Encode.uint64 and Decode.uint64.
value: Codec<Json>
value: Codec<Json>A codec for the JSON tree itself, passing values through untouched.