[Gambas-user] MkXXX$() functions

Kevin Fishburne kevinfishburne at ...1887...
Sun Jan 16 18:31:48 CET 2011


On 01/16/2011 09:29 AM, Benoît Minisini wrote:
>>
>> I read the documentation on structures and they look interesting if not
>> tricky. Sounds like a good solution to sending groups of variables of
>> differing datatypes as a single UDP packet, but who knows until I change
>> my code to use structures. Will maintain current build for now to keep
>> moving forward, but will use structures if they are more efficient or
>> the other functions are removed. ASC() and STR() should be removed then,
>> too. Kidding...
> Asc() and Str$() have nothing to do with the MkXXX$() family. Asc() returns
> the ASCII code of a character, and Str$() converts an expression into a string
> by using the current localization. So they won't disappear.
>
> But MkXXXX$() do not seem to be useful:
>
> - They can be replaced by structures.
>
> - Moreover, they can lead to bad design : data sent to the network must be
> big-endian, and MkXXXX$() cannot guarantee that. For example, ARM CPUs can be
> big-endian, and they become more and more important!
>
> - And, finally, your code will be cleaner and easier to read if you replace a
> bunch of MkXXXX$() by structures. And a little bit faster! :-)
>
> I hope I will convince you to rewrite your code. :-s
>
> P.S. Did you write an article for Slashdot recently?
>

Yes, it seems you have convinced me. I have one final question however. 
Currently a UDP packet is being received as a single string of mixed 
datatypes. The recipient looks at the value of the first byte to 
determine the type of packet. Here are some made-up examples of packet 
contents:

Byte=0, String=?, String=?
Byte=1, Short=?, Short=?, Float=?, Float=?, Byte=?, Byte=?
Byte=2, Byte=?, Byte=?, Float=?, Float=?

The three packets have different total sizes and different datatype 
patterns. The only reliable constant is that first identifying byte. 
There are hundreds of packet types to minimize bandwidth, each one 
tailored to a specific purpose.

Is it possible for the recipient to load the UDP packet into a structure 
without knowing which structure it needs to go in to? Basically, if I 
know the first value in the structure is always a byte, can only that 
byte be read before dumping the entire thing back into a structure?

And yes, I had my first Slashdot article posted yesterday. Ken at Ultima 
Aiera said he got a record for hits to his site because of it...nice.

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list