forked from msgpack/msgpack-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamd-example.js
More file actions
26 lines (22 loc) · 715 Bytes
/
amd-example.js
File metadata and controls
26 lines (22 loc) · 715 Bytes
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
/* eslint-disable no-console */
"use strict";
try {
const object = {
nil: null,
integer: 1,
float: Math.PI,
string: "Hello, world!",
binary: Uint8Array.from([1, 2, 3]),
array: [10, 20, 30],
map: { foo: "bar" },
timestampExt: new Date(),
};
document.writeln("<p>input:</p>");
document.writeln(`<pre><code>${JSON.stringify(object, undefined, 2)}</code></pre>`);
const encoded = MessagePack.encode(object);
document.writeln("<p>output:</p>");
document.writeln(`<pre><code>${JSON.stringify(MessagePack.decode(encoded), undefined, 2)}</code></pre>`);
} catch (e) {
console.error(e);
document.write(`<p style="color: red">${e.constructor.name}: ${e.message}</p>`);
}