Detailed explanation of FAST protocol 4 Existence graph PMap

One,Summary

The existence graph is a relatively basic but very important setting. If the existence graph is not done correctly, there will definitely be problems with the subsequent analysis. But to understand the existence graph clearly, we must first understand the various data types, operators, and nullable attributes. Therefore, although the existence graph is at the front of the FAST data flow, it has to be put at the end.

2.Basic settings of the existence graph

The existence graph is mainly strongly related to the operator type, but it is also slightly related to the nullable attributes and data types. Here we use the operator as the main index and demonstrate the examples in sequence.

Operator

Nullable properties

PMap

illustrate

DEFAULTDefault

False/True

Occupy 1 place

After the field uses the DEFAULT operator, 1 bit will be occupied in PMap to indicate whether the field value is transmitted. If the value of this bit in PMap is 0, indicating that no value is passed, the parsing result of this field is "default value". If the value of this bit in PMap is 1, it indicates that there is a passed value, and the parsing result of this field shall be based on the passed value.

COPYCopy

False/True

Occupy 1 place

After the character uses the COPY operator, it will occupy 1 bit in PMap to indicate whether the field value is transmitted. If the value of this bit in PMap is 0, indicating that no value has been transmitted, the parsing result of this field is "the value of the last transmission--that is, copied". If the value of this bit in PMap is 1, it indicates that there is a passed value, and the parsing result of this field shall be based on the passed value.

INCREMENTincrement

False/True

Occupy 1 place

After the character uses the INCREMENT operator, it will occupy 1 bit in PMap to indicate whether the field value is transmitted. If the value of this bit in PMap is 0, indicating that no value has been transmitted, the parsing result of this field is "the value of the last transmission + 1". If the value of this bit in PMap is 1, it indicates that there is a passed value, and the parsing result of this field shall be based on the passed value.

TAIL suffix

False/True

Occupy 1 place

After the character uses the TAIL operator, it will occupy 1 bit in PMap to indicate whether the field value is transmitted. If the value of this bit in PMap is 0, indicating that no value has been transmitted, the parsing result of this field is "the value of the last transmission". If the value of this bit in PMap is 1, indicating that there is a transferred value, the parsing result of this field is the last transferred value + the tail part.

CONSTANTconstant

False

No space occupied

When the field uses the CONSTANT operator and the nullable attribute is False, it does not occupy a position in PMap. No matter whether the field has a set value during encoding, no value is transmitted in the stream, and the parser only parses according to the preset constant value.

CONSTANTconstant

True

Occupy 1 place

When the field uses the CONSTANT operator and the nullable attribute is True, it occupies 1 bit in PMap. If the field has a set value during encoding, the bit value in PMap is 1, indicating that the field is not empty and should be parsed to the default value. If the field is not set with a value during encoding, the bit value in PMap is 0, indicating that the field is empty and should be parsed as null.

NONENone

False/True

No space occupied

When the field uses the NONE operator, it does not occupy a position in PMap. That is, the field value will definitely be transmitted in the FAST stream.

Three,Example

1, DEFAULT default operator

Operator

Nullable properties

PMap

illustrate

DEFAULTDefault

False/True

Occupy 1 place

After the field uses the DEFAULT operator, 1 bit will be occupied in PMap to indicate whether the field value is transmitted. If the value of this bit in PMap is 0, indicating that no value is passed, the parsing result of this field is "default value". If the value of this bit in PMap is 1, it indicates that there is a passed value, and the parsing result of this field shall be based on the passed value.

The results of running the above code are as follows:

msg111= -> {123, 1}

msg111= -> {123, 2}

msg111= -> {123, 3}

outByteStr=11100000,11111011,10000001,10000000,10100000,10000011,

Binary data is parsed as follows:

Note in advance: It should be noted that the template ID field must occupy 1 digit in PMap. According to "2. Basic Settings of Existence Graph", the data field here must occupy 1 digit in PMap.

binary number

Decoding result

illustrate

11100000

PMap

The first bit of PMap is the stop bit

The second digit is the template ID, which indicates that this field is transmitted

The third bit is the data field, which indicates that the field is transmitted

11111011

123

According to PMap, we know that there is a transmission template ID field, so template ID=123

10000001

1

According to PMap, we know that there is a transmission data field, so the data field = 1

10000000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the field is not transmitted. According to the field properties, the value of the data field should be =2 (default value)

10100000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the data field is transmitted

10000011

3

According to PMap, we know that there is a transmission data field, so the data field = 3

Question: How to change the nullable property to true

The results of running the above code are as follows:

msg111= -> {123, 1}

msg111= -> {123, 2}

msg111= -> {123, null}

outByteStr=11100000,11111011,10000010,10000000,10100000,10000000,

Binary data is parsed as follows:

binary number

Decoding result

illustrate

11100000

PMap

The first bit of PMap is the stop bit

The second digit is the template ID, which indicates that this field is transmitted

The third bit is the data field, which indicates that the field is transmitted

11111011

123

According to PMap, we know that there is a transmission template ID field, so template ID=123

10000010

1

Note: Since the field is nullable, it needs to be decremented by 1.

According to PMap, we know that there is a transmission data field, so the data field = 1

10000000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the field is not transmitted. According to the field properties, the value of the data field should be =2 (default value)

10100000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the data field is transmitted

10000000

Null

According to PMap, we know that there is a transmission data field, so the data field = null

It should be noted that due to the nullable attribute, when the field value is not set, 10000000 is actually passed. At the same time, the third bit in PMap is set to 1 to indicate that the value is passed.

Question: Are the results consistent for other data types?

Verify consistency

2, COPY copy operator

Operator

Nullable properties

PMap

illustrate

COPYCopy

False/True

Occupy 1 place

After the character uses the COPY operator, it will occupy 1 bit in PMap to indicate whether the field value is transmitted. If the value of this bit in PMap is 0, indicating that no value has been transmitted, the parsing result of this field is "the value of the last transmission--that is, copied". If the value of this bit in PMap is 1, it indicates that there is a passed value, and the parsing result of this field shall be based on the passed value.

The results of running the above code are as follows:

msg111= -> {123, 1}

msg111= -> {123, 2}

msg111= -> {123, 2}

outByteStr=11100000,11111011,10110001,10100000,10110010,10000000,

Binary data is parsed as follows:

binary number

Decoding result

illustrate

11100000

PMap

The first bit of PMap is the stop bit

The second digit is the template ID, which indicates that this field is transmitted

The third bit is the data field, which indicates that the field is transmitted

11111011

123

According to PMap, we know that there is a transmission template ID field, so template ID=123

10110001

49

According to PMap, we know that there is a transmission data field, so the data field = "1"

10100000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the field is transmitted

10110010

50

According to PMap, we know that there is a transmission data field, so the data field = "2"

10000000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the field has not been transmitted. According to the operator COPY, it is known that the result "2" of the last transmission should be copied.

3, INCREMENTsubstitution operation mark

Operator

Nullable properties

PMap

illustrate

INCREMENTincrement

False/True

Occupy 1 place

After the character uses the INCREMENT operator, it will occupy 1 bit in PMap to indicate whether the field value is transmitted. If the value of this bit in PMap is 0, indicating that no value has been transmitted, the parsing result of this field is "the value of the last transmission + 1". If the value of this bit in PMap is 1, it indicates that there is a passed value, and the parsing result of this field shall be based on the passed value.

The results of running the above code are as follows:

msg111= -> {123, 1}

msg111= -> {123, 3}

msg111= -> {123, 4}

outByteStr=11100000,11111011,10000001,10100000,10000011,10000000,

Binary data is parsed as follows:

binary number

Decoding result

illustrate

11100000

PMap

The first bit of PMap is the stop bit

The second digit is the template ID, which indicates that this field is transmitted

The third bit is the data field, which indicates that the field is transmitted

11111011

123

According to PMap, we know that there is a transmission template ID field, so template ID=123

10000001

1

According to PMap, we know that there is a transmission data field, so the data field = 1

10100000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the field is transmitted

10000011

3

According to PMap, we know that there is a transmission data field, so the data field = 3

10000000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the field has not been transmitted. According to the operator INCREMENT, it is known that the value of the last transmission should be +1, that is, =4.

4, TAIL suffix operation mark

Operator

Nullable properties

PMap

illustrate

TAIL suffix

False/True

Occupy 1 place

After the character uses the TAIL operator, it will occupy 1 bit in PMap to indicate whether the field value is transmitted. If the value of this bit in PMap is 0, indicating that no value has been transmitted, the parsing result of this field is "the value of the last transmission". If the value of this bit in PMap is 1, indicating that there is a transferred value, the parsing result of this field is the last transferred value + the tail part.

The results of running the above code are as follows:

msg111= -> {123, 111}

msg111= -> {123, 111}

msg111= -> {123, 112}

outByteStr=11100000,11111011,00110001,00110001,10110001,10000000,10100000,10110010,

Binary data is parsed as follows:

binary number

Decoding result

illustrate

11100000

PMap

The first bit of PMap is the stop bit

The second digit is the template ID, which indicates that this field is transmitted

The third bit is the data field, which indicates that the field is transmitted

11111011

123

According to PMap, we know that there is a transmission template ID field, so template ID=123

00110001,00110001,10110001

“111”

According to PMap, we know that there is a transmission data field, so the data field = "111"

10000000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the field has not been transmitted. According to the operator TAIL, it should be parsed to the value "111" of the last transmission.

10100000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

The third bit is the data field, which indicates that the field value is transmitted

10110010

“2”

According to the characteristics of operator TAIL, the last digit of "111" should be replaced with "2", which means the final parsing result is "112"

5,DEFAULT default operator 1

Operator

Nullable properties

PMap

illustrate

CONSTANTconstant

False

No space occupied

When the field uses the CONSTANT operator and the nullable attribute is False, it does not occupy a position in PMap. No matter whether the field has a set value during encoding, no value is transmitted in the stream, and the parser only parses according to the preset constant value.

The results of running the above code are as follows:

msg111= -> {123, 2}

msg111= -> {123, 2}

msg111= -> {123, 2}

outByteStr=11000000,11111011,10000000,10000000,

Binary data is parsed as follows:

binary number

Decoding result

illustrate

11000000

PMap

The first bit of PMap is the stop bit

The second digit is the template ID, which indicates that this field is transmitted

For the fields of the CONSTANT operator, the PMap bit is not occupied and the default value 2 is directly parsed.

11111011

123

According to PMap, we know that there is a transmission template ID field, so template ID=123

10000000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

For the fields of the CONSTANT operator, the PMap bit is not occupied and the default value 2 is directly parsed.

10000000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

For the fields of the CONSTANT operator, the PMap bit is not occupied and the default value 2 is directly parsed.

Question: Is it possible to use CONSTANT without setting the value while encoding

The results of running the above code are as follows:

msg111= -> {123, 2}

msg111= -> {123, 2}

msg111= -> {123, 2}

outByteStr=11000000,11111011,10000000,10000000,

It can be seen that regardless of whether the value is set during encoding, the decoding will be decoded into the preset value, and the field value will not be transmitted in the FAST stream.

Question: Is it possible to set a value different from the default value when encoding?

Answer: Practice has proved that this is not possible and an error will be reported.

6, DEFAULT default operator 2

Operator

Nullable properties

PMap

illustrate

CONSTANTconstant

True

Occupy 1 place

When the field uses the CONSTANT operator and the nullable attribute is True, it occupies 1 bit in PMap. If the field has a set value during encoding, the bit value in PMap is 1, indicating that the field is not empty and should be parsed to the default value. If the field is not set with a value during encoding, the bit value in PMap is 0, indicating that the field is empty and should be parsed as null.

The results of running the above code are as follows:

msg111= -> {123, 2}

msg111= -> {123, 2}

msg111= -> {123, 2}

outByteStr=11100000,11111011,10100000,10100000,

The results of running the above code are as follows:

msg111= -> {123, null}

msg111= -> {123, null}

msg111= -> {123, null}

outByteStr=11000000,11111011,10000000,10000000,

7, NONE no operator

Operator

Nullable properties

PMap

illustrate

NONENone

False/True

No space occupied

When the field uses the NONE operator, it does not occupy a position in PMap. That is, the field value will definitely be transmitted in the FAST stream.

The results of running the above code are as follows:

msg111= -> {123, 1}

msg111= -> {123, 2}

msg111= -> {123, 3}

outByteStr=11000000,11111011,10000001,10000000,10000010,10000000,10000011,

Binary data is parsed as follows:

binary number

Decoding result

illustrate

11000000

PMap

The first bit of PMap is the stop bit

The second digit is the template ID, which indicates that this field is transmitted

11111011

123

According to PMap, we know that there is a transmission template ID field, so template ID=123

10000001

1

For the NONE operator field, the value will be transmitted without looking at PMap, so the data field here is parsed as 1

10000000

PMap

The first bit of PMap is the stop bit

The second bit is the template ID, which indicates that this field has not been transmitted, and the template ID value will continue to use the previous result = 123

10000010

2

对于NONE操作符字段,不看PMap,一定会传输值,故这里数据字段解析为2

10000000

PMap

PMap第一位是停止位

第二位是模版ID,这里表明未传输该字段,则模版ID值沿用上一次的结果=123

10000011

3

对于NONE操作符字段,不看PMap,一定会传输值,故这里数据字段解析为3

问题:可空情况的处理

上述代码运行结果如下:

msg111= -> {123, 1}

msg111= -> {123, null}

msg111= -> {123, 3}

outByteStr=11000000,11111011,10000010,10000000,10000000,10000000,10000100,

二进制数据解析如下:

二进制数

解码结果

说明

11000000

PMap

PMap第一位是停止位

第二位是模版ID,这里表明有传输该字段

11111011

123

根据PMap得知有传输模版ID字段,故模版ID=123

10000010

1

对于NONE操作符字段,不看PMap,一定会传输值,故这里数据字段解析为2-1=1(可空字段要自行-1)

10000000

PMap

PMap第一位是停止位

第二位是模版ID,这里表明未传输该字段,则模版ID值沿用上一次的结果=123

10000000

Null

对于NONE操作符字段,不看PMap,一定会传输值,故这里数据字段解析为null(可空字段0就是null)

10000000

PMap

PMap第一位是停止位

第二位是模版ID,这里表明未传输该字段,则模版ID值沿用上一次的结果=123

10000100

3

对于NONE操作符字段,不看PMap,一定会传输值,故这里数据字段解析为4-1=3(可空字段要自行-1)

四、回顾

通过实例分析可见,PMap其实与操作符强相关,且大部分操作符都会使字段在PMap中占1位,占位目的是为了通过0和1来标识字段是否传输值,比如copy操作符,如对应PMap位为1则表明不传输该字段值,则解码时自动复制上一次解码结果。

Guess you like

Origin blog.csdn.net/weixin_40402375/article/details/132712272