2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
type error += Invalid_fitness
|
|
|
|
|
|
|
|
let int64_to_bytes i =
|
|
|
|
let b = MBytes.create 8 in
|
|
|
|
MBytes.set_int64 b 0 i;
|
|
|
|
b
|
|
|
|
|
|
|
|
let int64_of_bytes b =
|
|
|
|
if Compare.Int.(MBytes.length b <> 8) then
|
2017-04-10 14:14:11 +04:00
|
|
|
error Invalid_fitness
|
2016-09-08 21:13:10 +04:00
|
|
|
else
|
2017-04-10 14:14:11 +04:00
|
|
|
ok (MBytes.get_int64 b 0)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let from_int64 fitness =
|
2017-02-25 21:01:27 +04:00
|
|
|
[ MBytes.of_string Constants_repr.version_number ;
|
|
|
|
int64_to_bytes fitness ]
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let to_int64 = function
|
|
|
|
| [ version ;
|
|
|
|
fitness ]
|
|
|
|
when Compare.String.
|
|
|
|
(MBytes.to_string version = Constants_repr.version_number) ->
|
|
|
|
int64_of_bytes fitness
|
2017-04-10 14:14:11 +04:00
|
|
|
| [] -> ok 0L
|
|
|
|
| _ -> error Invalid_fitness
|