WireMapping Module
Compiles WireMappings for F# types, public or not, by reflection on their types, which .NET and Fable both have for F# types: the same for every encoding, so a contract's types mean the same in each. A mapping is compiled once, for every value it converts after, and compiling it fails for a type it doesn't support, so that a client or server finds out when it starts, not on its first call.
A record is a Map of its fields; a union case without fields is its name, one with fields a Map of its
name and its field, or an Array of its fields; a list, an array or a tuple is an Array; an option is
its value or Nil, or, when the value can itself be Nil, as in Some None, an Array of
the value; a map or a Dictionary keyed by strings is a Map, and by anything else an Array of [key, value]Arrays; a set, a ResizeArray or a HashSet is an Array; a float32 is the Float of its shortest text, 0.1 for 0.1f; a byte array is Bytes; a byte, an sbyte, an int16 and a uint16 are
Ints, read only within their bounds; an int64, a uint32, a uint64, a decimal and a Guid are strings, so
JavaScript's numbers don't round them; an enum's value is its name, or its number if it has none, such as flags
combined. Dates and times are ISO 8601 strings, the text of .NET's round-trip format:
a DateTime 2026-11-09T08:30:00.0000000Z, or without the Z if its kind is unspecified, and a local one
as UTC; a DateTimeOffset with its offset, +01:00; a DateOnly 2026-11-09; a TimeOnly
08:30:00.0000000; a TimeSpan 1.02:03:04.5000000. On Fable, which keeps milliseconds, a fraction of a
millisecond is lost. Reading, a float may be an Int, and bytes a base64 String, for the
encodings that can't tell them apart. Lists and options are checked before unions, which they also are to
reflection.
Functions and values
| Function or value |
Description
|
Full Usage:
compile t
Parameters:
Type
-
The type whose values the mapping converts
Returns: WireMapping
|
Compiles the mapping of t, or fails if its type isn't supported.
|
Orsak