[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.pack with bit resolution
- From: Sean Conner <sean@...>
- Date: Sun, 20 Oct 2019 03:59:44 -0400
It was thus said that the Great bil til once stated:
> One further offer, concerning the “n” specifier.
[ ... snip of about 100 lines of specification ... ]
At this point, it would be wise to actually look for an explicit module to
do the packing that you want. One such example would be CBOR, as it's a
documented standard (RFC-7049) and there are a lot of implementations for
many languages. It defines, I think, a nice balance between dense packing
and efficient encoding/decoding.
Seriously, please! Look into that [1] and stop trying to modify
string.pack()/string.unpack(). Even *IF* (and that's a big "if") the Lua
team decide to implement your ideas, they won't be in the Lua 5.4 release,
so you are looking at several *YEARS* at the minimum.
> (As I told already in my blogs before, I see no application why to support
> alignment larger than 1 Byte … and I think this alignment support bloats the
> C code quite a bit …
And your 100+ line wish list won't bloat the C code?
But more seriously, not every machine in existance is x86; there ARE
architetures out there with alignment restrictions STILL in use today (I use
them at work). And they can run Lua (which I also do at work). So
alignment is STILL important.
> but if there are good reasons to support alignment,
> then please correct me, then no problem to re-install the option ![n]’ …
> just I really do NOT understand what you mean with the option ‘Xop’ in your
> existing format table… .)
It's for alignment purposes. An example, if I want to pack the following
C structure [2]:
struct foo
{
char c;
int i;
};
with the following packing string:
"=! c1 XI I" -- [3]
The "XI" part says advance to the next alignment spot and not return said
padding.
-spc
[1] Here's one for Lua:
https://github.com/spc476/CBOR
And it supports half floats, which seem to be important to you.
Heck, here's a whole list of implementations for various languages:
http://cbor.io/impls.html
[2] The rules for C structures is that the order is kept, but padding
bytes can be added.
[3] I know! The size of the integer is unspecified---it's an example.
Deal with it!