doushouxie7064 2015-03-22 22:16
浏览 66
已采纳

使用binary.Read()将字节流解码为结构时,是否可以为每个字段指定大/小尾数?

When decoding bytes, binary.Read() requires you to specify the expected byte order of that operation. binary.Read() also allows you to pass in a struct, but AFAIK, it uses the same byte order to decode the byte stream into every field in the struct.

This is inconvenient when the byte order of encoded integers is in little endian but encoded strings and floats are in big endian.

Is it possible to specify on a per-field basis, which byte-order to use when decoding a stream of bytes into a struct?

  • 写回答

1条回答 默认 最新

  • duanhuan1147 2015-03-22 22:27
    关注

    No, it doesn't look like it.

    The Read method goes through all of the work of deciphering what it needs to read .. then all of the actual read methods have this:

    d.order.....
    

    So basically, they use the ByteOrder you've specified directly .. and make no attempt (via struct tags or anything else) to let you specify it on a per-field basis.

    Unfortunate .. but I smell an opportunity for someone to come along and make a neat package that can be shared with the community :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题