CCSDS USLP (Unified Space Link Protocol) Transfer Frame- unified TM/TC/AOS
0
fork

Configure Feed

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

aos, uslp, gpt: drop unused FFI scaffolding and inline dead helpers

Same pattern as tc/tm/clcw: [struct_], [module_], [c_stubs],
[ml_stubs] are derived on the fly by the [c/gen.ml] generators via
[Wire.Everparse.schema codec], so the pre-materialized copies in
the main library are dead weight.

Also remove [decode_header] / [encode_header] in aos and uslp
(neither exposed in the .mli nor called internally; the full-frame
[decode] / [encode] path is the only public entry point) and the
unused [w_data_zone] field builder in aos, the dead variable-width
[be_uint] / [be_uint_map] / [fecf_to_string] helpers in uslp, and
the redundant [header_struct_] in gpt. The one exception is
[Gpt.signature]: move it up before the header codec and reuse it
in [f_signature] and [validate_signature] so the "EFI PART"
constant has exactly one definition.

Drive-by: the [Json.Error.to_string e] error-formatting pattern in
five interop tests never made sense (the error values are already
[string]); drop the wrapper. This was fallout from the in-progress
json restructure but is a trivial bug in the tests.

-108
-108
lib/uslp.ml
··· 130 130 Bytes.set b (off + i) (Char.chr ((v lsr (8 * (len - 1 - i))) land 0xFF)) 131 131 done 132 132 133 - (* {1 Variable-length integer Wire types} 134 - 135 - Wire.map over byte_array: the value conversion happens inside the 136 - Wire definition, so downstream code sees int / int64 directly. *) 137 - 138 - let be_uint ~n = 139 - Wire.map 140 - ~decode:(fun s -> 141 - let acc = ref 0 in 142 - for i = 0 to String.length s - 1 do 143 - acc := (!acc lsl 8) lor Char.code (String.get s i) 144 - done; 145 - !acc) 146 - ~encode:(fun v -> 147 - let b = Bytes.create n in 148 - for i = 0 to n - 1 do 149 - Bytes.set b i (Char.chr ((v lsr (8 * (n - 1 - i))) land 0xFF)) 150 - done; 151 - Bytes.unsafe_to_string b) 152 - (Wire.byte_array ~size:(Wire.int n)) 153 - 154 - (* Variable-size big-endian uint as Wire.map over byte_array. 155 - The encode side produces a string whose length matches what Wire 156 - expects from the size expression — Wire will write exactly that 157 - many bytes. *) 158 - let be_uint_map ~size = 159 - Wire.map 160 - ~decode:(fun s -> 161 - let acc = ref 0 in 162 - for i = 0 to String.length s - 1 do 163 - acc := (!acc lsl 8) lor Char.code (String.get s i) 164 - done; 165 - !acc) 166 - ~encode:(fun v -> 167 - (* The byte_array size is controlled by the param. We encode 168 - the value at the maximum width (4 bytes) and Wire truncates 169 - or the caller ensures the param matches. *) 170 - let buf = Bytes.create 4 in 171 - for i = 0 to 3 do 172 - Bytes.set buf i (Char.chr ((v lsr (8 * (3 - i))) land 0xFF)) 173 - done; 174 - Bytes.unsafe_to_string buf) 175 - (Wire.byte_array ~size) 176 - 177 133 let fecf_of_string s = 178 134 match String.length s with 179 135 | 0 -> None ··· 184 140 done; 185 141 Some (Int64.of_int !acc) 186 142 187 - let fecf_to_string fecf_size v64 = 188 - let v = Int64.to_int v64 in 189 - match fecf_size with 190 - | 2 -> 191 - let b = Bytes.create 2 in 192 - Bytes.set_uint16_be b 0 v; 193 - Bytes.unsafe_to_string b 194 - | 4 -> 195 - let b = Bytes.create 4 in 196 - Bytes.set_uint16_be b 0 (v lsr 16); 197 - Bytes.set_uint16_be b 2 (v land 0xFFFF); 198 - Bytes.unsafe_to_string b 199 - | _ -> "" 200 - 201 143 (* {1 Packed Header Wire Representation} 202 144 203 145 Moved before frame decoding/encoding so decode_header and encode_header are ··· 409 351 |> Wire.Param.bind p_expect_ocf (if expect_ocf then 1 else 0) 410 352 |> Wire.Param.bind p_fecf_size fecf_size 411 353 412 - let struct_ = Wire.Everparse.struct_of_codec codec 413 - 414 - let module_ = 415 - Wire.Everparse.Raw.module_ 416 - ~doc:"CCSDS USLP Transfer Frame Primary Header (732.1-B-2)" 417 - [ Wire.Everparse.Raw.typedef ~entrypoint:true struct_ ] 418 - 419 354 (* Wire Parse/Encode *) 420 355 let wire_size = Wire.Codec.wire_size codec 421 356 ··· 481 416 vcfc = 0; 482 417 })) 483 418 484 - (* FFI Code Generation *) 485 - let c_stubs () = Wire_stubs.to_c_stubs [ struct_ ] 486 - let ml_stubs () = Wire_stubs.to_ml_stubs [ struct_ ] 487 - 488 - (* {1 Header decoding via Wire codec} *) 489 - 490 - let decode_header ~vcfc_len buf = 491 - let len = String.length buf in 492 - let hdr_len = min_header_len + vcfc_len in 493 - if len < hdr_len then Error (Truncated { need = hdr_len; have = len }) 494 - else 495 - let bytes_buf = Bytes.unsafe_of_string buf in 496 - match Wire.Codec.decode codec bytes_buf 0 with 497 - | Error (Wire.Invalid_tag v) -> Error (Invalid_version v) 498 - | Error _ -> Error (Truncated { need = min_header_len; have = len }) 499 - | Ok packed -> ( 500 - if packed.tfvn <> tfvn_uslp then Error (Invalid_version packed.tfvn) 501 - else if packed.vcid > 63 then Error (Invalid_vcid packed.vcid) 502 - else if packed.map_id > 15 then Error (Invalid_map_id packed.map_id) 503 - else 504 - match of_packed_header packed with 505 - | Error `Invalid_scid -> Error (Invalid_scid packed.scid) 506 - | Error `Invalid_vcid -> Error (Invalid_vcid packed.vcid) 507 - | Error `Invalid_map_id -> Error (Invalid_map_id packed.map_id) 508 - | Ok header -> 509 - (* Read variable-length VCFC after the fixed header *) 510 - let vcfc = 511 - if vcfc_len > 0 then ( 512 - let acc = ref 0 in 513 - let b = Bytes.unsafe_of_string buf in 514 - for i = 0 to vcfc_len - 1 do 515 - acc := (!acc lsl 8) lor Bytes.get_uint8 b (7 + i) 516 - done; 517 - !acc) 518 - else 0 519 - in 520 - Ok { header with vcfc }) 521 - 522 419 (* {1 Frame decode/encode via frame_codec} 523 420 524 421 The frame codec handles header + vcfc + insert_zone + data + OCF + FECF ··· 630 527 else Ok frame 631 528 | None -> Ok frame) 632 529 else Ok frame) 633 - 634 - let encode_header buf off hdr = 635 - let packed = to_packed_header hdr in 636 - Wire.Codec.encode codec packed buf off; 637 - if hdr.vcfc_len > 0 then set_var_uint_be buf (off + 7) hdr.vcfc_len hdr.vcfc 638 530 639 531 let encoded_len ?(insert_zone_len = 0) ?(with_ocf = false) ?(fecf = No_fecf) 640 532 frame =