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
4 changes: 2 additions & 2 deletions javascript/packages/core/lib/meta/TypeMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const fieldEncoder = new MetaStringEncoder("$", "_");
const fieldDecoder = new MetaStringDecoder("$", "_");
const pkgEncoder = new MetaStringEncoder(".", "_");
const pkgDecoder = new MetaStringDecoder(".", "_");
const typeNameEncoder = new MetaStringEncoder("$", ".");
const typeNameDecoder = new MetaStringDecoder("$", ".");
const typeNameEncoder = new MetaStringEncoder("$", "_");
const typeNameDecoder = new MetaStringDecoder("$", "_");

const COMPRESS_META_FLAG = 1n << 8n;
const RESERVED_META_FLAGS = 0b111n << 9n;
Expand Down
26 changes: 26 additions & 0 deletions javascript/test/typemeta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,32 @@ describe("typemeta", () => {

expect(result).toBeInstanceOf(EmptyWrapper);
});

// Bytes a spec-conformant peer (for example Java) emits for a named struct
// with namespace "example", typeName "Type_1", and one fixed int32 field
// "v". The type name uses LOWER_UPPER_DIGIT_SPECIAL, where char value 63 is
// "_" per the spec's type-name special-char set ("$", "_").
const specTypeNameMetaBytes = new Uint8Array([
16, 64, 45, 74, 58, 106, 49, 48, 161, 21, 18, 224, 99, 214, 64, 22, 90, 193, 226, 127, 168, 64,
4, 84,
]);

test("decodes spec char value 63 in type names as underscore", () => {
const reader = new BinaryReader({});
reader.reset(specTypeNameMetaBytes);
const decoded = TypeMeta.fromBytes(reader);
expect(decoded.getTypeName()).toBe("Type_1");
});

test("encodes underscore type names with the spec charset", () => {
const meta = TypeMeta.fromTypeInfo(
Type.struct(
{ namespace: "example", typeName: "Type_1" },
{ v: Type.int32({ encoding: "fixed" }) },
),
);
expect(Array.from(meta.toBytes())).toEqual(Array.from(specTypeNameMetaBytes));
});
});

function typeMetaBodyOffset(bytes: Uint8Array) {
Expand Down
Loading