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

Benoît Minisini gambas at ...1...
Fri Apr 1 11:24:56 CEST 2011


> I'm finding that the task of replacing the Mk$ functions with structures
> for UDP packet client/server transactions is a massive undertaking. So
> far it's affecting every part of my project that constructs, parses,
> sends and receives data. As a consequence the network code is going from
> dozens of lines to hundreds, and I'm beginning to see that the actual
> logic of network operations will need to be changed as well.
> 
> I can deal with all of that, but right now I'm just trying to make it
> work without the program becoming ridiculously complex and/or inefficient.
> 
> I have up to 256 different transaction types shared by the client and
> server. Each one is represented by a different structure containing
> multiple datatypes. The structures range from a few bytes to many KB of
> data. Values are assigned to a structure when a transaction must be
> sent, then the structure is sent by the client or server. The recipient
> then parses the structure and assigns its values to different variables.
> 
> Each transaction has an "ID" which represents the order in which it was
> sent and where it should be assigned in the recipient's transaction
> queue array. This ensures that transactions received out of order are
> processed in order. Both the client and the server have their own
> transaction queues that store the transactions they receive.
> 
> The transaction IDs range from 0-255, so originally I had a transaction
> queue array that was something like this:
> 
> Public ts[256, 3] As String ' Server transactions (256: Queue Position,
> 3: Status, Type, Data). Status = "new" or "old".
> 
> Each element of the transaction queue array was generic, meaning it
> could store any transaction type regardless of what data it contained.
> Now that I'm using structures, the transaction data is uniquely
> represented. Instead of a generic "data" string element that I could
> create/parse with MkSingle()/Single@(), I have a unique structure. How
> can I store a unique structure in a generic array of structures? Is this
> possible? Right now I'm thinking I need to have transaction queue arrays
> of [256,256] structures (65536 structures) to accommodate this. Not so
> good when any particular structure could be up to 198 KB + header.
> 
> Any ideas are appreciated, as this is starting to make me postal! :)

I haven't read the all thread, but:

Using a structure just allow you to directly use the READ/WRITE instruction 
because they have a build-in serialization support. But as you noticed, 
handling a lot of different structures is not handy!

Hopefully, you don't have to use structures. You can create one class for each 
packet type, and let them inherit the same parent class. Each class will have 
its own write method (and read) that will serialize/unserialize the packet 
to/from a given stream (that should be a Socket).

Regards,

-- 
Benoît Minisini




More information about the User mailing list