[Gambas-user] gb3 RC1: using structures to replace the loss of Mk$ functions

Kevin Fishburne kevinfishburne at ...1887...
Sun Apr 10 05:18:43 CEST 2011


On 04/08/2011 04:49 PM, Benoît Minisini wrote:
>> Kevin Fishburne wrote:
>>
>> Ahh, I understand a little better. I don't know much about endianness,
>> so please excuse my ignorance here.
>>
>> ...
>>
>> While it would be slow, I could just write functions for flipping the
>> byte order of characters in a string. That would work fine for the
>> client but may impact performance server side. I'll do some
>> experimenting tomorrow to see what I can come up with.
>
> Wikipedia is your friend, Kevin.
>
> http://en.wikipedia.org/wiki/Endianness

Believe it or not I actually read that exact article. It should have 
just said, "Endianness describes the order of the bytes comprising a 
variable stored in memory, file or a network stream," and I would have 
understood, but unfortunately the article was a mile long. Their mention 
of how rare "bit endianness" was should have given me a clue, though. 
I'd always assume it was bit order, not byte order.

> And UTF-8 strings used by Gambas are not endianness-dependent.
>
> Anyway, I'm almost sure that you can decode messages with READ while you
> receive them, and store the decoded data in an array, or a collection (the
> data is then indexed by name, easier but slower), and then process them later
> as you wanted.

I will file this away for possible use later. Right now I'm in the stage 
of "just getting things working", but later when I'm doing stress 
testing and optimization I'll be in the "get shit working as fast as 
possible" phase and may need to rework the transaction processing code.

The good news is that I did finally get it working. It turns out the 
packet payload is NOT reversed, only the individual values. I created 
this function to reverse the bytes for each value in the string when 
necessary:

Public Function Reverse(data As String) As String

   ' Reverse the order of the passed bytes.

   ' General declarations.
   Dim counter As Byte     ' Generic counter.
   Dim length As Byte      ' Length of the passed string.
   Dim reversed As String  ' The reversed string.

   ' Reverse the string
   length = Len(data)
   For counter = length To 1 Step -1
     reversed = reversed & Mid$(data, counter, 1)
   Next

   ' Return the reversed value.
   Return reversed

End

All the transactions are now processed properly, while their payload is 
still stored as a string in an array. Of course calling this function 
slows things down a bit, but I won't know the full implications of this 
until hundreds of players are connected simultaneously. Hopefully it 
won't be too slow.

-- 
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