fix alt_unit_names
This commit is contained in:
parent
6886d14027
commit
b7892fdca9
4 changed files with 45 additions and 56 deletions
|
|
@ -212,34 +212,3 @@ let etag s =
|
|||
match Headers_lib.Etag.parse (Fmt.str "\"%s\"" s) with
|
||||
| Ok etag -> etag
|
||||
| Error _ -> fail "could not parse etag `%s`: %s" s e)
|
||||
|
||||
(* TODO
|
||||
move to another module
|
||||
can we type the json as a Int_map directly? *)
|
||||
module Alt_unit_names = struct
|
||||
open Syntax
|
||||
module String_map = Map.Make (String)
|
||||
|
||||
let string_map_jsont = Jsont.Object.as_string_map Jsont.string
|
||||
|
||||
let decode s =
|
||||
let* string_map = Jsont_bytesrw.decode_string string_map_jsont s in
|
||||
let l = String_map.to_list string_map in
|
||||
let* l =
|
||||
list_map
|
||||
(fun (k, v) ->
|
||||
match int_of_string_opt k with
|
||||
| None -> Error "alt_unit_names has a non-integer key"
|
||||
| Some k -> Ok (k, v))
|
||||
l
|
||||
in
|
||||
match List.find_opt (fun (i, _) -> i = 0) l with
|
||||
| None -> Error "alt_unit_names with no entry for base value \"0\""
|
||||
| Some _ -> Ok l
|
||||
|
||||
let encode l =
|
||||
let l = List.map (fun (k, v) -> (string_of_int k, v)) l in
|
||||
let string_map = String_map.of_list l in
|
||||
let+ s = Jsont_bytesrw.encode_string string_map_jsont string_map in
|
||||
s
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue