Byte Array Conversion

I'm trying to read data after making a winsock call.  the data I get back is a byte array.  the problem i'm having is the data is mixed data types.  I can't just convert it all to strings as it has integer, byte, string, and float datatypes.  I'm not sure how to go about parsing this byte array to get the data i need.  I beleve the data is chr(0) seperated but the problem is the integer can have a 0 value.  I'm not sure how to tell the two apart in a byte array.  any help would be great

the format is . . .
--------------------------
      Server responds with the following packet:
      (int32)            -1
      (byte)            ASCII 'D' (players response, S2A_PLAYER)
      (byte)            active client count

      for each active client
            (byte)            client number / index
            (string)            player name
            (int32)            client's frag total
            (float32)            client's total time in-game
luige34Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

master01Commented:
why can you dim it as "any"?
0
luige34Author Commented:
I don't know what "any" is?  Please explain.
0
luige34Author Commented:
Oh, any only works with the Declare Statement
0
luige34Author Commented:
Didn't Answer Question.
0
bob_obobCommented:
From your description:
(int32) -1
(byte) ASCII 'D'
(byte) active client count

repeats:
 (byte) client number / index
 (string) player name
 (int32) client's frag total
 (float32) client's total time in-game


If this is correct, the only place that length varies is each string.  It is probably terminated with a null (char(0)) like you expect, but that's the only part.  the other parts are fixed in size.  You can count the other bytes, and always know whether a zero is a real value or the end of one of the strings.


So you would need to parse the byte array.  First toss out the top two values because you know what they mean.
then get the count.
Using the count, loop through getting the client data:

First, the number, one byte.
then the name, however many bytes it takes to reach the null character (and not including it)
then the two 32-bit numbers.

then repeat the loop, because the next byte will be the next client number/index

good luck with it,
     Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.