TooTallNate / ref-struct

Create ABI-compliant "struct" instances on top of Buffers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ref-array in ref-struct

S0c5 opened this issue · comments

Hi, I need help,is it possible to use ref-array in an structure ?

Byte =  ref.types.uchar;
ByteArray = ArrayType (Byte);
Uint32 = ref.types.uint32;

BlockData = Struct({
  BlockIndexInSector: Int32
  Data : new ByteArray(16)
})

this code, show error.

AssertionError: could not determine a proper "type" from: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]  at Object.coerceType (node_modules\ref\lib\ref.js:389:3)

It sure is! Just drop the new operator and a "type" object will be returned instead of an instance of the byte array. See the tests for some more examples. Cheers!

So you'd want this:

Byte =  ref.types.uchar;
ByteArray = ArrayType (Byte);
Uint32 = ref.types.uint32;

BlockData = Struct({
  BlockIndexInSector: Int32
  Data : ByteArray(16)
})

Thank u very much :)

i am testing now :)