diff --git a/gens/ts/function_parsing_ts.py b/gens/ts/function_parsing_ts.py index b198945..734a9a9 100644 --- a/gens/ts/function_parsing_ts.py +++ b/gens/ts/function_parsing_ts.py @@ -88,12 +88,14 @@ def _gen_buffer(self): elem_array.getElementType().asClassParameter() ) - params += "ReadHelper.readArrayStatic(di, () => {\n" + params += ( + "ReadHelper.readArrayStatic(di, (arrayData) => {\n" + ) if elem_param_simple: - params += f"\t\t\treturn di.get{get_formatted_subatomic_type(elem_param_simple.getType())}();\n" + params += f"\t\t\treturn arrayData.get{get_formatted_subatomic_type(elem_param_simple.getType())}();\n" else: - params += f"\t\t\treturn StructParsing.get{elem_param_class.getClass().getName()}(di);\n" + params += f"\t\t\treturn StructParsing.get{elem_param_class.getClass().getName()}(arrayData);\n" params += "\t\t}), " diff --git a/gens/ts/static/net/Datagram.ts b/gens/ts/static/net/Datagram.ts index 3af603a..671cf0b 100644 --- a/gens/ts/static/net/Datagram.ts +++ b/gens/ts/static/net/Datagram.ts @@ -99,7 +99,7 @@ export default class Datagram { } } - public addBlob(arg: string) { + public addBlob(arg: ArrayBuffer) { // TODO: Add this. } diff --git a/gens/ts/static/net/DatagramIterator.ts b/gens/ts/static/net/DatagramIterator.ts index 8dc00b1..5f6a7d7 100644 --- a/gens/ts/static/net/DatagramIterator.ts +++ b/gens/ts/static/net/DatagramIterator.ts @@ -96,9 +96,12 @@ export default class DatagramIterator { return str.join(""); } - public getBlob(): string { - // TODO: Add this. - return ""; + public getBlob(): ArrayBuffer { + const len = this.getUint16(); + const data = this.buffer.slice(this.bufferIndex, this.bufferIndex + len); + this.bufferIndex += len; + + return data; } public getUint32Array(): number[] { diff --git a/gens/ts/static/net/ReadHelper.ts b/gens/ts/static/net/ReadHelper.ts index 1200b2b..3c9a915 100644 --- a/gens/ts/static/net/ReadHelper.ts +++ b/gens/ts/static/net/ReadHelper.ts @@ -5,12 +5,13 @@ import DatagramIterator from "./DatagramIterator"; export default class ReadHelper { - public static readArrayStatic(di: DatagramIterator, callback: () => any): any[] { - const arrayLength = di.getUint16(); + public static readArrayStatic(di: DatagramIterator, callback: (arrayData: DatagramIterator) => any): any[] { + const data = di.getBlob(); + const arrayData = new DatagramIterator(data); const array = []; - for (let i = 0; i < arrayLength; i++) { - array.push(callback()); + while (arrayData.getRemainingSize()) { + array.push(callback(arrayData)); } return array; diff --git a/gens/ts/struct_parsing_ts.py b/gens/ts/struct_parsing_ts.py index 66425ed..7e27e2f 100644 --- a/gens/ts/struct_parsing_ts.py +++ b/gens/ts/struct_parsing_ts.py @@ -47,13 +47,26 @@ def _gen_buffer(self): ) continue + dc_param_class = dc_parameter.asClassParameter() dc_param_simple = dc_parameter.asSimpleParameter() dc_param_array = dc_parameter.asArrayParameter() - if dc_param_simple: + if dc_param_class: + # This is (always?) a struct arg. + elem_dc_class = dc_param_class.getClass() + if not elem_dc_class.isStruct(): + self.notify.warning( + f"Got non-struct class as field param: {name} - {elem_dc_class.getName()}" + ) + continue + + static_out += f"\t\tobj.{field.getName()} = StructParsing.get{elem_dc_class.getName()}(di);\n" + + elif dc_param_simple: static_out += f"\t\tobj.{field.getName()} = di.get{get_formatted_subatomic_type(dc_param_simple.getType())}();\n" + elif dc_param_array: - static_out += f"\t\tobj.{field.getName()} = ReadHelper.readArrayStatic(di, () => {{\n" + static_out += f"\t\tobj.{field.getName()} = ReadHelper.readArrayStatic(di, (arrayData) => {{\n" # TODO: Can we have multi-dimensional arrays? elem_param_simple = ( @@ -64,9 +77,9 @@ def _gen_buffer(self): ) if elem_param_simple: - static_out += f"\t\t\treturn di.get{get_formatted_subatomic_type(elem_param_simple.getType())}();\n" + static_out += f"\t\t\treturn arrayData.get{get_formatted_subatomic_type(elem_param_simple.getType())}();\n" elif elem_param_class: - static_out += f"\t\t\treturn StructParsing.get{elem_param_class.getClass().getName()}(di);\n" + static_out += f"\t\t\treturn StructParsing.get{elem_param_class.getClass().getName()}(arrayData);\n" static_out += "\t\t});\n" diff --git a/gens/ts/util_ts.py b/gens/ts/util_ts.py index 343cd95..4d807bc 100644 --- a/gens/ts/util_ts.py +++ b/gens/ts/util_ts.py @@ -16,9 +16,12 @@ def get_ts_type_for_subatomic_type(subatomic_type): elif subatomic_type in (STUint64, STInt64): return "bigint" - elif subatomic_type in (STChar, STString, STBlob, STBlob32): + elif subatomic_type in (STChar, STString): return "string" + elif subatomic_type in (STBlob, STBlob32): + return "ArrayBuffer" + elif subatomic_type in ( STUint8array, STInt8array,