> I've had some trouble posting to the various GAMBAS mailing lists in > the past and so have been using the Nabble forum, which generally has > echoed my posted to the proper mailing list. It seems to not have been > working so well recently though. As such I'm reposting my last post > directly to the mailing list and hopefully it will be delivered. Here's > the original thread for reference: > > http://old.nabble.com/someshort%3D%22xy%22-returns-%22Wanted-short,-got-str > ing-instead%22-td29715645.html#a29732625 >
First : if you post on nabble, then nabble will post on the mailing-list. So you will logically have more problem than if you post directly. Second : on a mailing-list, you never answer a thread with a mail that has no relation with it. So please post a new thread each time you start to talk about a new subject. > ... > > Basically I'm sending mixed datatypes as a single UDP packet. There may > be 1024 Bytes followed by 512 Shorts, etc., in a known sequence that can > be interpreted by the client. > > When the client interprets the data in the received UDP packet it needs > to assign different pieces of it to variables of varying datatypes. The > string is constructed on one side then deconstructed on the other. There > may be something fundamental that I'm missing (no surprise), but the > packet data is being received as a String and as such I must convert > segments of that string to the corresponding datatypes. > > I'm currently trying to write a function to convert a four-byte segment > of the string to a Single, and have a conversion module for all the > other datatypes that could be encoded in the UDP string. > > My current conversion function for Shorts is similar to Tobi's suggestion: > > PUBLIC FUNCTION ToShort(source AS String) AS Short > > ' Convert a two-byte string to a short datatype value. > > RETURN Asc(Mid$(source, 2, 1)) * 256 + Asc(Mid$(source, 1, 1)) > > END > > This works well, but I need similar functions for most common datatypes > (Integer, Long, Single, Float). Is this possible, or am I making a > fundamental programming mistake and there is an easier way? The app in > question will push the limits of typical upstream bandwidth so I need to > keep the packet size/frequency as low as possible. Most network > transactions will not consist of arrays, but a few values that must be > sent as raw data rather than numerical text strings. There is no good solution in Gambas 2 to forge UDP packets except the one you did. But in Gambas 3, the READ and WRITE instructions can serialize arrays and collection, and better, you have C-like structures. They are not serializable yet, but I should do that too if I keep being logical :-). So I suggest you use Gambas 3! If you don't succeed in compiling it, please post all the details (again?). It should not be harder than making Ubuntu Maverick work with a nvidia card. :-) (took me a day, I should have stayed with my Mandriva). Regards, -- Benoît Minisini ------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user