Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

jobs:
build:
if: false # disable the entire workflow
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion messgen/ts_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def generate_protocols(self, out_dir: Path, protocols: dict[str, Protocol]) -> N
code.append(f" '{proto_name}': {{")
for message in proto_def.messages.values():
ts_struct_name = self._to_camel_case(message.type)
code.append(f" '{message.name}': {message.type};")
code.append(f" '{message.name}': {ts_struct_name};")
types.add(ts_struct_name)
code.append(' }')
code.append('}')
Expand Down
2 changes: 1 addition & 1 deletion messgen/yaml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _get_enum_type(type_name: str, type_descriptors: dict[str, dict[str, Any]],
type_desc = type_descriptors.get(type_name)
assert type_desc

base_type = type_desc.get("base_type")
base_type = type_desc.get("base_type", '')

if base_type:
type_dependencies.add(_get_dependency_type(type_name, base_type, type_descriptors, type_dependencies)[0])
Expand Down
11 changes: 6 additions & 5 deletions port/js/src/Codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ export class Codec<Config extends GenericConfig = GenericConfig> {
this.protocols.load(rawTypes);
const converterFactory = new ConverterFactory(this.protocols);

for (const { name, proto_id: protoId, types } of protocols) {
for (const { name: protoName, proto_id: protoId, messages } of protocols) {
const typeMap = new Map<string, Converter>();
const idMap = new Map<MessageId, Converter>();

for (const [messageId, typeName] of Object.entries(types)) {
for (const message of Object.values(messages)) {
const { message_id: messageId, name: messageName, type: typeName } = message;
const converter = converterFactory.toConverter(typeName);

typeMap.set(typeName, converter);
idMap.set(parseInt(messageId, 10), converter);
typeMap.set(messageName, converter);
idMap.set(messageId, converter);
}
this.typesByName.set(name, typeMap);
this.typesByName.set(protoName, typeMap);
this.typesById.set(protoId, idMap);
}
}
Expand Down
8 changes: 7 additions & 1 deletion port/js/src/protocol/Protocols.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ export interface EnumTypeClass {

export type StructureType = StructTypeClass | EnumTypeClass;

export interface RawMessage {
message_id: number;
name: IName;
type: string;
}

export interface Protocol {
name: string;
proto_id: number;
types: Record<string, IName>;
messages: Record<string, RawMessage>;
}
4 changes: 2 additions & 2 deletions port/js/tests/Codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Codec', () => {
f9: true,
};

const message = codec.serialize('test_proto', 'messgen/test/simple_struct', rawData);
const message = codec.serialize('test_proto', 'simple_struct_msg', rawData);

expect(codec.deserialize(1, 0, message.buffer)).toEqual({
...rawData,
Expand All @@ -54,7 +54,7 @@ describe('Codec', () => {

const message = codec.serialize(
'another_proto',
'cross_proto',
'cross_proto_msg',
rawData,
);

Expand Down
16 changes: 8 additions & 8 deletions port/js/tests/Integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('integration', () => {
};
const rawDataBit = uploadBinary('../../../tests/data/serialized/bin/simple_struct.bin');

const buffer = codec.serialize('test_proto', 'messgen/test/simple_struct', rawData);
const buffer = codec.serialize('test_proto', 'simple_struct_msg', rawData);
const result = codec.deserialize(1, 0, new Uint8Array(rawDataBit).buffer);

expect(result).toEqual({ ...rawData, f5: expect.closeTo(rawData.f5, 5) });
Expand All @@ -49,7 +49,7 @@ describe('integration', () => {
};
const rawDataBit = uploadBinary('../../../tests/data/serialized/bin/var_size_struct.bin');

const buffer = codec.serialize('test_proto', 'messgen/test/var_size_struct', rawData);
const buffer = codec.serialize('test_proto', 'var_size_struct_msg', rawData);
const result = codec.deserialize(1, 2, new Uint8Array(rawDataBit).buffer);

expect(result).toEqual(rawData);
Expand All @@ -61,7 +61,7 @@ describe('integration', () => {
const rawData = { f0: bigint, f1: bigint, e0: 1 };
const rawDataBit = uploadBinary('../../../tests/data/serialized/bin/struct_with_enum.bin');

const buffer = codec.serialize('test_proto', 'messgen/test/struct_with_enum', rawData);
const buffer = codec.serialize('test_proto', 'struct_with_enum_msg', rawData);
const result = codec.deserialize(1, 3, new Uint8Array(rawDataBit).buffer);

expect(result).toEqual(rawData);
Expand All @@ -73,7 +73,7 @@ describe('integration', () => {
const rawData = {};
const rawDataBit = uploadBinary('../../../tests/data/serialized/bin/empty_struct.bin');

const buffer = codec.serialize('test_proto', 'messgen/test/empty_struct', rawData);
const buffer = codec.serialize('test_proto', 'empty_struct_msg', rawData);
const result = codec.deserialize(1, 4, new Uint8Array(rawDataBit).buffer);

expect(result).toEqual(rawData);
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('integration', () => {
};
const rawDataBit = uploadBinary('../../../tests/data/serialized/bin/complex_struct_with_empty.bin');

const buffer = codec.serialize('test_proto', 'messgen/test/complex_struct_with_empty', rawData);
const buffer = codec.serialize('test_proto', 'complex_struct_with_empty_msg', rawData);
const result = codec.deserialize(1, 5, new Uint8Array(rawDataBit).buffer);

expect(result).toEqual(rawData);
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('integration', () => {
};
const rawDataBit = uploadBinary('../../../tests/data/serialized/bin/complex_struct_nostl.bin');

const buffer = codec.serialize('test_proto', 'messgen/test/complex_struct_nostl', rawData);
const buffer = codec.serialize('test_proto', 'complex_struct_nostl_msg', rawData);
const result = codec.deserialize(1, 6, new Uint8Array(rawDataBit).buffer);

simpleStruct.f5 = expect.closeTo(simpleStruct.f5, 4);
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('integration', () => {
};
const rawDataBit = uploadBinary('../../../tests/data/serialized/bin/complex_struct.bin');

const buffer = codec.serialize('test_proto', 'messgen/test/complex_struct', rawData);
const buffer = codec.serialize('test_proto', 'complex_struct_msg', rawData);
const result = codec.deserialize(1, 1, new Uint8Array(rawDataBit).buffer);

simpleStruct.f5 = expect.closeTo(simpleStruct.f5, 4);
Expand All @@ -245,7 +245,7 @@ describe('integration', () => {
};
const rawDataBit = uploadBinary('../../../tests/data/serialized/bin/flat_struct.bin');

const buffer = codec.serialize('test_proto', 'messgen/test/flat_struct', rawData);
const buffer = codec.serialize('test_proto', 'flat_struct_msg', rawData);
const result = codec.deserialize(1, 7, new Uint8Array(rawDataBit).buffer);

rawData.f5 = expect.closeTo(rawData.f5, 5);
Expand Down
Loading