C # python equivalent struct.pack

Is there a library for C # that allows you to use similar functionality for python structfrom the standard nofollow noreferrer ">

You can emulate a structure library quite closely with real aligned structures. But I have not yet found a way to directly control endianess in C # structs (C # structures seem to be more focused on COM interoperability and less on general-purpose binary packaging).

+3
source share
1 answer

The closest equivalent is likely to be a BinaryWriterwrite to MemoryStreamor BitConverterfor a one-time conversion of a single value to an array of bytes.

If you want to control this, you can use my EndianBinaryWriter / EndianBitConverter from MiscUtil . Another feature of mine EndianBitConverteris that you can convert to a specific part of an existing array, which will help you if you want to port struct.packyourself.

+6
source

Source: https://habr.com/ru/post/1724262/


All Articles