tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: A Library for Converting Data to and from C Structs for Lua
Hi James,
On Sat, Nov 23, 2013 at 1:22 AM, James K. Lowden
<jklowden%schemamania.org@localhost> wrote:
> On Mon, 18 Nov 2013 09:07:52 +0100
> Marc Balmer <marc%msys.ch@localhost> wrote:
>
>> After discussion we lneto@ and others we realised that there are
>> several such libraries around, and that I as well as lneto@ wrote
>> one. SO we decided to merge our works and have a library that allows
>> to encode/decode structured binary data in one call (my work) and that
>> allows to access individual fields as well (lneto@'s work).
>
> How do you deal with the usual issues of alignment and endianism?
I'm working on this approach:
d = data.new{0xF0, 0xFF, 0x00} -- creates a new data object with 3 bytes.
d:layout{
x = { __offset = 0, __length = 3 },
y = { __offset = 8, __length = 16, __endian = 'net' },
z = { __offset = 0, __step = 9 }
}
d.x -- returns the 3 most significant bits from d (that is, 7)
d.y -- returns 16 bits counting from bit-8 most significant.
-- in this case, these 2 bytes are converted using ntohs(3),
that is 0xFF00.
d.z[1] -- returns the 9 most significant bits from d (that is, 0x1E1).
> (BTW, I'm curious what unstructured binary data might be.)
I don't think that Marc meant 'structured binary data' in opposition
to 'unstructured binary data'. We both are working with structured
data. The main difference is that I'm working on random accessing and
he is working on encoding/decoding data at once (e.g., x, y, z =
d:extract(fmt)).
Regards,
--
Lourival Vieira Neto
Home |
Main Index |
Thread Index |
Old Index