[sane-devel] Byte ordering

sane-devel at symme.link sane-devel at symme.link
Wed Jun 4 07:36:19 BST 2025


On Tue, Jun 03, 2025 at 10:00:45PM -0700, Ralph Little wrote:
> On Tue, Jun 3, 2025 at 9:54 PM James Ring <sjr at jdns.org> wrote:
> > On Tue, Jun 3, 2025 at 9:46 PM Ralph Little <skelband at gmail.com> wrote:
> >> Someone has asked the question about byte order in multi-byte image data
> >> that we might get from a SANE backend.

Hi, it's me, I had the question.

> >> It is not enough to assume the local machine byte order since we may get
> >> data through the net backend from a remote machine with a different byte
> >> order.

The `net` backend explicitly swaps to local machine byte order:
https://gitlab.com/sane-project/backends/-/blob/master/backend/net.c?ref_type=heads#L2356-2362

So, it does seem like the de facto standard is that backends produce
data in local machine byte order.

(The protocol documentation reinforces this as a standard:

> Argument byte_order specifies the byte-order of the image data. A
> value of 0x1234 indicates little-endian format, a value of 0x4321
> indicates big-endian format. All other values are presently undefined
> and reserved for future enhancements of this protocol. The intent is
> that a network server sends data in its own byte-order and the client
> is responsible for adjusting the byte-order, if necessary. This
> approach causes no unnecessary overheads in the case where the server
> and client byte-order match and puts the extra burden on the client
> side when there is a byte-order mismatch. Putting the burden on the
> client-side improves the scalability properties of this protocol.

)

- Tricia



More information about the sane-devel mailing list