我如何在变量中表示数据包(二进制流)(c++)
你好,我正在做一个个人项目 对于传输解析器。
我希望能够用二进制数表示收到的数据包,然后能够设置特定的位。 我对如何做第二部分有一个很好的想法,但我真的卡在了开始的地方 我得到了使用 unsigned char 的建议,但是我真的可以在该变量中表示完整的数据包吗?
谢谢
hi i'm working on a personal project
for a transport parser.
i want to be able to represent a recived packet in binary number and afterwards be able to set specific bits.
I've got a pretty good idea how to do the second part but i'm really stuck at the beginning
ive got an advice to use unsigned char for that but can i really represent a full packet in that variable.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个
unsigned char array
可能就是您所需要的:您可以在此结构中存储您想要的任何内容,并以您喜欢的任何方式访问它。您也可以将此容器放在更大的容器中:更大的容器将具有指向每层的开头和结尾的指针。结束等
an
unsigned char array
is probably what you need: you can store whatever you want in this structure and access it in whatever means pleases you.You could have this container in a bigger container too: the bigger container would have pointers to the each layer's beginning & end etc.
我可能会有一个简单的类(无论如何都很简单):
这只是开始,毫无疑问它会变得更加复杂,具体取决于您使用它的用途。您可能会考虑重载数组运算符,但这可能超出了“初学者水平”,现在最好忽略。
I'd probably have a simple class (simple to begin with anyway):
That's just to start, no doubt it would get more complex depending what you use it for. You might consider overloading the array operator but that's probably outside "beginner level" and maybe best ignored right now.