C# equivalent of python's struct.pack

前端 未结 1 1649
予麋鹿
予麋鹿 2021-01-14 17:01

Is there a library for C# that allows similar functionality to python\'s struct from the standard library?

One can emulate the struct library quite clos

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 17:49

    The closest equivalent would probably be to use BinaryWriter writing into a MemoryStream, or BitConverter for a one-off conversion of a single value into a byte array.

    If you want to control the endianness of that, you can use my EndianBinaryWriter/EndianBitConverter from MiscUtil. One extra feature of my EndianBitConverter is that you can convert into a specific portion of an existing array, which would help you if you wanted to port struct.pack yourself.

    0 讨论(0)
提交回复
热议问题