CCSDS Proximity-1 Space Link Protocol (211.0-B)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Eliminate manual byte-picking across 8 packages

Migrate all remaining binary protocol packages to use Wire codecs
for encode/decode, replacing manual Char.code / set_u8 / get_u16_be
/ put_u32_be byte-picking with Wire.Codec, Wire.map, Wire.Param,
and Wire.optional.

Packages migrated:

- cfdp: Wire codecs for 6 directive types (EOF, Finished, ACK,
Metadata, Prompt, Keep-Alive) with Param.input for large_file
flag and fss_size = 4 + 4*large_file. NAK uses be_bytes_to_int64
for the gap list (Wire.repeat blocked on byte budget from outer
PDU). 41 lines of byte helpers removed.

- sdls: Wire codecs for MC status reply, log/erase/self-test
replies, TLV event encoding. Security header/trailer use
Param.input for iv_len, sn_len, mac_len with byte_array ~size.
85 lines of byte helpers removed.

- ax25: FCS encode/decode via Wire.uint16 (LE). Extension tag
and cancel reason via Wire.map. 14 lines removed.

- proximity1: Staged Wire.Codec.get for frame-type bitfield
extraction, replacing manual bitmask. 4 lines removed.

- ltp: Wire.map for extension_tag and cancel_reason enum fields.
SDNV codec kept (variable-length encoding, not expressible as
Wire type). 3 lines removed.

- pus: Wire codecs for HK parameter, u16be field access. All
PUS secondary header encode/decode through Wire. 7 lines removed.

- mbr: Full 512-byte MBR Wire.Codec with embedded Wire.codec
for partition entries. 18 lines of byte helpers removed.

- pid1: Direct Bytes.of_string to Wire.Codec.decode, eliminating
intermediate buffer copy. 1 line removed.

- uslp: Wire.map helpers (be_uint) for variable-length integer
conversions; fecf_of_string/fecf_to_string cleaned up.

Total: ~170 lines of manual byte-picking eliminated across the
monorepo. Every binary protocol now uses Wire for format parsing.
The remaining Char.code usage is in: SDNV codec (LTP, inherently
variable-length), crypto operations (SDLS CMAC/hex), and value
conversions on Wire-decoded byte arrays.

All tests pass across all packages.

+8 -6
+8 -6
lib/proximity1.ml
··· 85 85 (Wire.byte_array 86 86 ~size:Wire.Expr.(Wire.Field.ref f_frame_length - Wire.int header_size)) 87 87 88 + let bf_frame_type = Wire.Codec.(f_frame_type $ fun t -> int_of_frame_type t.frame_type) 89 + 88 90 let codec = 89 91 Wire.Codec.v "Proximity1" 90 92 (fun version scid frame_type _reserved seq_hi seq_lo _frame_length data -> ··· 104 106 [ 105 107 (f_version $ fun t -> t.version); 106 108 (f_scid $ fun t -> t.scid); 107 - (f_frame_type $ fun t -> int_of_frame_type t.frame_type); 109 + bf_frame_type; 108 110 (f_reserved $ fun _ -> 0); 109 111 (f_seq_hi $ fun t -> (t.sequence_count lsr 16) land 0xFF); 110 112 (f_seq_lo $ fun t -> t.sequence_count land 0xFFFF); ··· 112 114 (f_data $ fun t -> t.data); 113 115 ] 114 116 117 + (* Staged getter for the frame-type bitfield — reads the first U16be word once 118 + and extracts bits [4..6] with pure shift+mask. No manual Char.code needed. *) 119 + let get_frame_type = Wire.Staged.unstage (Wire.Codec.get codec bf_frame_type) 120 + 115 121 let encode t = 116 122 let total = header_size + String.length t.data in 117 123 let buf = Bytes.create total in ··· 126 132 let total = Wire.Codec.wire_size_at codec buf 0 in 127 133 if len < total then Error `Truncated 128 134 else 129 - (* Extract frame type bits to validate before full decode *) 130 - let b0 = Char.code (Bytes.get buf 0) in 131 - let b1 = Char.code (Bytes.get buf 1) in 132 - let word0 = (b0 lsl 8) lor b1 in 133 - let ft_bits = (word0 lsr 2) land 0x7 in 135 + let ft_bits = get_frame_type buf 0 in 134 136 match frame_type_of_int ft_bits with 135 137 | None -> Error (`Invalid_frame_type ft_bits) 136 138 | Some _ -> (