get_attribute

Declaration

int get_attribute(int fd, unsigned int buffSize, unsigned char *buff)

Parameter Description

Table 1 Parameter description

Parameter

Type

Description

fd

int

Device file descriptor

buffSize

unsigned int

Size of the array cache space

buff

unsigned char*

Cache used to transfer data

Function Description

Obtains attributes. The device is determined based on the input fd value, and the attribute ID and value are obtained by parsing the TLV-encoded buffer.

TLV is a variable format. The Type field indicates the attribute ID. The Length field indicates the length of the attribute. The Value field is the attribute value. The length of Type and Length is fixed to 4 bytes. The length of Value varies according to the attribute type. The following figure shows the parsing mode.
Figure 1 TLV parsing

An attribute of the JSON type has multiple subattributes. The value of the JSON attribute is the size of all subattributes in TLV format. The TLV parsing needs to be performed again on the Value attribute. The TLV parsing of the JSON subattributes is performed cyclically using the offset mode until the parsing of the Value attribute is complete. The following figure shows the parsing mode.

Figure 2 Double TLV parsing of JSON attributes