diff options
Diffstat (limited to 'subsystem/karuta/Translator.ml')
| -rw-r--r-- | subsystem/karuta/Translator.ml | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/subsystem/karuta/Translator.ml b/subsystem/karuta/Translator.ml index 1fbbd9d..0d7e7b7 100644 --- a/subsystem/karuta/Translator.ml +++ b/subsystem/karuta/Translator.ml @@ -1,16 +1,11 @@ -(* A tuple of an ephemeral relation as an Erlang term in the external - term format, for binary_to_term on the BEAM: {Type, #{Name => - Value}}, with the type, names and strings as binaries. And back, - from what term_to_binary writes for such a term. *) - open Rnt module Error = struct open Concepts.Condition + let malformed () = - Concepts.Condition.condition "malformed-beam-tuple" - "A term is not {Type, #{Name => Value}} of binaries, and integers that fit an int" - Concepts.Condition.empty + condition "malformed-beam-tuple" + "A term is not {Type, #{Name => Value}} of binaries, and integers that fit an int" empty end let binary buffer s = @@ -18,9 +13,6 @@ let binary buffer s = Buffer.add_int32_be buffer (Int32.of_int (String.length s)); Buffer.add_string buffer s -(* Every integer as a small big: a sign, then the bytes of the magnitude, - least significant first. binary_to_term gives back an ordinary - integer when it fits one, and lsr reads abs min_int as 2^62. *) let integer buffer n = let rec digits m = if m = 0 then [] else (m land 0xff) :: digits (m lsr 8) in let digits = digits (abs n) in @@ -46,7 +38,6 @@ let encode {Concepts.Tuple.type_; attributes} = attributes; Buffer.contents buffer -(* Decoding raises within and answers a result at the end. *) exception Malformed let decode bytes = @@ -65,9 +56,6 @@ let decode bytes = let n = u32 () in String.sub bytes (take n) n in - (* a sign, then at most 8 bytes of the magnitude, least significant - first; an int holds magnitudes up to 2^62 - 1, or 2^62 when - negative *) let big n = let negative = u8 () = 1 in if n > 8 then raise Malformed; @@ -83,7 +71,6 @@ let decode bytes = if Int64.compare m 0L < 0 || Int64.compare m limit > 0 then raise Malformed; Int64.to_int (if negative then Int64.neg m else m) in - (* term_to_binary writes an integer in the least of these that holds it *) let value () = match u8 () with | 109 -> Concepts.Value.String (binary ()) |
