Skip to main content

Parse Header of Packet

We have three type packet:

  • request
  • response
  • push

The type of packet and some other info can decide the length of packet. Then length of Header is 1 byte.

info

The length of Header is 1 byte.

Structure

 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
| type |v|g|re.|
+-+-+-+-+-+-+-+-+
FieldLength in bitdescription
type4packet type:
1 - request
2 - resopnse
3 - push
verify1if have signature data

0 - Yes
1 - No
gzip1if use gzip to compress data:

1 - Yes
0 - No
reserve2reversed

Example

// reserve - 0, gzip - 0, verify - 0,  type - 1
0b 0000 0001

// reserve - 0, gzip - 1, verify - 0, type - 2
0b 0011 0010

// reserve - 0, gzip - 1, verify - 1, type - 3
0b 0001 0011


// reserve - 3, gzip - 1, verify - 0, type - 3
0b 1110 0011