-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.js
53 lines (42 loc) · 1.39 KB
/
index.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
'use strict';
var EncoderV1 = exports.EncoderV1 = exports.Encoder = require('./lib/v1/encoder');
var DecoderV1 = exports.DecoderV1 = exports.Decoder = require('./lib/v1/decoder');
var EncoderV2 = exports.EncoderV2 = require('./lib/v2/encoder');
var DecoderV2 = exports.DecoderV2 = require('./lib/v2/decoder');
exports.encoderV1 = new EncoderV1({size: 1024 * 1024});
exports.encoderV2 = new EncoderV2({size: 1024 * 1024});
exports.decode = function decode(buf, version, options) {
var classCache;
var withType;
if (version && typeof version !== 'string') {
// buf, withType, version
var t = version;
version = options;
options = t;
}
if (typeof options === 'boolean') {
withType = options;
}
if (typeof options === 'object') {
withType = options.withType;
classCache = options.classCache;
}
withType = !!withType;
if (version === '2.0') {
return new DecoderV2(buf, classCache).read(withType);
}
return new DecoderV1(buf, classCache).read(withType);
};
exports.encode = function encode(obj, version) {
var encoder;
if (version === '2.0') {
encoder = exports.encoderV2;
} else {
encoder = exports.encoderV1;
}
encoder.reset();
return encoder.write(obj).get();
};
var custom = require('./lib/custom_handler');
exports.registerDecodeHandler = custom.registerDecodeHandler;
exports.deregisterDecodeHandler= custom.deregisterDecodeHandler;