Some C function return aCPointer to a C struct.
The C struct is known.
Now i want to put the C struct into a ByteArray. Basically copy the contents of the struct to a ByteArray.
In GemStone/S this can be done with:
CByteArray fromCPointer: aCPointer numBytes: 120.
"this create aCByteArray with the contents of the struct referenced by CPointer (copying only 120 bytes)"
Is there something similar on Visual Works ? I did not find it yet. It could be possible to replicate C struct at Visual Works level but is only one struct and it is ok to handle it at low level.
There's only the rather ugly
#copyAt:to:size:startingAt:that you can send to a pointer. You need to allocate aByteArrayyourself (make sure it's big enough).The other way (ByteArray -> Pointer) would be done using
#copyAt:from:size:startingAt:.This method works for both
ByteArrayandUninterpretedBytes. If you want to read data from the bytes,UninterpretedBytesmay be more helpful as you can send things like#longAt:to read alongfrom an offset.