PythonStructCS 1.0.1
dotnet add package PythonStructCS --version 1.0.1
NuGet\Install-Package PythonStructCS -Version 1.0.1
<PackageReference Include="PythonStructCS" Version="1.0.1" />
<PackageVersion Include="PythonStructCS" Version="1.0.1" />
<PackageReference Include="PythonStructCS" />
paket add PythonStructCS --version 1.0.1
#r "nuget: PythonStructCS, 1.0.1"
#:package PythonStructCS@1.0.1
#addin nuget:?package=PythonStructCS&version=1.0.1
#tool nuget:?package=PythonStructCS&version=1.0.1
PythonStructCS
A quick port of the essential features of python's struct library to C#
PyStruct.pack(string format, List<object> data) -- returns a byte array (byte[]) with the packed data PyStruct.unpack(string format, byte[] data) -- returns an object List (List<object>) with the unpacked data PyStruct.calcSize(string format) -- returns the byte size of the given format
This library is not meant to be exactly the same as the original library, nor is it even meant to maintain 100% compatibility, its a single "good enough" class for my personal use.
Formats
A format should be a string starting with the endian of the data, followed by specifier characters, prefixed with their count (or size), for example:
<32s4i
is interpreted as little endian (Least significant Byte first), a 32 byte long string (as strings are variable length), and 4 integers (as integers are all 4 bytes)
Endianness
In the original Python struct library there were 5 supported endian characters:
- @ - Native Endian with native sizing
- = - Native Endian with standard sizing
- < - Little Endian with standard sizing
- > - Big Endian with standard sizing
- ! - Network (Big Endian with standard sizing)
only < and > are actually implemented in this library:
@, and = are aliases for <, and ! is an alias for >
this should produce the same results in the vast majority of cases.
Supported format specifiers
the majority of this documentation is copied straight from the previously linked python page
1 byte
- x - Pad Byte
- c - Character (Char)
- b - Signed Byte (SByte) (signed character in python)
- B - Unsigned Byte (Byte) (unsigned character in python)
- ? - Boolean
- e - Half
2 bytes
- h - short (Int16)
- H - unsigned short (UInt16)
4 bytes
- i - Integer (Int32)
- I - Unsigned Integer (UInt32)
- l - Long (Int32)
- L - Unsigned Long (UInt32)
- f - Float (Single)
- d - Double
8 bytes
- q - Long Long (Int64)
- Q - Unsigned Long Long (UInt64)
Variable
- s (String)
(Currently) Unsupported format specifiers
- n ssize_t
- N size_t
- p char[] (Pascal string)
- P void*
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.