8000 Rename functions to better match their purpose · arduino/cbor-js@8527a43 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8527a43

Browse files
Tyler Youngparoga
Tyler Young
authored andcommitted
Rename functions to better match their purpose
Rename ensureSpace() to prepareWrite(), write() to commitWrite(), read() to commitRead() and appendUtf16data() to appendUtf16Data().
1 parent 0838441 commit 8527a43

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

cbor.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function encode(value) {
3333
var lastLength;
3434
var offset = 0;
3535

36-
function ensureSpace(length) {
36+
function prepareWrite(length) {
3737
var newByteLength = data.byteLength;
3838
var requiredLength = offset + length;
3939
while (newByteLength < requiredLength)
@@ -50,34 +50,34 @@ function encode(value) {
5050
lastLength = length;
5151
return dataView;
5252
}
53-
function write() {
53+
function commitWrite() {
5454
offset += lastLength;
5555
}
5656
function writeFloat64(value) {
57-
write(ensureSpace(8).setFloat64(offset, value));
57+
commitWrite(prepareWrite(8).setFloat64(offset, value));
5858
}
5959
function writeUint8(value) {
60-
write(ensureSpace(1).setUint8(offset, value));
60+
commitWrite(prepareWrite(1).setUint8(offset, value));
6161
}
6262
function writeUint8Array(value) {
63-
var dataView = ensureSpace(value.length);
63+
var dataView = prepareWrite(value.length);
6464
for (var i = 0; i < value.length; ++i)
6565
dataView.setUint8(offset + i, value[i]);
66-
write();
66+
commitWrite();
6767
}
6868
function writeUint16(value) {
69-
write(ensureSpace(2).setUint16(offset, value));
69+
commitWrite(prepareWrite(2).setUint16(offset, value));
7070
}
7171
function writeUint32(value) {
72-
write(ensureSpace(4).setUint32(offset, value));
72+
commitWrite(prepareWrite(4).setUint32(offset, value));
7373
}
7474
function writeUint64(value) {
7575
var low = value % POW_2_32;
7676
var high = (value - low) / POW_2_32;
77-
var dataView = ensureSpace(8);
77+
var dataView = prepareWrite(8);
7878
dataView.setUint32(offset, high);
7979
dataView.setUint32(offset + 4, low);
80-
write();
80+
commitWrite();
8181
}
8282
function writeTypeAndLength(type, length) {
8383
if (length < 24) {
@@ -192,12 +192,12 @@ function decode(data, tagger, simpleValue) {
192192
if (typeof simpleValue !== "function")
193193
simpleValue = function() { return undefined; };
194194

195-
function read(value, length) {
195+
function commitRead(length, value) {
196196
offset += length;
197197
return value;
198198
}
199199
function readArrayBuffer(length) {
200-
return read(new Uint8Array(data, offset, length), length);
200+
return commitRead(length, new Uint8Array(data, offset, length));
201201
}
202202
function readFloat16() {
203203
var tempArrayBuffer = new ArrayBuffer(4);
@@ -219,19 +219,19 @@ function decode(data, tagger, simpleValue) {
219219
return tempDataView.getFloat32(0);
220220
}
221221
function readFloat32() {
222-
return read(dataView.getFloat32(offset), 4);
222+
return commitRead(4, dataView.getFloat32(offset));
223223
}
224224
function readFloat64() {
225-
return read(dataView.getFloat64(offset), 8);
225+
return commitRead(8, dataView.getFloat64(offset));
226226
}
227227
function readUint8() {
228-
return read(dataView.getUint8(offset), 1);
228+
return commitRead(1, dataView.getUint8(offset));
229229
}
230230
function readUint16() {
231-
return read(dataView.getUint16(offset), 2);
231+
return commitRead(2, dataView.getUint16(offset));
232232
}
233233
function readUint32() {
234-
return read(dataView.getUint32(offset), 4);
234+
return commitRead(4, dataView.getUint32(offset));
235235
}
236236
function readUint64() {
237237
return readUint32() * POW_2_32 + readUint32();
@@ -267,7 +267,7 @@ function decode(data, tagger, simpleValue) {
267267
return length;
268268
}
269269

270-
function appendUtf16data(utf16data, length) {
270+
function appendUtf16Data(utf16data, length) {
271271
for (var i = 0; i < length; ++i) {
272272
var value = readUint8();
273273
if (value & 0x80) {
@@ -347,9 +347,9 @@ function decode(data, tagger, simpleValue) {
347347
var utf16data = [];
348348
if (length < 0) {
349349
while ((length = readIndefiniteStringLength(majorType)) >= 0)
350-
appendUtf16data(utf16data, length);
350+
appendUtf16Data(utf16data, length);
351351
} else
352-
appendUtf16data(utf16data, length);
352+
appendUtf16Data(utf16data, length);
353353
return String.fromCharCode.apply(null, utf16data);
354354
case 4:
355355
var retArray;

0 commit comments

Comments
 (0)
0