This commit is contained in:
swrup 2026-02-11 00:31:03 +01:00
parent 2dda037001
commit b2d499d87a
3 changed files with 13 additions and 13 deletions

View file

@ -14,8 +14,7 @@ type t = {
fraction: Int32.t;
}
(* rm Zarith *)
let value_upper_bound = Z.(pow (of_int 2) 52) |> Z.to_int64
let value_upper_bound = Int64.of_float @@ Float.pow 2. 52.
(* TODO
the constraint is on the number of digits,
@ -97,28 +96,31 @@ let jsont = Jsont.of_of_string ~kind:"Amount" of_string ~enc:to_string
(* byte length of currency string *)
let currency_len = 12
(* TODO error *)
let pad_currency s =
let pad_currency_string s =
let len = String.length s in
assert (len <= 11);
assert (len < currency_len);
let b = Bytes.make 12 '\x00' in
Bytes.blit_string s 0 b 0 len;
Bytes.to_string b
(* binary decoding unused? *)
let make_exn value fraction currency =
match make ~sign:None ~currency ~value ~fraction with
| Error _ -> Fmt.failwith "Amount of binary data failure"
| Ok v -> v
let bin =
let open Bin in
record (fun _value _fraction _currency ->
(* no need to decode amount? *)
assert false)
record make_exn
|+ field neint64 (fun t -> t.value)
|+ field neint32 (fun t -> t.fraction)
|+ field (bytes currency_len) (fun t -> pad_currency t.currency)
|+ field (bytes currency_len) (fun t -> pad_currency_string t.currency)
|> sealr
let bin_nbo =
let open Bin in
record (fun _value _fraction _currency -> assert false)
record make_exn
|+ field beint64 (fun t -> t.value)
|+ field beint32 (fun t -> t.fraction)
|+ field (bytes currency_len) (fun t -> pad_currency t.currency)
|+ field (bytes currency_len) (fun t -> pad_currency_string t.currency)
|> sealr