If I do it in C I need to do a user-defined function correct?

Anyway, I am infact storing the data raw.  Unfortunately byte swapping
before is not an option because I am getting a stream of raw data and
storing it in a blob field.  Then based on some configuration, I pull
parts of the data out of the BLOB, and do conversions on it.  So it a
specific element that I am looking for is defined as and Integer, I query
the BLOB data, do a substring (based on some offset and length) then
perform some conversion (Floats, Doubles, Signed, Unsigned).

You would think, hey why don't you break the data out and store it in the
correct form to make your life easier?  Well, I have to preserve the data
in Raw form, and also, the definitions of the data change (base on some
other engineers decisions).  So it isn't practical nor desirable to
convert the data before I put it in the database.

What I am really looking for (I know byte swapping in C is easy) is a
procedure or a Mysql function that does this.  If I do a UDF then I have
to compile it for several platforms, because this is also supposed to be
very portable.  If it was completely up to me, it wouldn't be this way,
but alas it is not.

David Godsey

> 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
>


Accomplishing the impossible means only that the boss will add it to your
regular duties.

David Godsey


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

Reply via email to