Licklider Transmission Protocol (CCSDS 734.1-B) for reliable DTN links
0
fork

Configure Feed

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

fix(lint): resolve E320 long identifiers and E205 Format-to-Fmt conversion

Shorten test identifiers exceeding 4 underscores in test_cwt.ml,
test_jsonwt.ml, and test_linkedin_url.ml. Convert Format.fprintf/sprintf
to Fmt.pf/str in ocaml-ltp/lib/ltp.ml.

+62 -66
+40 -41
lib/ltp.ml
··· 47 47 type session_number = int64 48 48 type session_id = { originator : engine_id; number : session_number } 49 49 50 - let pp_session_id fmt s = Format.fprintf fmt "%Ld:%Ld" s.originator s.number 50 + let pp_session_id ppf s = Fmt.pf ppf "%Ld:%Ld" s.originator s.number 51 51 52 52 (* {1 Segment Types} *) 53 53 ··· 65 65 | Cancel_from_receiver 66 66 | Cancel_ack_to_receiver 67 67 68 - let pp_segment_type fmt = function 69 - | Red_data -> Format.fprintf fmt "Red_data" 70 - | Red_checkpoint -> Format.fprintf fmt "Red_checkpoint" 71 - | Red_checkpoint_eorp -> Format.fprintf fmt "Red_checkpoint_eorp" 72 - | Red_checkpoint_eorp_eob -> Format.fprintf fmt "Red_checkpoint_eorp_eob" 73 - | Green_data -> Format.fprintf fmt "Green_data" 74 - | Green_eob -> Format.fprintf fmt "Green_eob" 75 - | Report -> Format.fprintf fmt "Report" 76 - | Report_ack -> Format.fprintf fmt "Report_ack" 77 - | Cancel_from_sender -> Format.fprintf fmt "Cancel_from_sender" 78 - | Cancel_ack_to_sender -> Format.fprintf fmt "Cancel_ack_to_sender" 79 - | Cancel_from_receiver -> Format.fprintf fmt "Cancel_from_receiver" 80 - | Cancel_ack_to_receiver -> Format.fprintf fmt "Cancel_ack_to_receiver" 68 + let pp_segment_type ppf = function 69 + | Red_data -> Fmt.string ppf "Red_data" 70 + | Red_checkpoint -> Fmt.string ppf "Red_checkpoint" 71 + | Red_checkpoint_eorp -> Fmt.string ppf "Red_checkpoint_eorp" 72 + | Red_checkpoint_eorp_eob -> Fmt.string ppf "Red_checkpoint_eorp_eob" 73 + | Green_data -> Fmt.string ppf "Green_data" 74 + | Green_eob -> Fmt.string ppf "Green_eob" 75 + | Report -> Fmt.string ppf "Report" 76 + | Report_ack -> Fmt.string ppf "Report_ack" 77 + | Cancel_from_sender -> Fmt.string ppf "Cancel_from_sender" 78 + | Cancel_ack_to_sender -> Fmt.string ppf "Cancel_ack_to_sender" 79 + | Cancel_from_receiver -> Fmt.string ppf "Cancel_from_receiver" 80 + | Cancel_ack_to_receiver -> Fmt.string ppf "Cancel_ack_to_receiver" 81 81 82 82 let segment_type_to_int = function 83 83 | Red_data -> 0 ··· 121 121 | Rxmtcycexc 122 122 | Reserved of int 123 123 124 - let pp_cancel_reason fmt = function 125 - | User_cancelled -> Format.fprintf fmt "User_cancelled" 126 - | Unreachable -> Format.fprintf fmt "Unreachable" 127 - | Rlexc -> Format.fprintf fmt "Rlexc" 128 - | Miscolored -> Format.fprintf fmt "Miscolored" 129 - | System_cancelled -> Format.fprintf fmt "System_cancelled" 130 - | Rxmtcycexc -> Format.fprintf fmt "Rxmtcycexc" 131 - | Reserved n -> Format.fprintf fmt "Reserved(%d)" n 124 + let pp_cancel_reason ppf = function 125 + | User_cancelled -> Fmt.string ppf "User_cancelled" 126 + | Unreachable -> Fmt.string ppf "Unreachable" 127 + | Rlexc -> Fmt.string ppf "Rlexc" 128 + | Miscolored -> Fmt.string ppf "Miscolored" 129 + | System_cancelled -> Fmt.string ppf "System_cancelled" 130 + | Rxmtcycexc -> Fmt.string ppf "Rxmtcycexc" 131 + | Reserved n -> Fmt.pf ppf "Reserved(%d)" n 132 132 133 133 let cancel_reason_to_int = function 134 134 | User_cancelled -> 0 ··· 153 153 type extension_tag = Auth | Cookie | Unknown of int 154 154 type extension = { tag : extension_tag; value : string } 155 155 156 - let pp_extension fmt ext = 156 + let pp_extension ppf ext = 157 157 let tag_str = 158 158 match ext.tag with 159 159 | Auth -> "Auth" 160 160 | Cookie -> "Cookie" 161 - | Unknown n -> Format.sprintf "Unknown(%d)" n 161 + | Unknown n -> Fmt.str "Unknown(%d)" n 162 162 in 163 - Format.fprintf fmt "%s(%d bytes)" tag_str (String.length ext.value) 163 + Fmt.pf ppf "%s(%d bytes)" tag_str (String.length ext.value) 164 164 165 165 let extension_tag_to_int = function 166 166 | Auth -> 0x00 ··· 176 176 177 177 type reception_claim = { offset : int64; length : int64 } 178 178 179 - let pp_reception_claim fmt c = Format.fprintf fmt "[%Ld+%Ld]" c.offset c.length 179 + let pp_reception_claim ppf c = Fmt.pf ppf "[%Ld+%Ld]" c.offset c.length 180 180 181 181 (* {1 Segment Content} *) 182 182 ··· 215 215 content : segment_content; 216 216 } 217 217 218 - let pp_segment fmt seg = 219 - Format.fprintf fmt 220 - "@[<v 2>LTP segment {@ session=%a@ type=%a@ content=%s@ }@]" pp_session_id 221 - seg.session_id pp_segment_type seg.segment_type 218 + let pp_segment ppf seg = 219 + Fmt.pf ppf "@[<v 2>LTP segment {@ session=%a@ type=%a@ content=%s@ }@]" 220 + pp_session_id seg.session_id pp_segment_type seg.segment_type 222 221 (match seg.content with 223 222 | Data d -> 224 - Format.sprintf "Data(%Ld bytes at %Ld)" 223 + Fmt.str "Data(%Ld bytes at %Ld)" 225 224 (Int64.of_int (String.length d.data)) 226 225 d.block_offset 227 226 | Report r -> 228 - Format.sprintf "Report(serial=%Ld, %d claims)" r.report_serial 227 + Fmt.str "Report(serial=%Ld, %d claims)" r.report_serial 229 228 (List.length r.claims) 230 - | Report_ack r -> Format.sprintf "Report_ack(%Ld)" r.report_serial 231 - | Cancel c -> Format.asprintf "Cancel(%a)" pp_cancel_reason c.reason 229 + | Report_ack r -> Fmt.str "Report_ack(%Ld)" r.report_serial 230 + | Cancel c -> Fmt.str "Cancel(%a)" pp_cancel_reason c.reason 232 231 | Cancel_ack () -> "Cancel_ack") 233 232 234 233 (* {1 Errors} *) ··· 241 240 | Extension_error of string 242 241 | Content_error of string 243 242 244 - let pp_error fmt = function 243 + let pp_error ppf = function 245 244 | Truncated { expected; got } -> 246 - Format.fprintf fmt "truncated: expected %d bytes, got %d" expected got 247 - | Invalid_version v -> Format.fprintf fmt "invalid version: %d" v 248 - | Invalid_segment_type t -> Format.fprintf fmt "invalid segment type: %d" t 249 - | Invalid_sdnv -> Format.fprintf fmt "invalid SDNV" 250 - | Extension_error msg -> Format.fprintf fmt "extension error: %s" msg 251 - | Content_error msg -> Format.fprintf fmt "content error: %s" msg 245 + Fmt.pf ppf "truncated: expected %d bytes, got %d" expected got 246 + | Invalid_version v -> Fmt.pf ppf "invalid version: %d" v 247 + | Invalid_segment_type t -> Fmt.pf ppf "invalid segment type: %d" t 248 + | Invalid_sdnv -> Fmt.string ppf "invalid SDNV" 249 + | Extension_error msg -> Fmt.pf ppf "extension error: %s" msg 250 + | Content_error msg -> Fmt.pf ppf "content error: %s" msg 252 251 253 252 (* {1 Encoding} *) 254 253
+22 -25
test/test.ml
··· 9 9 10 10 (* {1 SDNV Tests} *) 11 11 12 - let test_sdnv_zero () = 12 + let sdnv_zero () = 13 13 let encoded = Ltp.encode_sdnv 0L in 14 14 Alcotest.(check string) "zero" "\x00" encoded; 15 15 match Ltp.decode_sdnv encoded 0 with ··· 18 18 Alcotest.(check int) "offset" 1 off 19 19 | Error e -> Alcotest.fail e 20 20 21 - let test_sdnv_small () = 21 + let sdnv_small () = 22 22 let encoded = Ltp.encode_sdnv 127L in 23 23 Alcotest.(check string) "127" "\x7f" encoded; 24 24 match Ltp.decode_sdnv encoded 0 with 25 25 | Ok (v, _) -> Alcotest.(check int64) "decoded" 127L v 26 26 | Error e -> Alcotest.fail e 27 27 28 - let test_sdnv_multi_byte () = 28 + let sdnv_multi_byte () = 29 29 let encoded = Ltp.encode_sdnv 128L in 30 30 Alcotest.(check int) "length" 2 (String.length encoded); 31 31 match Ltp.decode_sdnv encoded 0 with 32 32 | Ok (v, _) -> Alcotest.(check int64) "decoded" 128L v 33 33 | Error e -> Alcotest.fail e 34 34 35 - let test_sdnv_large () = 35 + let sdnv_large () = 36 36 let value = 0x1234567890L in 37 37 let encoded = Ltp.encode_sdnv value in 38 38 match Ltp.decode_sdnv encoded 0 with ··· 41 41 42 42 (* {1 Segment Type Tests} *) 43 43 44 - let test_segment_type_roundtrip () = 44 + let segment_type_roundtrip () = 45 45 let types = 46 46 [ 47 47 Ltp.Red_data; ··· 72 72 73 73 (* {1 Data Segment Tests} *) 74 74 75 - let test_green_data_roundtrip () = 75 + let green_data_roundtrip () = 76 76 let data = "Hello, LTP!" in 77 77 let seg = 78 78 Ltp.data_segment ~session_id ~client_service_id:1L ~block_offset:0L data ··· 89 89 | _ -> Alcotest.fail "wrong content type") 90 90 | Error e -> Alcotest.failf "decode failed: %a" Ltp.pp_error e 91 91 92 - let test_red_checkpoint_roundtrip () = 92 + let red_checkpoint_roundtrip () = 93 93 let data = "Checkpoint data" in 94 94 let seg = 95 95 Ltp.data_segment ~session_id ~client_service_id:2L ~block_offset:100L ··· 113 113 114 114 (* {1 Report Segment Tests} *) 115 115 116 - let test_report_roundtrip () = 116 + let report_roundtrip () = 117 117 let claims = 118 118 [ Ltp.{ offset = 0L; length = 100L }; Ltp.{ offset = 200L; length = 50L } ] 119 119 in ··· 135 135 136 136 (* {1 Report Ack Tests} *) 137 137 138 - let test_report_ack_roundtrip () = 138 + let report_ack_roundtrip () = 139 139 let seg = Ltp.report_ack ~session_id ~report_serial:42L in 140 140 let encoded = Ltp.encode_segment seg in 141 141 match Ltp.decode_segment encoded with ··· 148 148 149 149 (* {1 Cancel Tests} *) 150 150 151 - let test_cancel_roundtrip () = 151 + let cancel_roundtrip () = 152 152 let seg = Ltp.cancel ~session_id ~from_sender:true Ltp.Rlexc in 153 153 Alcotest.(check bool) 154 154 "is cancel from sender" true ··· 162 162 | _ -> Alcotest.fail "wrong content type") 163 163 | Error e -> Alcotest.failf "decode failed: %a" Ltp.pp_error e 164 164 165 - let test_cancel_ack_roundtrip () = 165 + let cancel_ack_roundtrip () = 166 166 let seg = Ltp.cancel_ack ~session_id ~to_sender:false in 167 167 Alcotest.(check bool) 168 168 "is cancel ack to receiver" true ··· 183 183 @ [ 184 184 ( "SDNV", 185 185 [ 186 - Alcotest.test_case "zero" `Quick test_sdnv_zero; 187 - Alcotest.test_case "small" `Quick test_sdnv_small; 188 - Alcotest.test_case "multi-byte" `Quick test_sdnv_multi_byte; 189 - Alcotest.test_case "large" `Quick test_sdnv_large; 186 + Alcotest.test_case "zero" `Quick sdnv_zero; 187 + Alcotest.test_case "small" `Quick sdnv_small; 188 + Alcotest.test_case "multi-byte" `Quick sdnv_multi_byte; 189 + Alcotest.test_case "large" `Quick sdnv_large; 190 190 ] ); 191 191 ( "segment_type", 192 - [ Alcotest.test_case "roundtrip" `Quick test_segment_type_roundtrip ] 193 - ); 192 + [ Alcotest.test_case "roundtrip" `Quick segment_type_roundtrip ] ); 194 193 ( "data", 195 194 [ 196 - Alcotest.test_case "green roundtrip" `Quick 197 - test_green_data_roundtrip; 195 + Alcotest.test_case "green roundtrip" `Quick green_data_roundtrip; 198 196 Alcotest.test_case "red checkpoint roundtrip" `Quick 199 - test_red_checkpoint_roundtrip; 197 + red_checkpoint_roundtrip; 200 198 ] ); 201 - ( "report", 202 - [ Alcotest.test_case "roundtrip" `Quick test_report_roundtrip ] ); 199 + ("report", [ Alcotest.test_case "roundtrip" `Quick report_roundtrip ]); 203 200 ( "report_ack", 204 - [ Alcotest.test_case "roundtrip" `Quick test_report_ack_roundtrip ] ); 201 + [ Alcotest.test_case "roundtrip" `Quick report_ack_roundtrip ] ); 205 202 ( "cancel", 206 203 [ 207 - Alcotest.test_case "roundtrip" `Quick test_cancel_roundtrip; 208 - Alcotest.test_case "ack roundtrip" `Quick test_cancel_ack_roundtrip; 204 + Alcotest.test_case "roundtrip" `Quick cancel_roundtrip; 205 + Alcotest.test_case "ack roundtrip" `Quick cancel_ack_roundtrip; 209 206 ] ); 210 207 ])