-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
29 lines (29 loc) · 1 KB
/
util.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
var PAYLOAD = {
defaultMode : 'json',
encode: function(object, mode){
//try{
switch(mode || PAYLOAD.defaultMode){
case 'cbor' : return CBOR.stringify(object);
case 'json' : return JSON.stringify(object);
case 'pretty-json' : return JSON.stringify(object, null, ' ');
default : throw new Error('Unrecognized parse format: '+ mode);
}
//}catch(ex){}
},
stringify: function(object, mode){
return PAYLOAD.encode(object, mode);
},
decode : function(payload, mode){
//try{
switch(mode || PAYLOAD.defaultMode){
case 'cbor' : return CBOR.decode(payload);
case 'json' : return JSON.decode(payload);
case 'pretty-json' : return JSON.decode(payload, null, ' ');
default : throw new Error('Unrecognized parse format: '+ mode);
}
//}catch(ex){}
}
}
module.exports = {
payload: PAYLOAD
}