Age | Commit message (Collapse) | Author |
|
Add full documentation coverage for the struct module by utilizing large
parts of the Python struct module documentation for the format string
description.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
It is unused and I couldn't find any purpose for it
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
Extend the `unpack()` function to take an optional, second offset parameter
which is useful to skip an initial portion of the input data without having
to encode pad bytes into the format string.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When packing a format such as `!6C*`, the `*` format was not included into
the result buffer due to improper tracking of the function argument offset.
Solve this issue by taking field repetitions into account when tracking
the argument offset while calculating the size of dynamic arguments.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Implement a new `*` format which acts like `s` on unpack but accepts
input records which are shorter than the specified length, e.g. the
following call will yield "abc" while an equivalent "10s" format would
fail:
unpack("2*", "abc") // [ "ab" ]
unpack("10*", "abc") // [ "abc" ]
unpack("10s", "abc") // null
The `*` format is primarily useful to extract the remainder of a variable
length record without having to encode the specific length of the record
directly into the format string.
When packing records, the `*` format takes at most as many bytes as
specified in the format string repeat count. If the input string is
shorter than the given repeat count, only as many bytes as present in
the input string are taken. A bare `*` without any repeat count will take
all bytes from the given input string:
pack("2*", "abc") // "ab"
pack("10*", "abc") // "abc"
pack("*", "abc") // "abc"
pack("10s", "abc") // "abc\0\0\0\0\0\0\0"
Additionally prevent invalid memory accesses when unpacking a buffer
shorter than the length expected by the format string.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Use uc_pack_double() and uc_unpack_double() from core to avoid unnecessary
code duplication.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Fix instances of misspelled "resource".
This commit breaks the exported libucode ABI.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
The "align" pragma was accidentally renamed while refactoring the
original module code.
Fixes: 402f603 ("lib: introduce struct library")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Introduce a new "struct" library which is a port of the Python 3.10 struct
module with a reduced set of API functions. It supports the same format
patterns and conversions while providing the following methods:
struct = require('struct');
buf = struct.pack("fmt", args...);
values = struct.unpack("fmt", buf);
struct_inst = struct.new("fmt");
buf = struct_inst.pack(args...);
values = struct_inst.unpack(buf);
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|