cborg 4.5.5 → 4.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/lib/2bytes.js +2 -2
- package/lib/3string.js +1 -2
- package/lib/decode.js +4 -1
- package/package.json +1 -1
- package/types/lib/3string.d.ts.map +1 -1
- package/types/lib/decode.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
package/lib/2bytes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Token, Type } from './token.js'
|
|
2
2
|
import { assertEnoughData, decodeErrPrefix } from './common.js'
|
|
3
3
|
import * as uint from './0uint.js'
|
|
4
|
-
import { compare, fromString
|
|
4
|
+
import { compare, fromString } from './byte-utils.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @typedef {import('../interface').ByteWriter} ByteWriter
|
|
@@ -17,7 +17,7 @@ import { compare, fromString, slice } from './byte-utils.js'
|
|
|
17
17
|
*/
|
|
18
18
|
function toToken (data, pos, prefix, length) {
|
|
19
19
|
assertEnoughData(data, pos, prefix + length)
|
|
20
|
-
const buf = slice(
|
|
20
|
+
const buf = data.slice(pos + prefix, pos + prefix + length)
|
|
21
21
|
return new Token(Type.bytes, buf, prefix + length)
|
|
22
22
|
}
|
|
23
23
|
|
package/lib/3string.js
CHANGED
|
@@ -2,7 +2,6 @@ import { Token, Type } from './token.js'
|
|
|
2
2
|
import { assertEnoughData, decodeErrPrefix } from './common.js'
|
|
3
3
|
import * as uint from './0uint.js'
|
|
4
4
|
import { encodeBytes } from './2bytes.js'
|
|
5
|
-
import { slice } from './byte-utils.js'
|
|
6
5
|
|
|
7
6
|
const textDecoder = new TextDecoder()
|
|
8
7
|
|
|
@@ -52,7 +51,7 @@ function toToken (data, pos, prefix, length, options) {
|
|
|
52
51
|
assertEnoughData(data, pos, totLength)
|
|
53
52
|
const tok = new Token(Type.string, toStr(data, pos + prefix, pos + totLength), totLength)
|
|
54
53
|
if (options.retainStringBytes === true) {
|
|
55
|
-
tok.byteValue = slice(
|
|
54
|
+
tok.byteValue = data.slice(pos + prefix, pos + totLength)
|
|
56
55
|
}
|
|
57
56
|
return tok
|
|
58
57
|
}
|
package/lib/decode.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { decodeErrPrefix } from './common.js'
|
|
2
2
|
import { Type } from './token.js'
|
|
3
3
|
import { jump, quick } from './jump.js'
|
|
4
|
+
import { asU8A } from './byte-utils.js'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {import('./token.js').Token} Token
|
|
@@ -183,7 +184,9 @@ function decodeFirst (data, options) {
|
|
|
183
184
|
throw new Error(`${decodeErrPrefix} data to decode must be a Uint8Array`)
|
|
184
185
|
}
|
|
185
186
|
options = Object.assign({}, defaultDecodeOptions, options)
|
|
186
|
-
|
|
187
|
+
// Convert Buffer to plain Uint8Array for faster slicing in decode path
|
|
188
|
+
const u8aData = asU8A(data)
|
|
189
|
+
const tokeniser = options.tokenizer || new Tokeniser(u8aData, options)
|
|
187
190
|
const decoded = tokensToObject(tokeniser, options)
|
|
188
191
|
if (decoded === DONE) {
|
|
189
192
|
throw new Error(`${decodeErrPrefix} did not find any content to decode`)
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"3string.d.ts","sourceRoot":"","sources":["../../lib/3string.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"3string.d.ts","sourceRoot":"","sources":["../../lib/3string.js"],"names":[],"mappings":"AA0DA;;;;;;GAMG;AACH,0CANW,UAAU,OACV,MAAM,SACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED,8CAAuC;yBA1G1B,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;sBAbrB,YAAY;4BAGZ,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../lib/decode.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../lib/decode.js"],"names":[],"mappings":"oBAMa,OAAO,YAAY,EAAE,KAAK;4BAC1B,OAAO,cAAc,EAAE,aAAa;8BACpC,OAAO,cAAc,EAAE,eAAe;AAUnD;;GAEG;AACH,kCAFgB,eAAe;IAG7B;;;OAGG;IACH,kBAHW,UAAU,YACV,aAAa,EAMvB;IAHC,aAAa;IACb,kCAAgB;IAChB,8CAAsB;IAGxB,cAEC;IAED,gBAEC;IAED,mCAgBC;CACF;AA8ED;;;;GAIG;AACH,0CAJW,eAAe,WACf,aAAa,GACX,GAAG,6BAAW,CAoC1B;AAyBD;;;;GAIG;AACH,6BAJW,UAAU,YACV,aAAa,GACX,GAAG,CAQf;AAlCD;;;;GAIG;AACH,kCAJW,UAAU,YACV,aAAa,GACX,CAAC,GAAG,EAAE,UAAU,CAAC,CAkB7B;AAzID,mCAAiC;AADjC,kCAA+B"}
|