8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0838441 commit 8527a43Copy full SHA for 8527a43
cbor.js
@@ -33,7 +33,7 @@ function encode(value) {
33
var lastLength;
34
var offset = 0;
35
36
- function ensureSpace(length) {
+ function prepareWrite(length) {
37
var newByteLength = data.byteLength;
38
var requiredLength = offset + length;
39
while (newByteLength < requiredLength)
@@ -50,34 +50,34 @@ function encode(value) {
50
lastLength = length;
51
return dataView;
52
}
53
- function write() {
+ function commitWrite() {
54
offset += lastLength;
55
56
function writeFloat64(value) {
57
- write(ensureSpace(8).setFloat64(offset, value));
+ commitWrite(prepareWrite(8).setFloat64(offset, value));
58
59
function writeUint8(value) {
60
- write(ensureSpace(1).setUint8(offset, value));
+ commitWrite(prepareWrite(1).setUint8(offset, value));
61
62
function writeUint8Array(value) {
63
- var dataView = ensureSpace(value.length);
+ var dataView = prepareWrite(value.length);
64
for (var i = 0; i < value.length; ++i)
65
dataView.setUint8(offset + i, value[i]);
66
- write();
+ commitWrite();
67
68
function writeUint16(value) {
69
- write(ensureSpace(2).setUint16(offset, value));
+ commitWrite(prepareWrite(2).setUint16(offset, value));
70
71
function writeUint32(value) {
72
- write(ensureSpace(4).setUint32(offset, value));
+ commitWrite(prepareWrite(4).setUint32(offset, value));
73
74
function writeUint64(value) {
75
var low = value % POW_2_32;
76
var high = (value - low) / POW_2_32;
77
- var dataView = ensureSpace(8);
+ var dataView = prepareWrite(8);
78
dataView.setUint32(offset, high);
79
dataView.setUint32(offset + 4, low);
80
81
82
function writeTypeAndLength(type, length) {
83
if (length < 24) {
@@ -192,12 +192,12 @@ function decode(data, tagger, simpleValue) {
192
if (typeof simpleValue !== "function")
193
simpleValue = function() { return undefined; };
194
195
- function read(value, length) {
+ function commitRead(length, value) {
196
offset += length;
197
return value;
198
199
function readArrayBuffer(length) {
200
- return read(new Uint8Array(data, offset, length), length);
+ return commitRead(length, new Uint8Array(data, offset, length));
201
202
function readFloat16() {
203
var tempArrayBuffer = new ArrayBuffer(4);
@@ -219,19 +219,19 @@ function decode(data, tagger, simpleValue) {
219
return tempDataView.getFloat32(0);
220
221
function readFloat32() {
222
- return read(dataView.getFloat32(offset), 4);
+ return commitRead(4, dataView.getFloat32(offset));
223
224
function readFloat64() {
225
- return read(dataView.getFloat64(offset), 8);
+ return commitRead(8, dataView.getFloat64(offset));
226
227
function readUint8() {
228
- return read(dataView.getUint8(offset), 1);
+ return commitRead(1, dataView.getUint8(offset));
229
230
function readUint16() {
231
- return read(dataView.getUint16(offset), 2);
+ return commitRead(2, dataView.getUint16(offset));
232
233
function readUint32() {
234
- return read(dataView.getUint32(offset), 4);
+ return commitRead(4, dataView.getUint32(offset));
235
236
function readUint64() {
237
return readUint32() * POW_2_32 + readUint32();
@@ -267,7 +267,7 @@ function decode(data, tagger, simpleValue) {
267
return length;
268
269
270
- function appendUtf16data(utf16data, length) {
+ function appendUtf16Data(utf16data, length) {
271
for (var i = 0; i < length; ++i) {
272
var value = readUint8();
273
if (value & 0x80) {
@@ -347,9 +347,9 @@ function decode(data, tagger, simpleValue) {
347
var utf16data = [];
348
if (length < 0) {
349
while ((length = readIndefiniteStringLength(majorType)) >= 0)
350
- appendUtf16data(utf16data, length);
+ appendUtf16Data(utf16data, length);
351
} else
352
353
return String.fromCharCode.apply(null, utf16data);
354
case 4:
355
var retArray;