-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathmarshal.js
79 lines (69 loc) · 2.02 KB
/
marshal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Generated CODE, PLEASE EDIT WITH CARE
'use strict';
var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions");
var Caml_primitive = require("../runtime/caml_primitive");
var Caml_string = require("../runtime/caml_string");
function to_buffer(buff, ofs, len, v, flags) {
if (ofs < 0 || len < 0 || ofs > buff.length - len) {
throw [
Caml_builtin_exceptions.invalid_argument,
"Marshal.to_buffer: substring out of bounds"
];
}
else {
return Caml_primitive.caml_output_value_to_buffer(buff, ofs, len, v, flags);
}
}
function data_size(buff, ofs) {
if (ofs < 0 || ofs > buff.length - 20) {
throw [
Caml_builtin_exceptions.invalid_argument,
"Marshal.data_size"
];
}
else {
return Caml_primitive.caml_marshal_data_size(buff, ofs);
}
}
function total_size(buff, ofs) {
return 20 + data_size(buff, ofs);
}
function from_bytes(buff, ofs) {
if (ofs < 0 || ofs > buff.length - 20) {
throw [
Caml_builtin_exceptions.invalid_argument,
"Marshal.from_bytes"
];
}
else {
var len = Caml_primitive.caml_marshal_data_size(buff, ofs);
if (ofs > buff.length - (20 + len)) {
throw [
Caml_builtin_exceptions.invalid_argument,
"Marshal.from_bytes"
];
}
else {
return Caml_primitive.caml_input_value_from_string(buff, ofs);
}
}
}
function from_string(buff, ofs) {
return from_bytes(Caml_string.bytes_of_string(buff), ofs);
}
function to_channel(prim, prim$1, prim$2) {
return Caml_primitive.caml_output_value(prim, prim$1, prim$2);
}
function from_channel(prim) {
return Caml_primitive.caml_input_value(prim);
}
var header_size = 20;
exports.to_channel = to_channel;
exports.to_buffer = to_buffer;
exports.from_channel = from_channel;
exports.from_bytes = from_bytes;
exports.from_string = from_string;
exports.header_size = header_size;
exports.data_size = data_size;
exports.total_size = total_size;
/* No side effect */