Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(javascript): Added serialization and serialization for Type Meta Layer #1825

Merged
merged 35 commits into from
Sep 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d9ee8cd
Added wrapper on typemeta
Forchapeatl Sep 2, 2024
b0d73b9
Add files via upload
Forchapeatl Sep 2, 2024
03f6227
Update object.ts
Forchapeatl Sep 2, 2024
f639b3c
using BinaryBuilderReader
Forchapeatl Sep 7, 2024
5d30608
Removed MetaString and Using TypeMeta
Forchapeatl Sep 7, 2024
b88b616
Update builder.ts
Forchapeatl Sep 7, 2024
3a4e9f4
reoved TypeMeta
Forchapeatl Sep 9, 2024
a7d7bf1
added ownName to binary.reader
Forchapeatl Sep 9, 2024
b81255a
moved from TypeMetaWrapper to TypeMetaBuilder
Forchapeatl Sep 9, 2024
d259a2d
Added TypeMeta
Forchapeatl Sep 9, 2024
2780033
Added TypeMeta to constructor
Forchapeatl Sep 11, 2024
81b274f
removed TypeMeta from constructor
Forchapeatl Sep 12, 2024
b67f509
FIxed syntax error
Forchapeatl Sep 14, 2024
753869e
fixed lint errors
Forchapeatl Sep 24, 2024
ef92c34
Fixed Meta Layer Buffer
Forchapeatl Sep 24, 2024
615a473
fixed byte length over flow
Forchapeatl Sep 24, 2024
42845e6
removed BinaryReader Builder dependency
Forchapeatl Sep 24, 2024
1434328
fixed lint errors
Forchapeatl Sep 24, 2024
418f4a5
Fixed Meta Layer Buffer
Forchapeatl Sep 24, 2024
7b666c2
fixed lint errors
Forchapeatl Sep 24, 2024
4a3b3f5
fixed lint errors
Forchapeatl Sep 24, 2024
aedf2aa
fixed lint errors
Forchapeatl Sep 24, 2024
f3b87da
Merge branch 'main' into Forchapeatl-TypeMeta
Forchapeatl Sep 24, 2024
9c48706
switched to camel casing
Forchapeatl Sep 26, 2024
b9c3cc9
switched to camel casing
Forchapeatl Sep 26, 2024
636fb05
switched to camel casing
Forchapeatl Sep 26, 2024
5418532
Added Compatible mode
Forchapeatl Sep 27, 2024
7cd91cd
Added mode to fury config
Forchapeatl Sep 27, 2024
2bb55ad
exported Mode
Forchapeatl Sep 27, 2024
1555617
used Mode from type.ts
Forchapeatl Sep 27, 2024
f107fc1
SchemaConsistent for default mode
Forchapeatl Sep 27, 2024
37e88d8
Reading TypeMeta only in Compatible mode
Forchapeatl Sep 28, 2024
91fc901
Imported Fury Mode
Forchapeatl Sep 28, 2024
1941170
fixed lint errors
Forchapeatl Sep 28, 2024
83bb434
Merge branch 'main' into Forchapeatl-TypeMeta
theweipeng Sep 28, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
switched to camel casing
  • Loading branch information
Forchapeatl authored Sep 26, 2024
commit 9c487068d40706977e5eb394651f4034d3785637
84 changes: 42 additions & 42 deletions javascript/packages/fury/lib/meta/TypeMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ enum Encoding {
}

export class FieldInfo {
constructor(private field_name: string, private field_id: number) {
constructor(private fieldName: string, private fieldId: number) {
}

static u8_to_encoding(value: number) {
static u8ToEncoding(value: number) {
switch (value) {
case 0x00:
return Encoding.Utf8;
Expand All @@ -42,102 +42,102 @@ export class FieldInfo {
}
}

static from_bytes(reader: BinaryReader) {
static fromBytes(reader: BinaryReader) {
const header = reader.uint8();
let size = (header & 0b11100000) >> 5;
size = (size === 0b111) ? reader.varInt32() + 7 : size;
const type_id = reader.int16();
const typeId = reader.int16();
// reader.skip(size);
const field_name = MetaString.decode(reader.buffer(size)); // now we commentd this line , the code work well
return new FieldInfo(field_name, type_id);
const fieldName = MetaString.decode(reader.buffer(size)); // now we commentd this line , the code work well
return new FieldInfo(fieldName, typeId);
}

to_bytes() {
toBytes() {
const writer = new BinaryWriter({});
const meta_string = MetaString.encode(this.field_name);
const metaString = MetaString.encode(this.fieldName);
let header = 1 << 2;
const size = meta_string.byteLength;
const big_size = size >= 7;
if (big_size) {
const size = metaString.byteLength;
const bigSize = size >= 7;
if (bigSize) {
header |= 0b11100000;
writer.uint8(header);
writer.varInt32(size - 7);
} else {
header |= size << 5;
writer.uint8(header);
}
writer.int16(this.field_id);
writer.buffer(meta_string);
writer.int16(this.fieldId);
writer.buffer(metaString);
return writer.dump();
}
}

// Using classes to emulate struct methods in Rust
class TypeMetaLayer {
constructor(private type_id: number, private field_info: FieldInfo[]) {
constructor(private typeId: number, private fieldInfo: FieldInfo[]) {
}

get_type_id() {
return this.type_id;
getTypeId() {
return this.typeId;
}

get_field_info() {
return this.field_info;
getFieldInfo() {
return this.fieldInfo;
}

to_bytes() {
toBytes() {
const writer = new BinaryWriter({});
writer.varInt32(this.field_info.length);
writer.varInt32(this.type_id);
for (const field of this.field_info) {
writer.buffer(field.to_bytes());
writer.varInt32(this.fieldInfo.length);
writer.varInt32(this.typeId);
for (const field of this.fieldInfo) {
writer.buffer(field.toBytes());
}
return writer.dump();
}

static from_bytes(reader: BinaryReader) {
const field_num = reader.varInt32();
const type_id = reader.varInt32();
const field_info = [];
for (let i = 0; i < field_num; i++) {
field_info.push(FieldInfo.from_bytes(reader));
static fromBytes(reader: BinaryReader) {
const fieldNum = reader.varInt32();
const typeId = reader.varInt32();
const fieldInfo = [];
for (let i = 0; i < fieldNum; i++) {
fieldInfo.push(FieldInfo.fromBytes(reader));
}
return new TypeMetaLayer(type_id, field_info);
return new TypeMetaLayer(typeId, fieldInfo);
}
}

export class TypeMeta {
constructor(private hash: bigint, private layers: TypeMetaLayer[]) {
}

get_field_info() {
return this.layers[0].get_field_info();
getFieldInfo() {
return this.layers[0].getFieldInfo();
}

get_type_id() {
return this.layers[0].get_type_id();
getTypeId() {
return this.layers[0].getTypeId();
}

static from_fields(type_id: number, field_info: FieldInfo[]) {
return new TypeMeta(BigInt(0), [new TypeMetaLayer(type_id, field_info)]);
static fromFields(typeId: number, fieldInfo: FieldInfo[]) {
return new TypeMeta(BigInt(0), [new TypeMetaLayer(typeId, fieldInfo)]);
}

static from_bytes(reader: BinaryReader) {
static fromBytes(reader: BinaryReader) {
const header = reader.uint64();
const hash = header >> BigInt(8);
const layer_count = header & BigInt(0b1111);
const layerCount = header & BigInt(0b1111);
const layers = [];
for (let i = 0; i < layer_count; i++) {
layers.push(TypeMetaLayer.from_bytes(reader));
for (let i = 0; i < layerCount; i++) {
layers.push(TypeMetaLayer.fromBytes(reader));
}
return new TypeMeta(hash, layers);
}

to_bytes() {
toBytes() {
const writer = new BinaryWriter({});
writer.uint64(BigInt((this.hash << BigInt(8)) | BigInt((this.layers.length & 0b1111))));
for (const layer of this.layers) {
writer.buffer(layer.to_bytes());
writer.buffer(layer.toBytes());
}
return writer.dump();
}
Expand Down
Loading