glibtojava.c
来自「SRI international 发布的OAA框架软件」· C语言 代码 · 共 71 行
C
71 行
#include <string.h>
#include "glibtojava.h"
GByteArray* glibtojava_writeJavaChar(GByteArray* buf, gchar theChar)
{
// each char is two bytes; the first byte is 0x00, the second is the char
char toWrite[2];
toWrite[0] = '\0';
toWrite[1] = theChar;
buf = g_byte_array_append(buf, (guint8*)toWrite, 2);
return buf;
}
GByteArray* glibtojava_writeJavaChars(GByteArray* buf, size_t bufSize, gchar* theCharString)
{
size_t i;
for(i = 0; i < bufSize; ++i) {
buf = glibtojava_writeJavaChar(buf, theCharString[i]);
}
return buf;
}
GByteArray* glibtojava_writeJavaBytes(GByteArray* buf, size_t bufSize, guint8* bytes)
{
buf = g_byte_array_append(buf, bytes, bufSize);
return buf;
}
GByteArray* glibtojava_writeJavaInt(GByteArray* buf, gint32 theInt)
{
guint8 toWrite[4];
toWrite[0] = (0xff & (theInt >> 24));
toWrite[1] = (0xff & (theInt >> 16));
toWrite[2] = (0xff & (theInt >> 8));
toWrite[3] = (0xff & theInt);
buf = g_byte_array_append(buf, toWrite, 4);
return buf;
}
GByteArray* glibtojava_writeJavaLong(GByteArray* buf, gint64 theLong)
{
guint8 toWrite[8];
toWrite[0] = (0xff & (theLong >> 56));
toWrite[1] = (0xff & (theLong >> 48));
toWrite[2] = (0xff & (theLong >> 40));
toWrite[3] = (0xff & (theLong >> 32));
toWrite[4] = (0xff & (theLong >> 24));
toWrite[5] = (0xff & (theLong >> 16));
toWrite[6] = (0xff & (theLong >> 8));
toWrite[7] = (0xff & theLong);
buf = g_byte_array_append(buf, toWrite, 8);
return buf;
}
GByteArray* glibtojava_writeJavaDouble(GByteArray* buf, gdouble theDouble)
{
guint64 bits;
guint8 toWrite[8];
memcpy(&bits, &theDouble, sizeof(gdouble));
bits = GUINT64_TO_BE(bits);
memcpy(toWrite, &bits, sizeof(guint64));
buf = g_byte_array_append(buf, toWrite, 8);
return buf;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?