SSE Level 2 Vendor Interface Specification(FAST)-15章-FAST Decoder(FAST解析-第四部分)

15.6 FAST decode example

>>>FAST解析例子
Here is an example for decoding a fast message of UA1101:

>>>解析UA1101 FAST消息的例子:
 
Template of UA1101:
<template name="Transaction" id="1101">
        <string name="MessageType" id="35"><constant value="UA1101"/></string>
        <int32 name="DataStatus" id="10121" presence="optional"><default/></int32>
        <int32 name="TradeIndex" id="10011"><increment /></int32>
        <string name="SecurityID" id="48" presence="optional"><copy/></string>
        <int32 name="TradeChannel" id="10115"><copy/></int32>
        <int32 name="TradeRef" id="10012" presence="optional"><increment /></int32>
        <int32 name="TradeTime" id="10013" presence="optional"><copy/></int32>
        <int32 name="TradePrice" id="10014" presence="optional" decimalPlaces="3"><default/></int32>
        <int32 name="TradeQty" id="10015" presence="optional"><default/></int32>
        <int64 name="TradeMoney" id="10016" presence="optional" decimalPlaces="3"><default/></int64>
</template>

 

After the binary data of UA1101 for FAST are extracted from the tag RawData (96),  
 
The binary data, stop bit in red and the number of byte is in bracket:

>>>在这个二进制数据中: 停止位用红色,在括号里的是字节的序号(便于解释):

 

1.  Presence map should be come first, the first presence map for this binary data is 101 1111 111 0000. 

>>>Presence map 应该是首先要考虑的,这个二进制数据的第一个Presence map 是 101 1111 111 0000.

 

2.  The 1st entry of any FAST data is TemplateID (999) and it occupies a presence map bit.  The first
presence map bit is on, so the template ID should be read from the third byte from the binary data.
Template ID is an integer and mandatory field and the stop bit is found in the fourth byte,
therefore, the content is 100 0100 1101 which is 1101 in Dec. The corresponding template is
found by the template ID 1101.
>>>任何FAST数据的第一个实体是TemplateID(999)并且它占据一个Presence map 位。

>>>第一个Presence map 位是on,所以模板ID应该从这个二进制数据的第三个byte被读取。

>>>模板ID是一个整型值,并且是强制字段,并且在第四个byte找到了停止位,

>>>所以实际内容是100 0100 1101,十进制正好是1101。通过模板ID 1101,就找到了相对应的模板。

 

3.  The 2nd entry of UA1101 is DataStatus (10121) which is an optional integer field with default
operator.  It occupied 1 presence map bit and the value of it is off (0).  Therefore, the DataStatus
is absent in the stream.
>>>UA1101的第二个实体是 DataStatus (10121),它是使用默认操作符的可选整型字段。

>>>它占据一个presence map位,并且它的值是off(0).所以,DataStatus 在这个流中是不存在的,缺席的。

 

4.  The 3rd entry of UA1101 is TradeIndex (10011) which is a mandatory integer field with increment
operator.  It occupied 1 presence map bit and it is on (1). Therefore, the value is in the stream and
1 is decoded from 5th byte.
>>>UA1101的第三个实体是 TradeIndex (10011),它是一个使用增量操作符的强制整型字段。

>>>它占据一个presence map位,并且它的值是on(1).所以,这个值是在这个流中的,并且从第五个byte解析出了1。

 

5.  The 4th entry of UA1101 is SecurityID (48) which is an optional ASCII filed with copy operator.
It occupied 1 presence map bit and it is on (1). Therefore, the value is in the stream and started
from the 6th byte.  The stop bit is found in the 11th byte. The value is “600000”. 
>>>UA1101的第四个实体是 SecurityID (48),它是一个使用拷贝操作符的可选ASCII字段。

>>>它占据一个presence map位,并且值是on(1).

>>>所以,这个值是在这个流中的,并且开始于第六个byte。停止位在第11个byte找到。这个值是“600000”。

 

6.  The 5th entry of UA1101 is TradeChannel (10115) which is a mandatory integer field with copy
operator. It occupied 1 presence map bit and it is on (1). Therefore, the value is in the stream and
1 is decoded from 12th byte.
>>>UA1101的第五个实体是 TradeChannel (10115) ,它是一个使用拷贝操作符的强制整型字段。

>>>它占据一个presence map位,并且它的值是on(1).

>>>所以,这个值是在这个流中的,并且从第12个byte解析出了1。


7.  The 6th entry of UA1101 is TradeRef (10012) which is an optional integer field with increment
operator. It occupied 1 presence map bit and it is on (1). The value is in the stream and 1 is
decoded from 13th byte. 

 

>>>UA1101的第六个实体是 TradeRef (10012) ,它是一个使用增量操作符的可选整型字段。

>>>它占据一个presence map位,并且它的值是on(1).

>>>所以,这个值是在这个流中的,并且从第13个byte解析出了1。

 

8.  The 7th entry of UA1101 is TradeTime (10013) which is an optional integer filed with copy
operator. It occupied 1 presence map bit and it is on (1). Therefore, the value is in the stream and
‘93000’ is decoded from 14th byte to 16th byte.
>>>UA1101的第七个实体是 TradeTime (10013) ,它是一个使用拷贝操作符的可选整型字段。

>>>它占据一个presence map位,并且它的值是on(1).

>>>所以,这个值是在这个流中的,并且从第14个byte到第16个byte解析出了‘93000’

 

9.  The 8th entry of UA1101 is TradePrice (10014) which is an optional integer field with default
operator. It occupied 1 presence map bit and it is on (1). Therefore, the value is in the stream and
‘3100’ is decoded from 17th byte to 18th byte. The number of decimal places is 3 for TradePrice,
so the value is 3.100.
>>>UA1101的第八个实体是 TradePrice (10014),它是一个使用默认操作符的可选整型字段。

>>>它占据一个presence map位,并且它的值是on(1).

>>>所以,这个值是在这个流中的,并且从第17个byte到第18个byte解析出了‘3100’。

>>>TradePrice的小数位数是3,所以这个值应是3.100.

 

10. The 9th entry of UA1101 is TradeQty (10015) which is an optional integer field with default
operator. It occupied 1 presence map bit and it is on (1). Therefore, the value is in the stream and
‘200’ is decoded from 19th byte and 20th byte.
>>>UA1101的第九个实体是 TradeQty (10015),它是一个使用默认操作符的可选整型字段。

>>>它占据一个presence map位,并且它的值是on(1).

>>>所以,这个值是在这个流中的,并且从第19个byte到第20个byte解析出了‘200‘。

 

11. The last entry of UA1101 is TradeMoney (10016) which is an optional 64-bit integer field with
default operator. It occupied 1 presence map bit and it is on (1). Therefore, the value is in the
stream and ‘620000’ is decoded from 21st to 23rd
 byte. The number of decimal places is 3 for TradeMoney, so the value is 620.000.
>>>UA1101的最后一个实体是 TradeMoney (10016),它是一个使用默认操作符的可选64位整型字段。

>>>它占据一个presence map位,并且它的值是on(1).

>>>所以,这个值是在这个流中的,并且从第21个byte到第23个byte解析出了‘620000’。

>>>TradeMoney的小数位数是3,所以这个值应是620.000.

 

12. The final result is 999=1101, 35=UA1101, 10011=1, 48=600000, 10115=1, 10012=1,
10013=930000, 10014=3.100, 10015=200, 10016=620.000.
>>>最后的结果是:

>>>999=1101, 35=UA1101, 10011=1, 48=600000, 10115=1, 10012=1,
>>>10013=930000, 10014=3.100, 10015=200, 10016=620.000.


13. As there is still some bytes left, do step 1 to 11 again.
>>>这里仍有一些byte剩余,重复第一步到第十一步。

 

14. Presence map is 110 1011 from 24th byte.
>>>从24个byte开始,Presence map 是 110 1011。


15. The 1st entry is TemplateID (999), the value is 1101 in the stream from 25th
 byte to 26th byte.

>>>第一个实体是TemplateID (999),在流中这个值是1101,并且是从第25个byte到第26个byte.


16. The 2nd entry of UA1101 is DataStatus (10121) which is an optional integer field with default
operator.  It occupied 1 presence map bit and the value of it is on (1).  Therefore, the DataStatus is
in the stream. The value is 1 from 27th byte.

>>>略


17. The 3rd entry of UA1101 is TradeIndex (10011) which is a mandatory integer field with increment
operator.  It occupied 1 presence map bit and it is off (0). Therefore, the value 2 is referred by the
increment value, 1, of TradeIndex plus previous value in the dictionary. 
>>>略


18. The 4th entry of UA1101 is SecurityID (48) which is an optional ASCII filed with copy operator.
It occupied 1 presence map bit and it is on (1). Therefore, the value is in the stream and it is empty
string from 28th.
>>>略


19. The 5th entry of UA1101 is TradeChannel (10115) which is a mandatory integer field with copy
operator. It occupied 1 presence map bit and it is off (0). The trade channel is copied from
previous value in the dictionary which is 1.
>>>略


20. The 6th entry of UA1101 is TradeRef (10012) which is an optional integer field with increment
operator. It occupied 1 presence map bit and it is on (1). The value is in the stream and it is NULL,
so the TradeRef is absent. 
>>>略


21. The 7th entry of UA1101 is TradeTime (10013) which is an optional integer filed with copy
operator. It occupied 1 presence map bit and it is on (1). Therefore, the value is in the stream and
it is NULL which represents TradeRef is absent. 
>>>略


22. The 8th entry of UA1101 is TradePrice (10014) which is an optional integer field with default
operator. It occupied 1 presence map bit and it is off (0). Therefore, the TradePrice is absent.
>>>略


23. The 9th entry of UA1101 is TradeQty (10015) which is an optional integer field with default
operator. It occupied 1 presence map bit and it is off (0). Therefore, the TradePrice is absent.
>>>略


24. The last entry of UA1101 is TradeMoney (10016) which is an optional 64-bit integer field with
default operator. It occupied 1 presence map bit and it is off (0). Therefore, the TradePrice is
absent.
>>>略


25. The final result is 999=1101, 35=UA1101, 100121=1, 10011=2, 10115=1.
>>>略


26. No more byte is in the data. The decode process is finished for this binary data.

>>>没有更多的byte。这个二进制数据解码结束。


 

 

 

SSE Level 2 Vendor Interface Specification(FAST)-15章-FAST Decoder(FAST解析-第四部分)---完---(总15章完)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Fast-RTPS 是一个高性能的实时通信协议,用于在分布式系统中传输实时数据。在 Fast-RTPS 中,每个消息都由头部和数据组成。在本示例中,我们将展示如何解析 Fast-RTPS 消息的头部字段以及 topic name。 首先,我们需要了解 Fast-RTPS 消息头部字段的含义。Fast-RTPS 消息头部包括以下字段: - `protocolId`:Fast-RTPS 协议的版本号。 - `vendorId`:Fast-RTPS 实现的厂商 ID。 - `guidPrefix`:全局唯一标识符的前缀,用于识别 Fast-RTPS 实例。 - `guidEntityId`:Fast-RTPS 实体的唯一标识符。 - `sequenceNumber`:消息的序列号。 - `sourceTimestamp`:消息的时间戳。 - `destinationGuidPrefix`:消息的目标实体的 GUID 前缀。 其中,`guidPrefix` 和 `guidEntityId` 组成了消息的唯一标识符 GUID,用于在 Fast-RTPS 网络中识别消息。 接下来,我们可以通过以下代码示例解析 Fast-RTPS 消息的头部字段和 topic name: ```c++ #include <fastrtps/fastrtps.h> #include <fastrtps/attributes/TopicAttributes.h> void parseFastRTPSMessageHeader(const void* buffer, size_t size) { // Deserialize the message header using Fast-RTPS library eprosima::fastcdr::FastBuffer cdrbuffer(reinterpret_cast<char*>(const_cast<void*>(buffer)), size); eprosima::fastrtps::rtps::CDRMessage_t cdrm(cdrbuffer); eprosima::fastcdr::Cdr cdr_des(cdrm, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); // Parse the fields in the header eprosima::fastrtps::rtps::Header_t header; header.readFromCDRMessage(cdrm); std::cout << "protocolId: " << std::to_string(header.protocolId) << std::endl; std::cout << "vendorId: " << std::to_string(header.vendorId) << std::endl; std::cout << "guidPrefix: " << header.guidPrefix << std::endl; std::cout << "guidEntityId: " << header.guidEntityId << std::endl; std::cout << "sequenceNumber: " << std::to_string(header.sequenceNumber.to64long()) << std::endl; std::cout << "sourceTimestamp: " << header.sourceTimestamp.to_string() << std::endl; std::cout << "destinationGuidPrefix: " << header.destinationGuidPrefix << std::endl; // Deserialize the topic name from the message payload eprosima::fastrtps::TopicAttributes topic_attr; topic_attr.deserialize(&cdr_des); std::cout << "topic name: " << topic_attr.getTopicName() << std::endl; } ``` 在上述示例中,我们使用了 Fast-RTPS 库中的 `Header_t` 类和 `TopicAttributes` 类来解析消息头部和 topic name。首先,我们将消息头部反序列化为 `Header_t` 类型,并读取其中的各个字段。然后,我们从消息负载中反序列化出 `TopicAttributes` 类型,以获取 topic name。 该示例代码可以在 Fast-RTPS 库提供的各种平台和语言中使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值