Hi David,

This might be an unusual question because mysql always stores in little
endian for all platforms (if I'm not mistaken).  However, I am receiving
data from several different platforms (custom boards with various
processors) in raw form.  I will have stored as a configuration option
what endianess it is.

So what I need to do is write a procdure, or use a mysql function (if
there is one available) to byte swap the data (for integer types).  I'm
really just hoping someone has done this, or it is implemented as a mysql
function and I just wasn't able to find it.

This seems very strange that you're storing it in raw form. Are you sure that you actually are?

Anyway, swapping between big/little endian is not difficult in C.

The code is all here:

  http://jcole.us/svn/libmygis/mygis.h

e.g.:

#define SWAP(x, y)                   { (x) ^= (y) ^= (x) ^= (y); }

#define MYGIS_SWAP4(pos)       { \
  SWAP(((byte *)(pos))[0], ((byte *)(pos))[3]); \
  SWAP(((byte *)(pos))[1], ((byte *)(pos))[2]); \
}

That's enough to swap 32-bits (4-bytes) of whatever is stored at any pointer address.

I would encourage that you:

a. make sure you really are storing the data raw -- it seems very odd
b. stop storing the data raw... do the swap before storing

Can you give more details about what you're doing?

Regards,

Jeremy

--
Jeremy Cole
MySQL Geek, Yahoo! Inc.
Desk: 408 349 5104

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to