简体   繁体   English

将大字节数组解码为文本

[英]Decoding large byte array to text

I have a custom protocol that I use for inter-process communication. 我有一个用于进程间通信的自定义协议。 There are approx. 有大约。 400-500 messages all with custom payloads. 400-500条消息均带有自定义有效负载。 The messages all have a unique message id (word), but that's it. 消息都有唯一的消息ID(单词),仅此而已。 A c struct defines each message. 结构定义每个消息。

Almost all messages have custom enums for one or more fields in the struct. 几乎所有消息都具有针对该结构中一个或多个字段的自定义枚举。

I get message logs that have thousands of these messages and I want to write a decoder that will run relatively fast and not be a complete pain to maintain. 我收到的消息日志中包含成千上万条这样的消息,并且我想编写一个解码器,该解码器的运行速度相对较快,并且很难维护。

I looked at writing a custom app and storing the decode structure in an ms access db or something. 我看过编写一个自定义应用程序并将解码结构存储在ms access db或其他内容中的情况。 This was very slow and was limited by number of simultaneous decodes. 这非常慢,并且受同时解码次数的限制。 I also looked at xml, but again doing a translation was slow in my small test. 我也查看了xml,但是在我的小测试中,再次进行翻译很慢。

I would love to use something like a wireshark disector, but these aren't network packets... Just a big byte array. 我很想使用诸如Wireshark Disector的东西,但是这些不是网络数据包……只是一个大字节数组。

Any thoughts/recommendations would be very appreciated. 任何想法/建议将不胜感激。

If your intent is to look for statistics, then a faster way might just be to add numeric stats in the IPC layer itself. 如果您要查找统计信息,则更快的方法可能只是在IPC层本身中添加数字统计信息。 So, when the sender sends an IPC packet of type X, it increases a counter stats_sent_X and a similar book-keeping for the receive side. 因此,当发送方发送类型为X的IPC数据包时,它会增加计数器stats_sent_X并为接收方增加类似的簿记功能。

On the other hand, if you want to go through the contents of a log, then a simpler approach would be to simply read the log file, split it into tokens, identify the tokens that pertain to the IPC enum-value and then read it. 另一方面,如果您要查看日志的内容,则一种更简单的方法是简单地读取日志文件,将其拆分为令牌,识别与IPC枚举值有关的令牌,然后再读取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM