package wire
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=323f48e6cb897fe48aac558b09bb25134d3b19fec37b20d7930eec15f387c238
sha512=00c77f8672396ab15d993602db9bab95d2478ace1f569606f0140ed25d7ff852525e53436d95e5061442a6ea8b5650549239c68ef861b4b921b4a53faac97eb7
doc/wire/Wire/Field/index.html
Module Wire.FieldSource
A named field carrying values of type 'a.
An anonymous (padding) field. Cannot be referenced.
val v :
string ->
?constraint_:bool expr ->
?self_constraint:(int expr -> bool expr) ->
?self_int64:(int64 expr -> bool expr) ->
?action:Action.t ->
?doc:string ->
'a typ ->
'a tv name typ creates a named field. ?doc attaches a free-text note (e.g. an RFC section) that the documentation projection renders as a /* ... */ comment on the field in the generated 3D. ?self_constraint receives the field's own ref and returns a constraint over it; useful for proving a later size-expression safe (e.g. self >= int 7 when a later field uses byte_slice ~size:(ref len - int 7)). ?self_int64 is the same convenience for full-width 64-bit constraints using Expr.int64 literals and int64 field references.
Use optional / optional_or / repeat for optional and repeating payloads -- they only project to 3D as the top of a struct field, never as a nested type.
val optional :
string ->
?constraint_:bool expr ->
?self_constraint:(int expr -> bool expr) ->
?self_int64:(int64 expr -> bool expr) ->
?action:Action.t ->
present:bool expr ->
'a typ ->
'a option toptional name ~present t is a field present iff present evaluates to true. Absent fields decode as None and consume zero bytes.
val optional_or :
string ->
?constraint_:bool expr ->
?self_constraint:(int expr -> bool expr) ->
?self_int64:(int64 expr -> bool expr) ->
?action:Action.t ->
present:bool expr ->
default:'a ->
'a typ ->
'a toptional_or name ~present ~default t is a field that decodes to the inner value when present, or default when absent.
val repeat :
string ->
?constraint_:bool expr ->
?self_constraint:(int expr -> bool expr) ->
?self_int64:(int64 expr -> bool expr) ->
?action:Action.t ->
size:int expr ->
'a typ ->
'a list trepeat name ~size t parses elements of type t until size bytes are consumed. The bound is a byte budget, not an element count, which is what lets the elements be variable-size (a tagged union, a length-prefixed sub-codec). It projects to 3D as t name[:byte-size size]. There is no count-driven form: "a count field, then that many variable-size elements" is expressible neither here nor in 3D (3D arrays are byte-budgeted), so that shape needs caller-side iteration over the element parser.
val repeat_seq :
string ->
?constraint_:bool expr ->
?self_constraint:(int expr -> bool expr) ->
?self_int64:(int64 expr -> bool expr) ->
?action:Action.t ->
seq:('a, 'seq) Wire__.Types.seq_map ->
size:int expr ->
'a typ ->
'seq tLike repeat but accumulates into a custom sequence via seq.
ref f returns the expression referencing this field's underlying integer value. Works on any field whose wire type is or wraps an integer, including boolean fields created with bit.
int64 f returns the expression referencing this field's full 64-bit value, without truncating to OCaml's native integer range.
Pretty-print the field's name.