objective categorical abstract machine language personal data server
65
fork

Configure Feed

Select the types of activity you want to include in your feed.

TID implementation

futurGH 30843f2b f3d99d91

+78 -3
+1 -1
dune-project
··· 21 21 (name mist) 22 22 (synopsis "Atproto repo functionality") 23 23 (allow_empty) 24 - (depends ocaml dune (cborl (>= 0.1.0)) (cid (>= 0.1.0)) lwt (multihash (>= 0.1.0)) (yojson (>= 3.0.0)) (alcotest :with-test))) 24 + (depends ocaml dune (cborl (>= 0.1.0)) (cid (>= 0.1.0)) (hacl-star (>= 0.7.2)) lwt (mtime (>= 2.1.0)) (multihash (>= 0.1.0)) (yojson (>= 3.0.0)) (alcotest :with-test))) 25 25 26 26 (package 27 27 (name ipld)
+2
mist.opam
··· 11 11 "dune" {>= "3.14"} 12 12 "cborl" {>= "0.1.0"} 13 13 "cid" {>= "0.1.0"} 14 + "hacl-star" {>= "0.7.2"} 14 15 "lwt" 16 + "mtime" {>= "2.1.0"} 15 17 "multihash" {>= "0.1.0"} 16 18 "yojson" {>= "3.0.0"} 17 19 "alcotest" {with-test}
+12 -2
mist/lib/dune
··· 1 1 (library 2 2 (name mist) 3 - (libraries digestif ipld lwt multihash str yojson ppx_deriving_yojson.runtime) 4 - (preprocess (pps ppx_deriving_yojson))) 3 + (libraries 4 + digestif 5 + hacl-star 6 + ipld 7 + lwt 8 + mtime.clock 9 + multihash 10 + str 11 + yojson 12 + ppx_deriving_yojson.runtime) 13 + (preprocess 14 + (pps ppx_deriving_yojson))) 5 15 6 16 (include_subdirs qualified)
+63
mist/lib/tid.ml
··· 1 + type t = string 2 + 3 + let charset = "234567abcdefghijklmnopqrstuvwxyz" 4 + 5 + let encode (n : int64) : t = 6 + let rec encode ~tid n = 7 + match n with 8 + | 0L -> 9 + tid 10 + | n -> 11 + encode 12 + ~tid:(String.make 1 charset.[Int64.to_int (Int64.rem n 32L)] ^ tid) 13 + (Int64.unsigned_div n 32L) 14 + in 15 + encode ~tid:"" n 16 + 17 + let decode (s : t) : int64 = 18 + let rec decode ~(n : int64) (s : string) = 19 + match s with 20 + | s when String.length s > 0 -> 21 + let c = s.[0] in 22 + let cs = String.sub s 1 (String.length s - 1) in 23 + decode 24 + ~n: 25 + (Int64.add (Int64.mul n 32L) 26 + (Int64.of_int (String.index charset c)) ) 27 + cs 28 + | _ -> 29 + n 30 + in 31 + decode ~n:0L s 32 + 33 + let now () : t = 34 + Mtime_clock.now_ns () |> Int64.unsigned_div 1_000_000L |> encode 35 + 36 + let of_string (s : string) : t = 37 + match String.length s with 38 + | 13 39 + when Str.string_match 40 + (Str.regexp 41 + "/^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/" ) 42 + s 0 -> 43 + s 44 + | _ -> 45 + raise (Invalid_argument (Format.sprintf "invalid tid: %s" s)) 46 + 47 + let to_string (s : t) : string = s 48 + 49 + let of_yojson = function 50 + | `String s -> 51 + Ok (of_string s) 52 + | _ -> 53 + Error "expected string tid" 54 + 55 + let to_yojson s = `String (to_string s) 56 + 57 + let compare = String.compare 58 + 59 + let hash = Hashtbl.hash 60 + 61 + let equal = ( = ) 62 + 63 + let pp fmt t = Format.fprintf fmt "%s" t