Given an index, produce the corresponding decoding function or nothing if the index is out of bounds.
Given an index, produce the corresponding decoding function or nothing if the index is out of bounds.
Encode a value of the sum type into a tree and the index.
Encode a value of the sum type into a tree and the index.
Decode a value from an XML tree, or produce an error.
Encode a value into an XML tree.
Codec for a list of T
s, tagged with the string list
.
Codec for a list of T
s, tagged with the string list
.
Create an identical codec which adds (or expects, respectively) an additional top-level tag.
Create an identical codec which adds (or expects, respectively) an additional top-level tag.
The given tag can be anything acceptable as an XML attribute value, but should be globally unique. That is, no other codec should have the same tag. It is fine if there are multiple codecs for a type, as long as their tags are distinct, although that is not a requirement.
Transform a codec for a type T
into a codec for a type U
by applying
one of the two specified conversions.
Codec for a pair of T
and U
, tagged with the string tuple
.
Codec for a pair of T
and U
, tagged with the string tuple
.
Template for a codec for a sum type
A
.Each constructor of
A
should get assigned a unique index when implementing this class. It is used to tag XML trees, so that the correct decoding function can be chosen.In addition to the contract of
Codec
, instances of this class must also preserve the index, that is, any index returned byenc
must produce a valid decoding function indec
.Using this is simple: Instead of creating a new
Codec
object, create an object extending from this class and implementenc
anddec
accordingly. It is automatically aCodec
.Example usage