简体   繁体   English

最佳实践:什么是处理字节协议的最佳方法

[英]Best practices: What's the best way to treat byte protocol

I have a serial communication with a device that has its own protocol, in other words, it has some byte arrays (frames) with some meaning. 我与具有自己协议的设备进行串行通信,换句话说,它具有某些含义的字节数组(帧)。 So, I have been treating it with a lot of default frames in a map to send data to the device and a kind of state machine, a big switch-case block to receive data from the device. 因此,我一直在使用映射中的许多默认帧来处理它,以将数据发送到设备,以及一种状态机,这是一个很大的开关盒块,用于从设备接收数据。

I know this question is subjective but I really would like to receive best practices to implement this relationship. 我知道这个问题是主观的,但是我真的很想获得实现这种关系的最佳实践。 Maybe there are design patterns to do the same. 也许有设计模式可以做到相同。

It all depends on how complex it is. 这完全取决于它的复杂程度。 If it's something as hairy as 3270 you certainly need a state machine. 如果它像3270一样繁琐,那么您肯定需要一个状态机。 If it's a simple byte protocol you don't need anything more complex than a DataInputStream. 如果这是一个简单的字节协议,那么您不需要比DataInputStream.更复杂的东西DataInputStream. There's not enough information here to say which. 这里没有足够的信息说。

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

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