00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <string.h>
00022 #include "glibtojava.h"
00023
00024 GByteArray* glibtojava_writeJavaChar(GByteArray* buf, gchar theChar)
00025 {
00026
00027 char toWrite[2];
00028 toWrite[0] = '\0';
00029 toWrite[1] = theChar;
00030 buf = g_byte_array_append(buf, (guint8*)toWrite, 2);
00031 return buf;
00032 }
00033
00034 GByteArray* glibtojava_writeJavaChars(GByteArray* buf, size_t bufSize, gchar* theCharString)
00035 {
00036 size_t i;
00037
00038 for(i = 0; i < bufSize; ++i) {
00039 buf = glibtojava_writeJavaChar(buf, theCharString[i]);
00040 }
00041 return buf;
00042 }
00043
00044 GByteArray* glibtojava_writeJavaBytes(GByteArray* buf, size_t bufSize, guint8* bytes)
00045 {
00046 buf = g_byte_array_append(buf, bytes, bufSize);
00047 return buf;
00048 }
00049
00050 GByteArray* glibtojava_writeJavaInt(GByteArray* buf, gint32 theInt)
00051 {
00052 guint8 toWrite[4];
00053
00054 toWrite[0] = (0xff & (theInt >> 24));
00055 toWrite[1] = (0xff & (theInt >> 16));
00056 toWrite[2] = (0xff & (theInt >> 8));
00057 toWrite[3] = (0xff & theInt);
00058 buf = g_byte_array_append(buf, toWrite, 4);
00059 return buf;
00060 }
00061
00062 GByteArray* glibtojava_writeJavaLong(GByteArray* buf, gint64 theLong)
00063 {
00064 guint8 toWrite[8];
00065
00066 toWrite[0] = (0xff & (theLong >> 56));
00067 toWrite[1] = (0xff & (theLong >> 48));
00068 toWrite[2] = (0xff & (theLong >> 40));
00069 toWrite[3] = (0xff & (theLong >> 32));
00070 toWrite[4] = (0xff & (theLong >> 24));
00071 toWrite[5] = (0xff & (theLong >> 16));
00072 toWrite[6] = (0xff & (theLong >> 8));
00073 toWrite[7] = (0xff & theLong);
00074
00075 buf = g_byte_array_append(buf, toWrite, 8);
00076 return buf;
00077 }
00078
00079 GByteArray* glibtojava_writeJavaDouble(GByteArray* buf, gdouble theDouble)
00080 {
00081 guint64 bits;
00082 guint8 toWrite[8];
00083
00084 memcpy(&bits, &theDouble, sizeof(gdouble));
00085 bits = GUINT64_TO_BE(bits);
00086 memcpy(toWrite, &bits, sizeof(guint64));
00087 buf = g_byte_array_append(buf, toWrite, 8);
00088 return buf;
00089 }
00090