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 :)

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!