manual:appendix:protocols:header_datalen

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:appendix:protocols:header_datalen [2018/04/03 12:03]
glebs.ivanovskis added code snippets showing how to add protocol header in various languages
manual:appendix:protocols:header_datalen [2020/08/06 06:53] (current)
marinagen [ZBX-18175] protocol limit 1 GB
Line 1: Line 1:
-==== 4 Header ​and data length ​====+==== 4 Header ====
  
 === Overview === === Overview ===
  
-Header ​and data length are present in response and request messages between Zabbix components. It is required to determine the length of message. +Header ​is present in response and request messages between Zabbix components. It is required to determine the length of message. ​The header consists of:
 <​code>​ <​code>​
-<HEADER> - "ZBXD\x01" (bytes) +<PROTOCOL> - "​ZBXD"​ (bytes)
-<​DATALEN>​ - data length (bytes). 1 will be formatted as 01/​00/​00/​00/​00/00/00/00 (eight bytes, ​64 bit number in little-endian format)+<​FLAGS>​ -the protocol flags, (1 byte). 0x01 - Zabbix communications protocol, 0x02 - compression). 
 +<​DATALEN>​ - data length (bytes). 1 will be formatted as 01/00/00/00 (four bytes, ​32 bit number in little-endian format)
 +<​RESERVED>​ - reserved for protocol extensions (4 bytes).
 </​code>​ </​code>​
  
-To not exhaust memory ​(potentially) Zabbix protocol ​is limited to accept only 128MB in one connection.+When compression is enabled ​(0x02 flagthe <​RESERVED>​ bytes contains uncompressed data size, 32 bit number in little-endian format. 
 + 
 +Zabbix protocol ​has 1GB packet size limit per connection.
  
 === Implementation === === Implementation ===
Line 20: Line 23:
 printf -v LENGTH '​%016x'​ "​${#​DATA}"​ printf -v LENGTH '​%016x'​ "​${#​DATA}"​
 PACK=""​ PACK=""​
-for i in {14..0..-2}; do PACK="​$PACK\\x${LENGTH:​$i:​2}";​ done +for (( i=14; i>=0; i-=)); do PACK="​$PACK\\x${LENGTH:​$i:​2}";​ done 
-printf "​ZBXD\1$PACK%s"​ $DATA+printf "​ZBXD\1$PACK%s" ​"$DATA"
 </​code>​| </​code>​|
 |Java|<​code Java> |Java|<​code Java>
-int length = data.length;​ +byte[] ​header ​= new byte[] { 
-byte[] ​packet ​= new byte[] { + '​Z',​ '​B',​ '​X',​ '​D',​ '​\1',​ 
- '​Z',​ '​B',​ '​X',​ '​D',​ '​\1',​ + (byte)(data.length & 0xFF), 
- (byte)(length & 0xFF), + (byte)((data.length >> 8& 0xFF), 
- (byte)(length >> 8 & 0xFF), + (byte)((data.length >> 16& 0xFF), 
- (byte)(length >> 16 & 0xFF), + (byte)((data.length >> 24& 0xFF), 
- (byte)(length >> 24 & 0xFF), + '​\0',​ '​\0',​ '​\0',​ '​\0'​}
- '​\0',​ '​\0',​ '​\0',​ '​\0'​};​+ 
 +byte[] packet = new byte[header.length + data.length];​ 
 +System.arraycopy(header,​ 0, packet, 0, header.length);​ 
 +System.arraycopy(data,​ 0, packet, header.length,​ data.length);
 </​code>​| </​code>​|
 |PHP|<​code PHP> |PHP|<​code PHP>