23 #define CHECK_BUF(SIZE) \
24 if (buf->start == 0 || buf->end == 0 || buf->cur == 0) { \
25 buf->error = DB_ERR_INVALID_BUFFER; \
28 if (buf->start > buf->cur || buf->cur > buf->end ) { \
29 buf->error = DB_ERR_INVALID_BUFFER; \
32 if ((buf->cur + ( SIZE )) > buf->end) { \
33 buf->error = DB_ERR_END_OF_BUFFER; \
43 memcpy(buf->
cur, buffer, len);
51 memcpy(buffer, buf->
cur, len);
70 #define W_BYTE_UNSAFE(BUF, BYTE) \
71 *(BUF)->cur++ = ( 0xFF & ( BYTE ) )
79 if (max > 0 && len > max) len = max;
88 for (i = 0; i < len; ++i, ++s)
91 if (c > 0 && c <= 0x7f)
93 W_BYTE_UNSAFE(buf, c);
96 W_BYTE_UNSAFE(buf,
'@');
109 if (len > max - 1) len = max - 1;
116 if (c == 0 || c > 0x7f) {
166 buf->
cur[0] = u >> 8;
181 buf->
cur += skipSize;
189 *u = ( buf->
cur[0] << 8 ) | ( buf->
cur[1] );
204 buf->
cur[0] = u >> 24;
205 buf->
cur[1] = u >> 16;
206 buf->
cur[2] = u >> 8;
222 *u = ( buf->
cur[0] << 24 ) |
223 ( buf->
cur[1] << 16 ) |
224 ( buf->
cur[2] << 8 ) |
233 *i = ( ((uint64_t)buf->
cur[0]) << 56 ) |
234 ( ((uint64_t) buf->
cur[1]) << 48 ) |
235 ( ((uint64_t) buf->
cur[2]) << 40 ) |
236 ( ((uint64_t) buf->
cur[3]) << 32 ) |
237 ( ((uint64_t) buf->
cur[4]) << 24 ) |
238 ( ((uint64_t) buf->
cur[5]) << 16 ) |
239 ( ((uint64_t) buf->
cur[6]) << 8 ) |
240 ( ((uint64_t) buf->
cur[7]) );
248 buf->
cur[0] = i >> 56;
249 buf->
cur[1] = i >> 48;
250 buf->
cur[2] = i >> 40;
251 buf->
cur[3] = i >> 32;
252 buf->
cur[4] = i >> 24;
253 buf->
cur[5] = i >> 16;
254 buf->
cur[6] = i >> 8;
272 buf->
cur[0] = i >> 56;
273 buf->
cur[1] = i >> 48;
274 buf->
cur[2] = i >> 40;
275 buf->
cur[3] = i >> 32;
276 buf->
cur[4] = i >> 24;
277 buf->
cur[5] = i >> 16;
278 buf->
cur[6] = i >> 8;
287 *i = ( ((int64_t)buf->
cur[0]) << 56 ) |
288 ( ((int64_t) buf->
cur[1]) << 48 ) |
289 ( ((int64_t) buf->
cur[2]) << 40 ) |
290 ( ((int64_t) buf->
cur[3]) << 32 ) |
291 ( ((int64_t) buf->
cur[4]) << 24 ) |
292 ( ((int64_t) buf->
cur[5]) << 16 ) |
293 ( ((int64_t) buf->
cur[6]) << 8 ) |
294 ( ((int64_t) buf->
cur[7]) );
322 uint8_t * b = (uint8_t *)&flt;
324 *(buf->
cur++) = b[0];
325 *(buf->
cur++) = b[1];
326 *(buf->
cur++) = b[2];
327 *(buf->
cur++) = b[3];
337 #pragma GCC diagnostic warning "-Wstrict-aliasing"
bool dbReadF64(DataBuffer *buf, f64_t *flt)
Reads an 64-bit floating point.
bool dbReadU8(DataBuffer *buf, uint8_t *byte)
Reads an unsigned byte.
bool dbReadString(DataBuffer *buf, char *s, int size)
Reads a string from the stream.
bool dbSkip(DataBuffer *buf, size_t skipSize)
Skips a number of bytes in the buffer.
#define DB_ERR_NOT_SUPPORTED
De type is not supported.
bool dbWriteI16(DataBuffer *buf, int16_t i)
Writes a short (16 bits signed) integer.
bool dbReadU16(DataBuffer *buf, uint16_t *u)
Reads a unsigned short (16 bits unsigned) integer.
bool dbWriteI32(DataBuffer *buf, int32_t i)
Writes an 32 bits signed integer.
bool dbWriteI8(DataBuffer *buf, int8_t byte)
Writes a byte.
bool dbReadF32(DataBuffer *buf, f32_t *flt)
Reads an 32-bit floating point.
Defines a DataBuffer structure.
bool dbReadI64(DataBuffer *buf, int64_t *i)
Reads an 64 bits signed integer.
bool dbWriteF64(DataBuffer *buf, f64_t flt)
Writes a 64-bit floating point.
DataBuffer reads and writes data into a buffer in the same format as defined in the data Java DataOut...
uint32_t f32_t
32 bit representation for float.
bool dbWriteF32(DataBuffer *buf, f32_t flt)
Writes a 32-bit floating point.
uint64_t f64_t
642 bit representation for float
bool dbWriteU8(DataBuffer *buf, uint8_t byte)
Writes a unsigned byte.
bool dbReadI8(DataBuffer *buf, int8_t *byte)
Reads an byte.
bool dbWriteU64(DataBuffer *buf, uint64_t i)
Writes an 64 bits unsigned integer.
bool dbReadU32(DataBuffer *buf, uint32_t *u)
Reads an 32 bits unsigned integer.
bool dbWrite(DataBuffer *buf, uint8_t *buffer, int len)
Writes the given buffer with the specified length.
bool dbWriteI64(DataBuffer *buf, int64_t i)
Writes an 64 bits signed integer.
bool dbWriteString(DataBuffer *buf, const char *s, int max)
Writes a String as 'sort of' UTF-8 encoding, as defined in the Java DataOuput and DataInput writeUTF ...
bool dbReadI32(DataBuffer *buf, int32_t *i)
Reads an 32 bits signed integer.
bool dbRead(DataBuffer *buf, uint8_t *buffer, int len)
Reads into given buffer with the specified length.
bool dbReadI16(DataBuffer *buf, int16_t *i)
Reads a short (16 bits signed) integer.
uint8_t * cur
Current Pointer.
bool dbWriteU32(DataBuffer *buf, uint32_t u)
Writes an 32 bits unsigned integer.
bool dbWriteU16(DataBuffer *buf, uint16_t u)
Writes a unsigned short (16 bits unsigned) integer.
bool dbReadU64(DataBuffer *buf, uint64_t *i)
Reads an 64 bits unsigned integer.