SpaceOS wire protocol codecs for host-guest communication
1(** SpaceOS fixed-size frame codec.
2
3 Every read/write is exactly 256 bytes. The [payload_length] field tells how
4 many of the 248 payload bytes are meaningful.
5
6 {v
7 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
8 | Version | Type | APID (uint16 BE) |
9 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
10 | Payload Length (uint16) | Reserved (uint16) |
11 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
12 | Payload (248 bytes, zero-padded) |
13 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
14 v} *)
15
16val frame_size : int
17(** Fixed frame size: 256 bytes. *)
18
19val header_size : int
20(** Header size: 8 bytes. *)
21
22val max_payload : int
23(** Maximum payload: 248 bytes. *)
24
25(** {1 Message types} *)
26
27type kind =
28 | TM
29 | TC
30 | EVR
31 | PRM_GET
32 | PRM_SET
33 | PRM_RSP
34 | DP
35 | HEALTH
36 | LOG
37 | ERROR
38
39val kind_to_int : kind -> int
40(** Convert a message type to its wire representation. *)
41
42val kind_of_int : int -> kind option
43(** Parse a message type from its wire representation. *)
44
45val pp_kind : kind Fmt.t
46(** Pretty-print a message type. *)
47
48(** {1 Frame} *)
49
50type t = {
51 version : int;
52 msg_type : int;
53 apid : int;
54 payload_length : int;
55 reserved : int;
56 payload : string;
57}
58
59val codec : t Wire.Codec.t
60(** Wire codec for the full 256-byte frame. *)
61
62val v : kind -> apid:int -> string -> t
63(** [v typ ~apid payload] builds a frame. Payload is truncated to 248 bytes. *)
64
65val payload_bytes : t -> string
66(** [payload_bytes t] returns the meaningful payload bytes (first
67 [payload_length] bytes). *)
68
69val pp : t Fmt.t
70(** Pretty-print a frame. *)
71
72val equal : t -> t -> bool
73(** Structural equality. *)