In my application, I handle many different types of packets. As such, I define each packet structure inside the case block that needs it inside my HandleMessage() procedure, because the structures are only needed in this one specific instance. For example:
Code: Select all
Select Type
Case #PacketType_Connection
Structure ConnectionPacket
Name$
OS.i
EndStructure
Protected Connection.ConnectionPacket
ExtractJSONStructure(JSONValue(ID), @Connection, ConnectionPacket)
Users(Str(ClientID))\Name$ = Connection\Name$
Users(Str(ClientID))\OS$ = OSVersionString(Connection\OS)
Users(Str(ClientID))\ID = ClientID
My question is, how recommended is this, and are there any drawbacks? I know I've seen this discussed here before, but "structure inside procedure" is an unfortunately unspecific search. It compiles and works just fine, but I'm not sure how this actually works under the hood. Are they actually declared in the top-level like any structures not inside a procedure?
Thanks!