strings and endianness

Jonathan M Davis jmdavisProg at gmx.com
Wed Jan 18 13:52:25 PST 2012


On Wednesday, January 18, 2012 21:42:51 Johannes Pfau wrote:
> Jonathan M Davis wrote:
> Section 4.1.2. indeed says that it uses big endian. However, I should still
> be able to use a ubyte[16] representation and just make sure that those
> bytes are equal to the big endian representation. Thinking about this: If I
> construct a ubyte[16] from a uuid string byte by byte, the resulting
> ubyte[16] should already be the big-endian representation?

Yes.

> > How that conversion is done though, depends on what each of the
> > values represent. If they're 4 uints, then you'd need to sway each set
> > of
> > 4 bytes. If they're 8 ushorts, then you need to swap each set of 2
> > bytes.
> > 
> > However, I belive that RFC 4122 is laid out like this
> > 
> > uint
> > ushort
> > ushort
> > ubyte
> > ubyte
> > ubyte
> > ubyte
> > ubyte
> > ubyte
> > ubyte
> > ubyte
> 
> Right, I totally forgot that, as boost just treats an UUID as a ubyte[16].
> But as long as I keep the data as ubyte[16] equal to the above layout in big
> endian, that should work as well.

Yes. I believe that the implementation (in C++) that we use where I work has a 
union between the various layouts. ubyte[16] should just be a mapping of the 
bytes such that you could cast each piece to the appropriate type and have it 
work (once you've dealt with endianness).

> If you want to comment on the code, it's here:
> https://github.com/jpf91/phobos/blob/std.uuid/std/uuid.d

I'll try and take a look at it at some point soon. Worst case, I can look at 
it when you try and get it into Phobos, which I assume that you're trying to 
do.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list