Skip to content

Commit a5a5d1b

Browse files
committed
try to encode an object with custom encoder to override built-in's
1 parent 4cef7e1 commit a5a5d1b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test:cover:wasm": "npx nyc --no-clean npm run test:wasm",
2525
"test:cover:td": "npx nyc --no-clean npm run test:td",
2626
"cover:clean": "rimraf .nyc_output coverage/",
27-
"cover:report": "nyc report --reporter=text-summary --reporter=html --reporter=json",
27+
"cover:report": "npx nyc report --reporter=text-summary --reporter=html --reporter=json",
2828
"test:browser": "karma start --single-run",
2929
"test:browser:firefox": "karma start --single-run --browsers FirefoxHeadless",
3030
"test:browser:chrome": "karma start --single-run --browsers ChromeHeadless",

src/ExtensionCodec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,25 @@ export class ExtensionCodec implements ExtensionCodecType {
5050
}
5151

5252
public tryToEncode(object: unknown): ExtData | null {
53-
// built-in extensions
54-
for (let i = 0; i < this.builtInEncoders.length; i++) {
55-
const encoder = this.builtInEncoders[i];
53+
// custom extensions
54+
for (let i = 0; i < this.encoders.length; i++) {
55+
const encoder = this.encoders[i];
5656
if (encoder != null) {
5757
const data = encoder(object);
5858
if (data != null) {
59-
const type = -1 - i;
59+
const type = i;
6060
return new ExtData(type, data);
6161
}
6262
}
6363
}
6464

65-
// custom extensions
66-
for (let i = 0; i < this.encoders.length; i++) {
67-
const encoder = this.encoders[i];
65+
// built-in extensions
66+
for (let i = 0; i < this.builtInEncoders.length; i++) {
67+
const encoder = this.builtInEncoders[i];
6868
if (encoder != null) {
6969
const data = encoder(object);
7070
if (data != null) {
71-
const type = i;
71+
const type = -1 - i;
7272
return new ExtData(type, data);
7373
}
7474
}

0 commit comments

Comments
 (0)