Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
belenios
belenios
Commits
4cf430ab
Commit
4cf430ab
authored
Mar 25, 2014
by
Stephane Glondu
Browse files
Add helpers for interacting with atd-generated stuff
parent
e17b0c1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/serializable_builtin_j.ml
View file @
4cf430ab
...
...
@@ -21,50 +21,54 @@
open
Serializable_builtin_t
(** {1
Serializers for type number
} *)
(** {1
Helpers for interacting with atd-generated stuff
} *)
let
write_number
buf
n
=
let
make_write
to_string
buf
x
=
Bi_outbuf
.
add_char
buf
'
"';
Bi_outbuf.add_string buf (
Z.
to_string
n
);
Bi_outbuf.add_string buf (to_string
x
);
Bi_outbuf.add_char buf '"
'
let
make_read
of_string
state
buf
=
match
Yojson
.
Safe
.
from_lexbuf
~
stream
:
true
state
buf
with
|
`String
s
->
of_string
s
|
_
->
assert
false
(** {1 Serializers for type number} *)
let
write_number
=
make_write
Z
.
to_string
let
string_of_number
?
(
len
=
2048
)
n
=
let
buf
=
Bi_outbuf
.
create
len
in
write_number
buf
n
;
Bi_outbuf
.
contents
buf
let
number_of_json
=
function
let
read_number
=
make_read
Z
.
of_string
let
number_of_string
x
=
match
Yojson
.
Safe
.
from_string
x
with
|
`String
s
->
Z
.
of_string
s
|
_
->
assert
false
let
read_number
state
buf
=
number_of_json
(
Yojson
.
Safe
.
from_lexbuf
~
stream
:
true
state
buf
)
let
number_of_string
s
=
number_of_json
(
Yojson
.
Safe
.
from_string
s
)
(** {1 Serializers for type uuid} *)
let
write_uuid
buf
n
=
Bi_outbuf
.
add_char
buf
'
"';
Bi_outbuf.add_string buf (Uuidm.to_string n);
Bi_outbuf.add_char buf '"
'
let
write_uuid
=
make_write
Uuidm
.
to_string
let
string_of_uuid
?
(
len
=
38
)
n
=
let
buf
=
Bi_outbuf
.
create
len
in
write_uuid
buf
n
;
Bi_outbuf
.
contents
buf
let
uuid_of_
json
=
function
|
`String
s
->
(
match
Uuidm
.
of_string
s
with
Some
s
->
s
|
_
->
assert
false
)
let
raw_
uuid_of_
string
x
=
match
Uuidm
.
of_string
x
with
|
Some
s
->
s
|
_
->
assert
false
let
read_uuid
state
buf
=
uuid_of_json
(
Yojson
.
Safe
.
from_lexbuf
~
stream
:
true
state
buf
)
let
read_uuid
=
make_read
raw_uuid_of_string
let
uuid_of_string
s
=
uuid_of_json
(
Yojson
.
Safe
.
from_string
s
)
let
uuid_of_string
x
=
match
Yojson
.
Safe
.
from_string
x
with
|
`String
s
->
raw_uuid_of_string
s
|
_
->
assert
false
(** {1 Serializers for type datetime} *)
...
...
src/lib/serializable_builtin_j.mli
View file @
4cf430ab
...
...
@@ -21,6 +21,14 @@
open
Serializable_builtin_t
(** {1 Helpers for interacting with atd-generated stuff} *)
val
make_write
:
(
'
a
->
string
)
->
Bi_outbuf
.
t
->
'
a
->
unit
val
make_read
:
(
string
->
'
a
)
->
Yojson
.
Safe
.
lexer_state
->
Lexing
.
lexbuf
->
'
a
(** {1 Serializers for type number} *)
val
write_number
:
Bi_outbuf
.
t
->
number
->
unit
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment