[M3devel] packing problem… how exactly does modula-3 pack data into records?? … "solved"

Dragiša Durić dragisha at m3w.org
Fri Jan 20 13:02:51 CET 2012


TYPE
  (* This is how it should be written... If only cm3 packed left-to-right-until-spent. todo for me.

  TSPacketHeader = RECORD
    sync: BITS 8 FOR [16_0..16_ff];   (* Always 0x47 *)
    tErrInd,                      (* Transport Error Indicator *)
    pusi: BITS 1 FOR BOOLEAN;     (* Payload Unit Start Indicator *)
    transPrio: BITS 1 FOR [0..1];
    pid: BITS 13 FOR PID;
    transScramControl: BITS 2 FOR [0..3]; (* 00 means no scrambling *)
    afc: BITS 2 FOR [0..3]; (* 01 - no adaptation field, payload only *)
    cc: BITS 4 FOR Nibble;
  END;
  *)

  TSPacketHeader = RECORD
    sync: BITS 8 FOR [16_0..16_ff];   (* Always 0x47 *)

    pidHi: BITS 5 FOR [16_00..16_1f];
    transPrio: BITS 1 FOR [0..1];
    pusi,
    tErrInd: BITS 1 FOR BOOLEAN;

    pidLo: BITS 8 FOR [16_00..16_ff];

    cc: BITS 4 FOR Nibble;
    afc: BITS 2 FOR [0..3]; (* 01 - no adaptation field, payload only *)
    transScramControl: BITS 2 FOR [0..3]; (* 00 means no scrambling *)
  END;

With additional methods for getPid() and setPid(), this works as expected.

But I _really_ think we should have continuous bit fields in cases where it spans byte boundary and combined with how other pieces of this work now - it means we need left to right packing of bit strings into bytes, not right to left as it is done now on my x86_64 box. This is probably some endianess relict, but I also think endiannes has nothing to do with us once we decide to go bit strings.

I don't see a big problem to implement this in such a way right now. Especially since at this moment nobody is having any expectations from implementation (except me O:) ) - we won't break anything.

TIA,
dd

On Jan 20, 2012, at 8:29 AM, Dragiša Durić wrote:

> I am not using packing to interface with C or to be compact.
> 
> My code is directly producing packets for some network protocol. No C in sight :). 
> 
> And, as probably all those pesky :) network protocols around… Order of bytes and (expected) order of bits is - left to right.
> 
> I really do not understand why this is something hard to accept as standard (or at least cm3) way for  bit packing?




More information about the M3devel mailing list