本文整理汇总了C++中write_int32函数的典型用法代码示例。如果您正苦于以下问题:C++ write_int32函数的具体用法?C++ write_int32怎么用?C++ write_int32使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_int32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jl_serialize_module
static void jl_serialize_module(ios_t *s, jl_module_t *m)
{
// set on every startup; don't save
jl_sym_t *jhsym = jl_symbol("JULIA_HOME");
writetag(s, jl_module_type);
jl_serialize_value(s, m->name);
jl_serialize_value(s, m->parent);
size_t i;
void **table = m->bindings.table;
for(i=1; i < m->bindings.size; i+=2) {
if (table[i] != HT_NOTFOUND &&
!(table[i-1] == jhsym && m == jl_core_module)) {
jl_binding_t *b = (jl_binding_t*)table[i];
if (!(b->owner != m && m == jl_main_module)) {
jl_serialize_value(s, b->name);
jl_serialize_value(s, b->value);
jl_serialize_value(s, b->type);
jl_serialize_value(s, b->owner);
write_int8(s, (b->constp<<2) | (b->exportp<<1) | (b->imported));
}
}
}
jl_serialize_value(s, NULL);
if (m == jl_main_module) {
write_int32(s, 1);
jl_serialize_value(s, (jl_value_t*)jl_core_module);
}
else {
write_int32(s, m->usings.len);
for(i=0; i < m->usings.len; i++) {
jl_serialize_value(s, (jl_value_t*)m->usings.items[i]);
}
}
}
示例2: process_test_message
int32_t process_test_message(struct mile_message_header* msg_head,
struct data_buffer* rbuf, struct data_buffer* sbuf) {
int32_t result_code = MILE_RETURN_SUCCESS;
MEM_POOL_PTR mem_pool;
switch (msg_head->message_type) {
case MT_TEST_REQ_ECHO: // echo message for testing.
{
mem_pool = mem_pool_init(MB_SIZE);
const char *str = read_cstring(rbuf, mem_pool);
log_debug("get echo message [%s]", str);
write_int32(0, sbuf);
write_int8(msg_head->version_major, sbuf);
write_int8(msg_head->version_minor, sbuf);
write_int16(MT_TEST_RES_ECHO, sbuf);
write_int32(msg_head->message_id, sbuf);
write_int32(strlen(str), sbuf);
write_bytes((uint8_t *) str, strlen(str), sbuf);
fill_int32(sbuf->data_len, sbuf, 0);
result_code = MILE_RETURN_SUCCESS;
mem_pool_destroy(mem_pool);
}
break;
default:
result_code = -1;
break;
}
return result_code;
}
示例3: gen_stat_packet
struct data_buffer* gen_stat_packet(char* cmd,uint8_t* type,MEM_POOL* mem_pool)
{
char* table_name = NULL;
char* token = NULL;
uint32_t tblen;
if((table_name = strtok(NULL," ")) == NULL)
return NULL;
tblen = strlen(table_name);
if((token = strtok(NULL," ")) == NULL)
return NULL;
*type = atoi(token);
struct data_buffer *dbuf = init_data_buffer();
size_t data_len = tblen + 5 * sizeof(uint8_t) + MESSAGE_HEAD_LEN + 2*sizeof(uint32_t);
databuf_resize(dbuf, data_len);
//写入数据长度
write_int32(data_len,dbuf);
write_int8(1, dbuf);
write_int8(1, dbuf);
write_int16(MT_CD_STAT, dbuf);
write_int32(0, dbuf);
//timeout
write_int32(0, dbuf);
//拼接协议包
write_int32(tblen,dbuf);
write_bytes((uint8_t*)table_name,tblen,dbuf);
write_int8(*type,dbuf);
return dbuf;
}
示例4: op_kill
/*
1 string cursor_id
return string package
*/
static int
op_kill(lua_State *L) {
size_t cursor_len = 0;
const char * cursor_id = luaL_tolstring(L, 1, &cursor_len);
if (cursor_len != 8) {
return luaL_error(L, "Invalid cursor id");
}
struct buffer buf;
buffer_create(&buf);
int len = reserve_length(&buf);
write_int32(&buf, 0);
write_int32(&buf, 0);
write_int32(&buf, OP_KILL_CURSORS);
write_int32(&buf, 0);
write_int32(&buf, 1);
write_bytes(&buf, cursor_id, 8);
write_length(&buf, buf.size, len);
lua_pushlstring(L, (const char *)buf.ptr, buf.size);
buffer_destroy(&buf);
return 1;
}
示例5: gen_set_load_threshold_packet
struct data_buffer* gen_set_load_threshold_packet(char* cmd,MEM_POOL* mem_pool)
{
struct data_buffer *dbuf = init_data_buffer();
size_t data_len = MESSAGE_HEAD_LEN + 2*sizeof(uint32_t) + sizeof(double);
databuf_resize(dbuf, data_len);
//写入数据长度
write_int32(data_len,dbuf);
write_int8(1, dbuf);
write_int8(1, dbuf);
write_int16(MT_CD_EXE_SET_LOAD_THRESHOLD, dbuf);
write_int32(0, dbuf);
//timeout
write_int32(0, dbuf);
char *value_str = strtok(NULL, " ");
if (!value_str)
return NULL;
double value = atof(value_str);
write_bytes((uint8_t *)&value, sizeof(value), dbuf);
return dbuf;
}
示例6: op_delete
/*
1 string collection
2 integer single remove
3 document selector
return string package
*/
static int
op_delete(lua_State *L) {
document selector = lua_touserdata(L,3);
if (selector == NULL) {
luaL_error(L, "Invalid param");
}
size_t sz = 0;
const char * name = luaL_checklstring(L,1,&sz);
luaL_Buffer b;
luaL_buffinit(L,&b);
struct buffer buf;
buffer_create(&buf);
int len = reserve_length(&buf);
write_int32(&buf, 0);
write_int32(&buf, 0);
write_int32(&buf, OP_DELETE);
write_int32(&buf, 0);
write_string(&buf, name, sz);
write_int32(&buf, lua_tointeger(L,2));
int32_t selector_len = get_length(selector);
int total = buf.size + selector_len;
write_length(&buf, total, len);
luaL_addlstring(&b, (const char *)buf.ptr, buf.size);
buffer_destroy(&buf);
luaL_addlstring(&b, (const char *)selector, selector_len);
luaL_pushresult(&b);
return 1;
}
示例7: cursor_id
/*
1 integer id
2 string collection
3 integer number
4 cursor_id (8 bytes string/ 64bit)
return string package
*/
static int
op_get_more(lua_State *L) {
int id = luaL_checkinteger(L, 1);
size_t sz = 0;
const char * name = luaL_checklstring(L,2,&sz);
int number = luaL_checkinteger(L, 3);
size_t cursor_len = 0;
const char * cursor_id = luaL_tolstring(L, 4, &cursor_len);
if (cursor_len != 8) {
return luaL_error(L, "Invalid cursor id");
}
struct buffer buf;
buffer_create(&buf);
int len = reserve_length(&buf);
write_int32(&buf, id);
write_int32(&buf, 0);
write_int32(&buf, OP_GET_MORE);
write_int32(&buf, 0);
write_string(&buf, name, sz);
write_int32(&buf, number);
write_bytes(&buf, cursor_id, 8);
write_length(&buf, buf.size, len);
lua_pushlstring(L, (const char *)buf.ptr, buf.size);
buffer_destroy(&buf);
return 1;
}
示例8: test_compress
void test_compress(FILE* outFp, FILE* inpFp)
{
LZ4_stream_t lz4Stream_body = { 0 };
LZ4_stream_t* lz4Stream = &lz4Stream_body;
static char inpBuf[RING_BUFFER_BYTES];
int inpOffset = 0;
for(;;) {
// Read random length ([1,MESSAGE_MAX_BYTES]) data to the ring buffer.
char* const inpPtr = &inpBuf[inpOffset];
const int randomLength = (rand() % MESSAGE_MAX_BYTES) + 1;
const int inpBytes = (int) read_bin(inpFp, inpPtr, randomLength);
if (0 == inpBytes) break;
{
char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)];
const int cmpBytes = LZ4_compress_continue(lz4Stream, inpPtr, cmpBuf, inpBytes);
if(cmpBytes <= 0) break;
write_int32(outFp, cmpBytes);
write_bin(outFp, cmpBuf, cmpBytes);
inpOffset += inpBytes;
// Wraparound the ringbuffer offset
if(inpOffset >= RING_BUFFER_BYTES - MESSAGE_MAX_BYTES) inpOffset = 0;
}
}
write_int32(outFp, 0);
}
示例9: test_compress
void test_compress(file* outfp, file* inpfp)
{
lz4_streamhc_t lz4stream_body = { 0 };
lz4_streamhc_t* lz4stream = &lz4stream_body;
static char inpbuf[ring_buffer_bytes];
int inpoffset = 0;
for(;;)
{
// read random length ([1,message_max_bytes]) data to the ring buffer.
char* const inpptr = &inpbuf[inpoffset];
const int randomlength = (rand() % message_max_bytes) + 1;
const int inpbytes = (int) read_bin(inpfp, inpptr, randomlength);
if (0 == inpbytes) break;
{
char cmpbuf[lz4_compressbound(message_max_bytes)];
const int cmpbytes = lz4_compresshc_continue(lz4stream, inpptr, cmpbuf, inpbytes);
if(cmpbytes <= 0) break;
write_int32(outfp, cmpbytes);
write_bin(outfp, cmpbuf, cmpbytes);
inpoffset += inpbytes;
// wraparound the ringbuffer offset
if(inpoffset >= ring_buffer_bytes - message_max_bytes)
inpoffset = 0;
}
}
write_int32(outfp, 0);
}
示例10: gen_ensure_index_packet
struct data_buffer* gen_ensure_index_packet(char* cmd,MEM_POOL* mem_pool)
{
char* table_name = NULL;
char* field_name = NULL;
uint32_t tblen;
uint32_t fdlen;
char* token;
enum index_key_alg index_type;
enum field_types data_type;
if((table_name = strtok(NULL," ")) == NULL)
return NULL;
if((field_name = strtok(NULL," ")) == NULL)
return NULL;
if((token = strtok(NULL," ")) == NULL)
return NULL;
index_type = (index_key_alg)atoi(token);
if(index_type > 0xff)
return NULL;
if((token = strtok(NULL," ")) == NULL)
return NULL;
data_type = (enum field_types)atoi(token);
if(data_type > 0xff)
return NULL;
tblen = strlen(table_name);
fdlen = strlen(field_name);
struct data_buffer *dbuf = init_data_buffer();
size_t data_len = tblen + fdlen + 10 * sizeof(uint8_t) + MESSAGE_HEAD_LEN + 2*sizeof(uint32_t);
databuf_resize(dbuf, data_len);
//写入数据长度
write_int32(data_len,dbuf);
write_int8(1, dbuf);
write_int8(1, dbuf);
write_int16(MT_CD_EXE_INDEX, dbuf);
write_int32(0, dbuf);
//timeout
write_int32(0, dbuf);
//拼接协议包
write_int32(tblen,dbuf);
write_bytes((uint8_t*)table_name,tblen,dbuf);
write_int32(fdlen,dbuf);
write_bytes((uint8_t*)field_name,fdlen,dbuf);
write_int8(index_type,dbuf);
write_int8(data_type,dbuf);
return dbuf;
}
示例11: write_int32
bool JArchivePrivate::write_header() {
qint32 version_number=JARCHIVE_VERSION;
qint32 header_size=4*3;
qint32 code=JARCHIVE_BEGIN_FILE_CODE;
write_int32(code); //4
write_int32(header_size); //4
write_int32(version_number); //4
return true;
}
示例12: avi_writer_write_stream_format
static void avi_writer_write_stream_format(AviWriter *self) {
avi_writer_push_chunk(self, "strf");
/* This is a BITMAPINFO structure for video streams */
/* BITMAPINFOHEADER size */
write_int32(self->file, 0x28);
/* width and height */
write_int32(self->file, self->width);
write_int32(self->file, self->height);
/* Number of planes, "must be set to 1" */
write_int16(self->file, 1);
/* bits per pixel */
write_int16(self->file, 24);
/* compression */
write_int32(self->file, 0);
/* size, in bytes, of the image */
write_int32(self->file, self->width * self->height * 3);
/* horizontal/vertical pixels per meter (75 dpi) */
write_int32(self->file, 2952);
write_int32(self->file, 2952);
/* Color table size and number of important colors */
write_int32(self->file, 0);
write_int32(self->file, 0);
avi_writer_pop_chunk(self);
}
示例13: jl_serialize_fptr
static void jl_serialize_fptr(ios_t *s, void *fptr)
{
void **pbp = ptrhash_bp(&fptr_to_id, fptr);
if (*pbp == HT_NOTFOUND)
jl_error("unknown function pointer");
write_int32(s, *(ptrint_t*)pbp);
}
示例14: bson_encoder_append_int
int
bson_encoder_append_int(bson_encoder_t encoder, const char *name, int64_t value)
{
bool result;
CODER_CHECK(encoder);
/* use the smallest encoding that will hold the value */
if (value == (int32_t)value) {
debug("encoding %lld as int32", value);
result = write_int8(encoder, BSON_INT32) ||
write_name(encoder, name) ||
write_int32(encoder, value);
} else {
debug("encoding %lld as int64", value);
result = write_int8(encoder, BSON_INT64) ||
write_name(encoder, name) ||
write_int64(encoder, value);
}
if (result) {
CODER_KILL(encoder, "write error on BSON_INT");
}
return 0;
}
示例15: avi_writer_close
void avi_writer_close (AviWriter *self) {
avi_writer_pop_chunk(self); /* Close the "movi" list */
avi_writer_write_index(self);
avi_writer_pop_chunk(self); /* Close the "AVI" chunk */
/* At this point, there should be no more open chunks */
g_assert(self->chunk_stack == NULL);
/* Fix up frame count and stream length */
fseek(self->file, self->frame_count_offset, SEEK_SET);
write_int32(self->file, self->frame_count);
fseek(self->file, self->length_offset, SEEK_SET);
write_int32(self->file, self->frame_count * self->frame_rate * RATE_SCALE);
fclose(self->file);
g_queue_free(self->index_queue);
}