Read BinaryStream into Struct

How do I do this?

If I have a structure and a BinaryStream, how do I read from the BinaryStream and place its contents into a struct?

[code]Structure TestStruct
Dim something As UInt32
Dim somethingElse as Single
Dim anotherThing as UInt16
End Structure

Dim bs as BinaryStream = BinaryStream.Open(f,False)
if f<>Nil then
Dim myStruct as TestStruct
// Get the contents from bs into TestStruct
end if[/code]

I don’t want to have to do:

myStruct.something = bs.ReadUInt32 myStruct.somethingElse = bs.ReadSingle myStruct.anotherThing = bs.ReadUInt16

The struct I am working with has a boat-load of members… there has to be a slick way of doing this in Xojo?

thanks…

Dim mystruct as TestStruct
mystruct.StringValue( True ) = bs.Read( mystruct.Size )
// You have to supply the LittleEndian setting when setting the StringValue

OK – Jumped the gun. StringValue lets you transfer binary strings back and forth.

' Read in a triangle... Dim tri as STLTriangle ' Get the size of a STLTriangle Dim nTriSize as Integer = LenB(tri.StringValue(True)) ' Read from the file Dim strBuff as String = bs.Read(nTriSize) ' Transfer the data to the triangle tri.StringValue(True) = strBuff

Even better, Kem! Thank you!