<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">packing, order, alignment. <div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Divided by a common language</div><div><br></div><div>Dragiša Durić</div><div><a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a></div><div><br></div></div></span><br class="Apple-interchange-newline"></span><br class="Apple-interchange-newline">
</div>
<br><div><div>On Aug 23, 2012, at 3:30 PM, Tony Hosking wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>PACKED?<br><br>Sent from my iPad<br><br>On Aug 23, 2012, at 3:24 AM, Dragiša Durić <<a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a>> wrote:<br><br><blockquote type="cite">I know this will probably be very dense subject, but… What about:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> TSPacketHeader = <* ENDIAN = BIG*>RECORD<br></blockquote><blockquote type="cite">   sync: BITS 8 FOR [16_0..16_ff];   (* Always 0x47 *)<br></blockquote><blockquote type="cite">   tErrInd,                      (* Transport Error Indicator *)<br></blockquote><blockquote type="cite">   pusi: BITS 1 FOR BOOLEAN;     (* Payload Unit Start Indicator *)<br></blockquote><blockquote type="cite">   transPrio: BITS 1 FOR [0..1];<br></blockquote><blockquote type="cite">   pid: BITS 13 FOR PID;<br></blockquote><blockquote type="cite">   transScramControl: BITS 2 FOR [0..3]; (* 00 means no scrambling *)<br></blockquote><blockquote type="cite">   afc: BITS 2 FOR [0..3]; (* 01 - no adaptation field, payload only *) <br></blockquote><blockquote type="cite">   cc: BITS 4 FOR Nibble;<br></blockquote><blockquote type="cite"> END;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Meaning: bit data is packed from left to right, and all multi-byte data is packed MSB first.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Right now I am doing this, based on knowledge of my platform (little endian, x86_64), like this:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> TSPacketHeader = RECORD<br></blockquote><blockquote type="cite">   sync: BITS 8 FOR [16_0..16_ff];   (* Always 0x47 *)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">   pidHi: BITS 5 FOR [16_00..16_1f];<br></blockquote><blockquote type="cite">   transPrio: BITS 1 FOR [0..1];<br></blockquote><blockquote type="cite">   pusi,<br></blockquote><blockquote type="cite">   tErrInd: BITS 1 FOR BOOLEAN;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">   pidLo: BITS 8 FOR [16_00..16_ff];<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">   cc: BITS 4 FOR Nibble;<br></blockquote><blockquote type="cite">   afc: BITS 2 FOR [0..3]; (* 01 - no adaptation field, payload only *) <br></blockquote><blockquote type="cite">   transScramControl: BITS 2 FOR [0..3]; (* 00 means no scrambling *)<br></blockquote><blockquote type="cite"> END;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">And please don't tell me "write in C", because then I will just "offload" this problem to C preprocessor and still only hope for the best. Modula-3 is provably very adept to systems programming and I hope it can be more so.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Thanks in advance..<br></blockquote><blockquote type="cite">--<br></blockquote><blockquote type="cite">Divided by a common language<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Dragiša Durić<br></blockquote><blockquote type="cite"><a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote></div></blockquote></div><br></div></body></html>