Re: Binary module - number endianness

The original proposal for number (un-)packing permitted endianess to be 
controlled with an additional boolean parameter which enabled big-endian 
operation, e.g.:

    bin:unpack-unsigned-integer($in as xs:base64Binary, $offset as
    xs:integer, $length as xs:integer)
         as xs:integer

defaults to little-endian (which still needs discussion), and

    bin:unpack-unsigned-integer($in as xs:base64Binary, $offset as
    xs:integer, $length as xs:integer,
         $big as xs:boolean)  as xs:integer

converts in a big-endian manner if $big is true().

However, this could easily lead to programmer confusion - "I can't 
remember which way it goes", "what does false() mean?" etc.

It's been suggested that a change of signature to:

    bin:unpack-unsigned-integer($in as xs:base64Binary, $offset as
    xs:integer, $length as xs:integer,
         $endian as xs:string)  as xs:integer

would be much clearer, and I suggest the following supported values:

  * any of 'most-significant-first', 'big-endian' or 'BE' direct
    most-significant octet first behaviour.
  * any of 'least-significant-first', 'little-endian' or 'LE' direct
    least-significant octet first behaviour.

Any other string values lead to error.

As I suggested in the previous message, currying can make things simpler:

    <xsl:variable name="bin:unpack-uint"
    select="bin:unpack-unsigned-integer(?,?,?,'most-significant-first')"/>
    ...
    $bin:unpack-uint($tiff,/$loc/,/$len/)......

Thoughts?


-- 
*John Lumley* MA PhD CEng FIEE
john@saxonica.com <mailto:john@saxonica.com>
on behalf of Saxonica Ltd

Received on Friday, 19 July 2013 10:04:26 UTC