open Wire type error_code = | Unknown_type | Unknown_version | Message_too_large | Apid_not_allocated | Host_busy | Malformed let error_code_to_int = function | Unknown_type -> 0x01 | Unknown_version -> 0x02 | Message_too_large -> 0x03 | Apid_not_allocated -> 0x04 | Host_busy -> 0x05 | Malformed -> 0x06 let error_code_of_int = function | 0x01 -> Some Unknown_type | 0x02 -> Some Unknown_version | 0x03 -> Some Message_too_large | 0x04 -> Some Apid_not_allocated | 0x05 -> Some Host_busy | 0x06 -> Some Malformed | _ -> None type t = { error_code : int; offending_type : int; offending_apid : int; offending_pay_len : int; reserved : int; } let codec = let open Codec in record "ErrorPayload" (fun error_code offending_type offending_apid offending_pay_len reserved -> { error_code; offending_type; offending_apid; offending_pay_len; reserved; }) |+ field "error_code" uint8 (fun t -> t.error_code) |+ field "offending_type" uint8 (fun t -> t.offending_type) |+ field "offending_apid" uint16be (fun t -> t.offending_apid) |+ field "offending_pay_len" uint16be (fun t -> t.offending_pay_len) |+ field "reserved" uint16be (fun t -> t.reserved) |> seal let v code ~offending_type ~offending_apid ~offending_pay_len = { error_code = error_code_to_int code; offending_type; offending_apid; offending_pay_len; reserved = 0; } let pp ppf t = Fmt.pf ppf "@[error(code=0x%02x type=0x%02x apid=%d pay_len=%d)@]" t.error_code t.offending_type t.offending_apid t.offending_pay_len let equal a b = a.error_code = b.error_code && a.offending_type = b.offending_type && a.offending_apid = b.offending_apid && a.offending_pay_len = b.offending_pay_len