package wire

  1. Overview
  2. Docs
Binary wire format DSL with EverParse 3D output

Install

dune-project
 Dependency

Authors

Maintainers

Sources

wire-1.0.0.tbz
sha256=323f48e6cb897fe48aac558b09bb25134d3b19fec37b20d7930eec15f387c238
sha512=00c77f8672396ab15d993602db9bab95d2478ace1f569606f0140ed25d7ff852525e53436d95e5061442a6ea8b5650549239c68ef861b4b921b4a53faac97eb7

doc/wire/Wire/Field/index.html

Module Wire.FieldSource

Sourcetype 'a t

A named field carrying values of type 'a.

Sourcetype 'a anon

An anonymous (padding) field. Cannot be referenced.

Sourcetype packed =
  1. | Named : 'a t -> packed
  2. | Anon : 'a anon -> packed
Sourceval 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 t

v 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.

Sourceval 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 t

optional name ~present t is a field present iff present evaluates to true. Absent fields decode as None and consume zero bytes.

Sourceval 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 t

optional_or name ~present ~default t is a field that decodes to the inner value when present, or default when absent.

Sourceval 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 t

repeat 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.

Sourceval 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 t

Like repeat but accumulates into a custom sequence via seq.

Sourceval anon : 'a typ -> 'a anon

anon typ creates an anonymous (padding) field.

Sourceval ref : 'a t -> int expr

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.

Sourceval int : 'a t -> int expr

int f returns this field as a native-integer expression.

Sourceval int64 : int64 t -> int64 expr

int64 f returns the expression referencing this field's full 64-bit value, without truncating to OCaml's native integer range.

Sourceval name : 'a t -> string

Field name.

Sourceval typ : 'a t -> 'a typ

Wire type.

Sourceval pp : Format.formatter -> 'a t -> unit

Pretty-print the field's name.

Sourceval constraint_ : 'a t -> bool expr option

Field constraint, if any.

Sourceval action : 'a t -> Wire__.Types.action option

Field action attached via v's ?action, if any.

Sourceval doc : 'a t -> string option

Field note attached via v's ?doc, if any.

Sourceval decl_of_packed : packed -> Wire__.Types.field

The Types.field declaration of a packed field.