Type byte-data

BlitzMax Forums/BlitzMax Programming/Type byte-data

Sub_Zero(Posted 2007) [#1]
When fooling around with types, I noticed when trying to assign a byte array to a type, it doesn't assign the bytes as raw data, instead it stores a byte pointer.

Im in need of storing chunks of bytes in a type, so I can just send the whole object to en external function. I've tried creating byte arrays, banks.

Is there an easier way of doing this:

Type icmp_echo
	Field iType:Byte	' Type of icmp message
	Field code:Byte		' Subcode icmp message
	Field checksum:Short	' Checksum icmp message
	Field ident:Short	' Identifier icmp message
	Field seq:Short		' Sequence number
	Field data:Byte
	Field data1:Byte
	Field data2:Byte
	Field data3:Byte
	Field data4:Byte
	Field data5:Byte
	Field data6:Byte
	Field data7:Byte
	Field data8:Byte
	Field data9:Byte
	Field data10:Byte
	Field data11:Byte
	Field data12:Byte
	Field data13:Byte
	Field data14:Byte
	Field data15:Byte
	Field data16:Byte
	Field data17:Byte
	Field data18:Byte
	Field data19:Byte
	Field data20:Byte
	Field data21:Byte
	Field data22:Byte
	Field data23:Byte
	Field data24:Byte
	Field data25:Byte
	Field data26:Byte
	Field data27:Byte
	Field data28:Byte
	Field data29:Byte
	Field data30:Byte
	Field data31:Byte
End Type


Thanks in advance


H&K(Posted 2007) [#2]
strings?


Sub_Zero(Posted 2007) [#3]
no, sequence of bytes or byte array


Gabriel(Posted 2007) [#4]
Not really no. I tend to pass a bank pointer and then have a function to put it back into a type. It carries an ever so slight performance overhead, but I'd prefer that to having to have all those type fields.


grable(Posted 2007) [#5]
How about using Long instead? less to type ;)


Sub_Zero(Posted 2007) [#6]
If i declare a field as an byte array, it leaves a pointer value in the type instead of the actual bytes of the array.
That is also the case if i declare a field as a bank.

Example code:
Type icmp_echo
	Field iType:Byte	' Type of icmp message
	Field code:Byte		' Subcode icmp message
	Field checksum:Short	' Checksum icmp message
	Field ident:Short	' Identifier icmp message
	Field seq:Short		' Sequence number
	Field payload:Byte[32]	' Data
End Type

local packet:icmp_echo = new icmp_echo
local counter:byte = 0

for counter = 0 to 31
	packet.payload[counter] = counter
next

extOsFunction(packet,sizeof(packet))


Can dynamic fields be declared in a type?

Edit:
Thanks for the fast replies =)


Sub_Zero(Posted 2007) [#7]
How about using Long instead? less to type ;)


That would do as long as the size of the data is not an odd number =)


grable(Posted 2007) [#8]

That would do as long as the size of the data is not an odd number =)


True, but you could allways padd it with a smaller type if that is the case.


Sub_Zero(Posted 2007) [#9]
Thanks for the help =)


Who was John Galt?(Posted 2007) [#10]
Gab is talking about writing a function to copy the data from the type to a bank, and filling in the data array. None of this is ideal but it's what we're stuck with in Blitz.


Sub_Zero(Posted 2007) [#11]
Yeah i get the picture, but it wouldn't work in my case since the function called with the type is an external os function. If I just had to call a blitzmax function there would be no problem.

Atleast now I know I have to live with it. Thanks for the info.


Sub_Zero(Posted 2007) [#12]
Hmm, I found an interesting topic on this forum concerning this: http://www.blitzbasic.com/Community/posts.php?topic=50604

Edit: Nvm, same problem, still have to pass on a pointer.