[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Byte swapping and bindat
From: |
Po Lu |
Subject: |
Re: Byte swapping and bindat |
Date: |
Sat, 11 Jun 2022 08:54:53 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux) |
Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
>> Is there a way to specify a bindat type with fields whose endianess
>> depends on an external parameter (or another field of the type?)
>
> I'm so glad you asked:
>
> (let* ((threshold 32)
> (type (bindat-type (kind uint 8)
> (length sint 32 (> kind threshold)))))
> (list (bindat-unpack type "\x10\x00\x00\x01\x01")
> (bindat-unpack type "\x80\x00\x00\x01\x01")))
> =>
> (((kind . 16) (length . 257))
> ((kind . 128) (length . 16842752)))
>
> That's one of the benefits of the new Bindat :-)
Thanks. Where is that documented?
(And what about an unsigned integer? Is it just `uint', which according
to the doc is a big-endian number?)