Skip to content

Commit aeef27a

Browse files
committed
test: 💍
feat: 🎸 implement `onKey` in capacity estimators
1 parent 0fed7c1 commit aeef27a

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

src/codegen/binary/AbstractBinaryCodegen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import type {
88
BinType,
99
BoolType,
1010
ConType,
11+
KeyType,
1112
MapType,
1213
NumType,
14+
ObjType,
1315
OrType,
1416
RefType,
1517
StrType,

src/codegen/binary/cbor copy/CborCodegen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {JsExpression} from '@jsonjoy.com/codegen/lib/util/JsExpression';
22
import {normalizeAccessor} from '@jsonjoy.com/codegen/lib/util/normalizeAccessor';
33
import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder';
4-
import {type MapType, KeyOptType, type ObjType, type Type} from '../../../type';
4+
import {type MapType, KeyOptType, type KeyType, type ObjType, type Type} from '../../../type';
55
import type {CompiledBinaryEncoder, SchemaPath} from '../../types';
66
import {lazyKeyedFactory} from '../../util';
77
import {AbstractBinaryCodegen} from '../AbstractBinaryCodegen';
@@ -79,6 +79,10 @@ export class CborCodegen extends AbstractBinaryCodegen<CborEncoder> {
7979
}
8080
}
8181

82+
protected onKey(path: SchemaPath, r: JsExpression, type: KeyType<any, any>): void {
83+
this.onNode([...path, type.key], r, type.val);
84+
}
85+
8286
protected genEncoder(type: Type): CompiledBinaryEncoder {
8387
return CborCodegen.get(type);
8488
}

src/codegen/binary/cbor/CborCodegen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {JsExpression} from '@jsonjoy.com/codegen/lib/util/JsExpression';
22
import {normalizeAccessor} from '@jsonjoy.com/codegen/lib/util/normalizeAccessor';
33
import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder';
4-
import {KeyOptType, type ObjType, type Type} from '../../../type';
4+
import {KeyOptType, type KeyType, type ObjType, type Type} from '../../../type';
55
import type {CompiledBinaryEncoder, SchemaPath} from '../../types';
66
import {lazyKeyedFactory} from '../../util';
77
import {AbstractBinaryCodegen} from '../AbstractBinaryCodegen';
@@ -79,6 +79,10 @@ export class CborCodegen extends AbstractBinaryCodegen<CborEncoder> {
7979
}
8080
}
8181

82+
protected onKey(path: SchemaPath, r: JsExpression, type: KeyType<any, any>): void {
83+
this.onNode([...path, type.key], r, type.val);
84+
}
85+
8286
protected genEncoder(type: Type): CompiledBinaryEncoder {
8387
return CborCodegen.get(type);
8488
}

src/codegen/binary/json/JsonCodegen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {JsExpression} from '@jsonjoy.com/codegen/lib/util/JsExpression';
22
import {normalizeAccessor} from '@jsonjoy.com/codegen/lib/util/normalizeAccessor';
33
import {JsonEncoder} from '@jsonjoy.com/json-pack/lib/json/JsonEncoder';
4-
import {type ArrType, type MapType, KeyOptType, type ObjType, type Type} from '../../../type';
4+
import {type ArrType, type MapType, KeyOptType, type KeyType, type ObjType, type Type} from '../../../type';
55
import type {CompiledBinaryEncoder, SchemaPath} from '../../types';
66
import {lazyKeyedFactory} from '../../util';
77
import {AbstractBinaryCodegen} from '../AbstractBinaryCodegen';
@@ -218,6 +218,10 @@ export class JsonCodegen extends AbstractBinaryCodegen<JsonEncoder> {
218218
this.blob(objEndBlob);
219219
}
220220

221+
protected onKey(path: SchemaPath, r: JsExpression, type: KeyType<any, any>): void {
222+
this.onNode([...path, type.key], r, type.val);
223+
}
224+
221225
protected genEncoder(type: Type): CompiledBinaryEncoder {
222226
return JsonCodegen.get(type);
223227
}

src/codegen/binary/msgpack/MsgPackCodegen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {JsExpression} from '@jsonjoy.com/codegen/lib/util/JsExpression';
22
import {normalizeAccessor} from '@jsonjoy.com/codegen/lib/util/normalizeAccessor';
33
import {MsgPackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack/MsgPackEncoder';
4-
import {KeyOptType, type ObjType, type Type} from '../../../type';
4+
import {KeyOptType, type KeyType, type ObjType, type Type} from '../../../type';
55
import type {CompiledBinaryEncoder, SchemaPath} from '../../types';
66
import {lazyKeyedFactory} from '../../util';
77
import {AbstractBinaryCodegen} from '../AbstractBinaryCodegen';
@@ -88,6 +88,10 @@ export class MsgPackCodegen extends AbstractBinaryCodegen<MsgPackEncoder> {
8888
}
8989
}
9090

91+
protected onKey(path: SchemaPath, r: JsExpression, type: KeyType<any, any>): void {
92+
this.onNode([...path, type.key], r, type.val);
93+
}
94+
9195
protected genEncoder(type: Type): CompiledBinaryEncoder {
9296
return MsgPackCodegen.get(type);
9397
}

0 commit comments

Comments
 (0)