Andres Quijano wrote:
You'll have to mask the rest of the byte for the next message...
You just have to store the current position in the stored bytes.
maybe
create a class where you can add bits to it until it reaches the msg
length, you'll have to keep count of which bits belong to which
message
As soon as you have read a message, you can discard the associated
bytes, except maybe the last one, which may be shared with the next
message. I don't think you need to add bits to any structure, you just
ave to keep the bytes and the starting position of the next message.
For instance, let's say that your messages are 10 bits long. You receive
1 byte :
1001 0010
As you didn't received the 10 bits, you store the byte into the
container, and store the container into the session. (here, the
container will just store the byte 0x92)
Then you receive the next byte :
0100 1010
This is obvioulsy the end of the first message, and the beginning of the
second message (which is not terminated).
As you now have more than 10 bits to decode (the first byte plus the 2
higher bits of the second byte), you can decode the first message, and
discard the first byte.
The remaining byte (0x4A) will be stored into the container, and we will
also store the current position (2) representing the starting position
of the next message.
Then you receive a third byte :
1011 0000
as you still have the previous byte (0x4A) you can decode the message
001010-1011. The second byte can be discarded, the third byte is stored
into the container, and a new position (4) is also stored there.
Etc...
--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org