Bug 367864

Summary: Specify Big or Little Endian for multi-byte structure primitives
Product: [Applications] okteta Reporter: Aaron Bishop <erroneous>
Component: Structures ToolAssignee: Alex Richardson <arichardson.kde>
Status: RESOLVED FIXED    
Severity: wishlist CC: kossebau
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:

Description Aaron Bishop 2016-08-26 18:10:26 UTC
version 0.19.3 (not available in drop version list)

I'm trying to write a structure for ANSI X9.37 files which encode the total length of each record as an unsigned 32 bit integer. Normally these are in Motorola byte order or Big Endian. Also, TIFF files can either by II or MM for Intel or Motorola byte order numerics.

Reproducible: Always

Steps to Reproduce:
1. Create a file with the following hex:
00 00 00 50
2. Create a structure with the following ods:
<?xml version="1.0" encoding="UTF-8"?>
<data><struct name="mm_example"><primitive type="uint32-be" /></struct></data>
3. Open the structure and the file.
4. Change the primitive type to "uint32".
5. Open the structure and the file.

Actual Results:  
On first opening with type="uint32-be", you get "uint32-be" does not name a valid primitive type.
With type="uint32", you get the correct structure, but the value is 1342177280

Expected Results:  
With type="uint32", the value should be 80
Comment 1 Alex Richardson 2016-08-26 22:05:55 UTC
You can use <primitive type="uint32" byteOrder="big-endian"\> to get the desired result.

Or do you want to be able to have type aliases so that  type="uint32-be" refers to that? That is not implemented yet and I'm not sure it makes sense. You could achieve that when using javascript structure definitions (https://userbase.kde.org/Okteta/Writing_structure_definitions):

function uint32_be() {
  var ret = uint32()
  ret.byteOrder = "big-endian"
  return ret;
}

function init() {
  var mm_example = struct({foo: uint32_be()}
  return mm_example;
}
Comment 2 Aaron Bishop 2016-08-28 15:48:14 UTC
my apologies, I don't know how I missed the byteOrder documentation. No need for another alias.