diff options
| author | Adelyn Breelove <[email protected]> | 2019-01-10 16:15:20 -0700 |
|---|---|---|
| committer | Adelyn Breelove <[email protected]> | 2019-01-10 16:15:20 -0700 |
| commit | b7f8f0de01c5014703376d7204b62d8e47c9179a (patch) | |
| tree | 45904decd22a7025e6dcb4e7cdb61ab754b5fe5f /lib/models/snowflake.ml | |
| parent | AAAAAAAAAAAAAAAAAAAAAAAA (diff) | |
| download | disml-b7f8f0de01c5014703376d7204b62d8e47c9179a.tar.xz disml-b7f8f0de01c5014703376d7204b62d8e47c9179a.zip | |
Fix some deserializing bits
Diffstat (limited to 'lib/models/snowflake.ml')
| -rw-r--r-- | lib/models/snowflake.ml | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml index 28b7fdb..9e630e1 100644 --- a/lib/models/snowflake.ml +++ b/lib/models/snowflake.ml @@ -1,6 +1,14 @@ open Core -type t = int [@@deriving yojson] +type t = int + +let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int.of_string |> Ok + +let of_yojson d = + try of_yojson_exn d + with Yojson.Safe.Util.Type_error (why,_) -> Error why + +let to_yojson s : Yojson.Safe.json = `String (Int.to_string s) let timestamp snowflake = let offset = (snowflake lsr 22) / 1000 in |