···930930 Wire.Codec.env codec
931931 |> Wire.Param.bind p_large_file (if large_file then 1 else 0)
932932933933+let entity_id_byte_width (eid : int64) =
934934+ (* Minimum number of bytes to represent this entity ID. *)
935935+ if eid = 0L then 1
936936+ else
937937+ let n = ref eid in
938938+ let w = ref 0 in
939939+ while !n <> 0L do
940940+ n := Int64.shift_right_logical !n 8;
941941+ incr w
942942+ done;
943943+ !w
944944+933945let encode_eof ~large_file (eof_pdu : eof) =
934946 let fss_len = if large_file then 8 else 4 in
935947 let base_size = 1 + 4 + fss_len in
···938950 match eof_pdu.fault_location with
939951 | None -> ""
940952 | Some eid ->
941941- (* TLV: type=0x06, length=8, value=entity_id as 8 BE bytes *)
942942- let tlv = Bytes.create 10 in
953953+ (* TLV: type=0x06, length=N, value=entity_id in minimal BE bytes *)
954954+ let v = Entity_id.to_int64 eid in
955955+ let n = entity_id_byte_width v in
956956+ let tlv = Bytes.create (2 + n) in
943957 Bytes.set_uint8 tlv 0 0x06;
944944- Bytes.set_uint8 tlv 1 8;
945945- let eid_s = int64_to_be_bytes 8 (Entity_id.to_int64 eid) in
946946- Bytes.blit_string eid_s 0 tlv 2 8;
958958+ Bytes.set_uint8 tlv 1 n;
959959+ let eid_s = int64_to_be_bytes n v in
960960+ Bytes.blit_string eid_s 0 tlv 2 n;
947961 Bytes.to_string tlv
948962 in
949963 let packed =