@ unmanaged export class ASONHeader { referenceTableByteLength : usize ; dataSegmentTableByteLength : usize ; arrayTableByteLength : usize ; arrayDataSegmentTableByteLength : usize ; staticReferenceTableByteLength : usize ; customTableByteLength : usize ; linkTableByteLength : usize ; arrayLinkTableByteLength : usize ; setReferenceTableByteLength : usize ; setEntryTableByteLength : usize ; mapReferenceTableByteLength : usize ; mapKeyValueEntryTableByteLength : usize ; } @ unmanaged export class ReferenceEntry { rtId : u32 ; entryId : u32 ; offset : usize ; } @ unmanaged export class LinkEntry { parentEntryId : u32 ; offset : usize ; childEntryId : u32 ; } @ unmanaged export class DataSegmentEntry { rtId : u32 ; entryId : u32 ; byteLength : usize ; } @ unmanaged export class ArrayEntry { rtId : u32 ; entryId : u32 ; length : i32 ; } @ unmanaged export class ArrayDataSegmentEntry { rtId : u32 ; entryId : u32 ; align : usize ; length : i32 ; } @ unmanaged export class ArrayLinkEntry { parentEntryId : u32 ; index : i32 ; childEntryId : u32 ; } @ unmanaged export class SetReferenceEntry { entryId : u32 ; rtId : u32 ; entrySize : usize ; capacity : i32 ; } @ unmanaged export class SetKeyEntry { parentEntryId : u32 ; childEntryId : u32 ; isString : bool ; } @ unmanaged export class MapReferenceEntry { entryId : u32 ; rtId : u32 ; capacity : i32 ; entrySize : usize ; } export const enum MapKeyValueType { Dummy , String , Number } @ unmanaged export class MapKeyValuePairEntry { parentEntryId : i32 ; keySize : i32 ; keyType : MapKeyValueType ; keyIsSigned : bool ; valueSize : i32 ; valueType : MapKeyValueType ; key : u64 ; value : u64 ; } @ unmanaged export class StaticReferenceEntry { entryId : u32 ; ptr : usize ; } @ unmanaged export class CustomEntry { entryId : u32 ; rtId : u32 ; offset : usize ; byteLength : i32 ; deserializeFuncIndex : i32 ; } export class Table < T > { data : StaticArray < u8 > ; index : i32 = 0 ; constructor ( defaultSize ) { if ( isManaged < T > ( ) ) ERROR ( "Internal class error. T must not be managed." ) ; this . data = new StaticArray < u8 > ( < i32 > defaultSize ) ; } ensureSize ( newLength ) { let data = this . data ; let length = data . length ; if ( length < newLength ) { let newData = new StaticArray < u8 > ( newLength << 1 ) ; memory . copy ( changetype < usize > ( newData ) , changetype < usize > ( data ) , < usize > length ) ; this . data = newData ; } } allocate ( ) { let index = this . index ; let nextIndex = index + < i32 > offsetof < T > ( ) ; this . ensureSize ( nextIndex ) ; let result = changetype < T > ( changetype < usize > ( this . data ) + < usize > index ) ; this . index = nextIndex ; return result ; } allocateSegment ( length ) { let index = this . index ; let nextIndex = index + length ; this . ensureSize ( nextIndex ) ; let result = changetype < usize > ( this . data ) + < usize > index ; this . index = nextIndex ; return result ; } reset ( ) { this . index = 0 ; memory . fill ( changetype < usize > ( this . data ) , 0 , this . data . length ) ; } public static from < T > ( data , length ) { let result = __new ( offsetof < Table < T > > ( ) , idof < Table < T > > ( ) ) ; __pin ( result ) ; let dataArray = new StaticArray < u8 > ( < i32 > length ) ; memory . copy ( changetype < usize > ( dataArray ) , data , length ) ; let resultRef = changetype < Table < T > > ( result ) ; resultRef . data = dataArray ; __unpin ( result ) ; return resultRef ; } copyTo ( array , offset ) { memory . copy ( changetype < usize > ( array ) + offset , changetype < usize > ( this . data ) , < usize > this . index ) ; } }