-
Notifications
You must be signed in to change notification settings - Fork 31
Framing
Mathias Cloet edited this page Feb 6, 2020
·
1 revision
Because Tcp just sends a stream to the connected socket, it's impossible to know where 1 message starts and another one stops, for this reason this library uses message framing. The first byte contains Flags, these flags determine what parts are present in the message.
Every type of message can have a different type of framing. Below is the max amount that can be used when framing a message.
Message part | Location in byte array | More info |
---|---|---|
Flags | 0 - 1 byte | Contains 8 possible boolean values |
MessageLength | 1-4 - 4 bytes | The total amount of bytes the message contains |
MessageType | 5 - 1 byte | 255 Possible types of different messages |
HeaderLength | 6-10 - 4 bytes | The length of the header |
FilePart | 10-14 - 4 bytes | The current part of the filetransfer |
TotalParts | 14-18 - 4 bytes | Total amount of parts of the filetransfer |
HeaderData | 18 + HeaderLength | The Header bytes |
MessageData | 18 + HeaderLength + MessageLength | Message bytes |
When framing a normal message this will be a lot smaller:
Message part | Location in byte array | More info |
---|---|---|
Flags | 0 - 1 byte | Contains 8 possible boolean values |
MessageLength | 1-4 - 4 bytes | The total amount of bytes the message contains |
MessageType | 5 - 1 byte | 255 Possible types of different messages |
MessageData | 18 + HeaderLength + MessageLength | Message bytes |