Skip to content

Commit 91b2a57

Browse files
Update to 0.0.9.
1 parent 4526c04 commit 91b2a57

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

README.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,22 @@ Open "egretProperties.json" and Add the following code to "modules" node.
5151
```javascript
5252
var ws = new WebSocket(url);
5353
ws.binaryType = 'arraybuffer';
54-
ws.send(bufferify.encode(0, { name: 'Bob', sex: 0, age: 25 }));
54+
ws.send(bufferify.encode(0, {
55+
sex: 0,
56+
name: 'Bob',
57+
age: 25
58+
}));
5559
```
5660

5761
### Revert ArrayBuffer to JSON.
5862

5963
```javascript
6064
ws.on('message', (data) => {
61-
console.log(bufferify.decode(0, { name: 'string', sex: 'number', age: 'number' }, data));
65+
console.log(bufferify.decode(0, {
66+
name: 'string',
67+
sex: 'number',
68+
age: 'number'
69+
}, data));
6270
});
6371
```
6472

@@ -77,4 +85,66 @@ Revert ArrayBuffer to JSON data and return it.
7785

7886
* `offset` - The start of the DataView where to read the data.
7987
* `template` - The template of the JSON.
80-
* `source` - The ArrayBuffer, or the Buffer in Node.js, or the DataView of the ArrayBuffer.
88+
* `source` - The ArrayBuffer, or the Buffer in Node.js, or the DataView of the ArrayBuffer.
89+
90+
## Example
91+
92+
### Convert/Revert an array.
93+
94+
```javascript
95+
var ws = new WebSocket(url);
96+
ws.binaryType = 'arraybuffer';
97+
ws.send(bufferify.encode(0, [1, 2, 3, 4, 5, 6, 7, 8, 9]));
98+
```
99+
100+
```javascript
101+
ws.on('message', (data) => {
102+
console.log(bufferify.decode(0, ['number'], data));
103+
});
104+
```
105+
106+
### Convert/Revert a complex Object.
107+
108+
```javascript
109+
var ws = new WebSocket(url);
110+
ws.binaryType = 'arraybuffer';
111+
ws.send(bufferify.encode(0, {
112+
obj: {
113+
opcode: 8,
114+
info: 'Hello'
115+
},
116+
arr: [1, 2, 3, 4, 5],
117+
list: [{
118+
name: 'Jerry',
119+
id: '536598'
120+
},
121+
{
122+
name: 'Tom',
123+
id: '85947'
124+
},
125+
{
126+
id: '459823',
127+
name: 'Kevin'
128+
}]
129+
}));
130+
```
131+
132+
```javascript
133+
ws.on('message', (data) => {
134+
console.log(bufferify.decode(0, {
135+
arr: ['number'],
136+
obj: {
137+
opcode: 'number',
138+
info: 'string'
139+
},
140+
list: [{
141+
id: 'string',
142+
name: 'string'
143+
}]
144+
}, data));
145+
});
146+
```
147+
148+
## License
149+
150+
This is licensed under the GNU LGPL, version 3 or later.

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ console.log(bufferify.decode(0, ['number'], bufferify.encode(0, [1, 2, 3, 4, 5,
1414

1515
console.log(bufferify.decode(0, {
1616
arr: ['number'],
17+
obj: {
18+
opcode: 'number',
19+
info: 'string'
20+
},
1721
list: [{
1822
id: 'string',
1923
name: 'string'
2024
}]
2125
}, bufferify.encode(0, {
26+
obj: {
27+
opcode: 8,
28+
info: 'Hello'
29+
},
2230
arr: [1, 2, 3, 4, 5],
2331
list: [{
2432
name: 'Jerry',

0 commit comments

Comments
 (0)