|
1 | 1 | /** |
2 | | - * json-bufferify 0.1.1 |
3 | | - * Date: 2017-11-10 |
| 2 | + * json-bufferify 0.1.2 |
| 3 | + * Date: 2017-11-13 |
4 | 4 | * © 2017 LangZhai(智能小菜菜) |
5 | 5 | * This is licensed under the GNU LGPL, version 3 or later. |
6 | 6 | * For details, see: http://www.gnu.org/licenses/lgpl.html |
|
24 | 24 | } |
25 | 25 | val.forEach((obj) => { |
26 | 26 | if (obj instanceof Object) { |
27 | | - Object.keys(obj).forEach(item => val[0][item] = deep ? extend(deep, {}, obj[item]) : obj[item]); |
| 27 | + Object.keys(obj).forEach(item => val[0][item] = deep ? extend(deep, obj[item] instanceof Array ? [] : {}, obj[item]) : obj[item]); |
28 | 28 | } else { |
29 | 29 | val[0] = obj; |
30 | 30 | } |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | } |
| 160 | + } else if (typeof data[item] === 'boolean') { |
| 161 | + arr.push({ |
| 162 | + val: data[item] ? 1 : 0, |
| 163 | + type: 'Uint8', |
| 164 | + offset: offset++ |
| 165 | + }); |
160 | 166 | } else { |
161 | 167 | data[item] = data[item].split('').map(item => item.charCodeAt(0)); |
162 | 168 | //Here is using a Uint8 to store the length of string, so the length of string can only be up to 255. |
|
203 | 209 | if (template instanceof Object) { |
204 | 210 | view = source instanceof DataView ? source : new DataView(source instanceof ArrayBuffer ? source : new Uint8Array(source).buffer); |
205 | 211 | if (template instanceof Array && (template.length = view.getUint8(offset++))) { |
206 | | - template.join().split(',').forEach((item, i) => template[i] = extend(true, {}, template[0])); |
| 212 | + template.join().split(',').forEach((item, i) => template[i] = extend(true, template[0] instanceof Array ? [] : {}, template[0])); |
207 | 213 | } |
208 | 214 | if (template instanceof Array && template[0] instanceof Object) { |
209 | 215 | template.forEach(item => offset = _decode(offset, item, view)); |
|
246 | 252 | offset += 8; |
247 | 253 | break; |
248 | 254 | } |
| 255 | + } else if (template[item] === 'boolean') { |
| 256 | + template[item] = !!view.getUint8(offset++); |
249 | 257 | } else { |
250 | 258 | template[item] = (template[item] = view.getUint8(offset++)) ? String.fromCharCode.apply(null, new Array(template[item]).join().split(',').map(() => { |
251 | 259 | let code = view.getUint16(offset); |
|
0 commit comments