Age | Commit message (Collapse) | Author |
|
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>
|