本文整理汇总了C++中bson_size函数的典型用法代码示例。如果您正苦于以下问题:C++ bson_size函数的具体用法?C++ bson_size怎么用?C++ bson_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bson_size函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: bson_append_code_w_scope
bson_buffer * bson_append_code_w_scope( bson_buffer * b , const char * name , const char * code , const bson * scope){
int sl = strlen(code) + 1;
int size = 4 + 4 + sl + bson_size(scope);
if (!bson_append_estart(b, bson_codewscope, name, size)) return 0;
bson_append32(b, &size);
bson_append32(b, &sl);
bson_append(b, code, sl);
bson_append(b, scope->data, bson_size(scope));
return b;
}
开发者ID:brooksdavis,项目名称:duo_unix,代码行数:10,代码来源:bson.c
示例2: test_bson_build_full
void
test_bson_build_full (void)
{
bson *b, *o;
b = bson_build_full (BSON_TYPE_DOUBLE, "double", FALSE, 3.14,
BSON_TYPE_STRING, "str", FALSE, "hello world", -1,
BSON_TYPE_DOCUMENT, "doc", TRUE,
bson_build (BSON_TYPE_STRING, "name", "sub-document", -1,
BSON_TYPE_INT32, "answer", 42,
BSON_TYPE_NONE),
BSON_TYPE_ARRAY, "array", TRUE,
bson_build (BSON_TYPE_INT32, "0", 32,
BSON_TYPE_INT64, "1", (gint64)-42,
BSON_TYPE_NONE),
BSON_TYPE_BINARY, "binary0", FALSE, BSON_BINARY_SUBTYPE_GENERIC,
"foo\0bar", 7,
BSON_TYPE_OID, "_id", FALSE, "1234567890ab",
BSON_TYPE_BOOLEAN, "TRUE", FALSE, FALSE,
BSON_TYPE_UTC_DATETIME, "date", FALSE, 1294860709000,
BSON_TYPE_TIMESTAMP, "ts", FALSE, 1294860709000,
BSON_TYPE_NULL, "null", FALSE,
BSON_TYPE_REGEXP, "foobar", FALSE, "s/foo.*bar/", "i",
BSON_TYPE_JS_CODE, "alert", FALSE, "alert (\"hello world!\");", -1,
BSON_TYPE_SYMBOL, "sex", FALSE, "Marilyn Monroe", -1,
BSON_TYPE_JS_CODE_W_SCOPE, "print", TRUE, "alert (v);", -1,
bson_build (BSON_TYPE_STRING, "v", "hello world", -1,
BSON_TYPE_NONE),
BSON_TYPE_INT32, "int32", FALSE, 32,
BSON_TYPE_INT64, "int64", FALSE, (gint64)-42,
BSON_TYPE_NONE);
bson_finish (b);
o = test_bson_generate_full ();
cmp_ok (bson_size (b), "==", bson_size (o),
"bson_build_full() and hand crafted BSON object sizes match");
ok (memcmp (bson_data (b), bson_data (o), bson_size (b)) == 0,
"bson_build_full() and hand crafted BSON objects match");
bson_free (b);
bson_free (o);
b = bson_build_full (BSON_TYPE_UNDEFINED, "undef", FALSE,
BSON_TYPE_NONE);
ok (b == NULL,
"bson_build_full() should fail with an unsupported element type");
b = bson_build_full (BSON_TYPE_STRING, "str", FALSE, "hello", -1,
BSON_TYPE_UNDEFINED, "undef", FALSE,
BSON_TYPE_NONE);
ok (b == NULL,
"bson_build_full() should fail with an unsupported element type");
}
开发者ID:algernon,项目名称:libmongo-client,代码行数:55,代码来源:bson_build_full.c
示例3: mongo_find
mongo_cursor* mongo_find(mongo_connection* conn, const char* ns, bson* query,
bson* fields, int nToReturn, int nToSkip, int options) {
int sl;
int res;
mongo_cursor * cursor;
char * data;
mongo_message * mm = mongo_message_create( 16 + /* header */
4 + /* options */
strlen( ns ) + 1 + /* ns */
4 + 4 + /* skip,return */
bson_size( query ) +
bson_size( fields ) ,
0 , 0 , MONGO_OP_QUERY );
data = &mm->data;
data = mongo_data_append32( data , &options );
data = mongo_data_append( data , ns , strlen( ns ) + 1 );
data = mongo_data_append32( data , &nToSkip );
data = mongo_data_append32( data , &nToReturn );
data = mongo_data_append( data , query->data , bson_size( query ) );
if ( fields )
data = mongo_data_append( data , fields->data , bson_size( fields ) );
bson_fatal_msg( (data == ((char*)mm) + mm->head.len), "query building fail!" );
res = mongo_message_send( conn , mm );
if(res != MONGO_OK){
return NULL;
}
cursor = (mongo_cursor*)bson_malloc(sizeof(mongo_cursor));
res = mongo_read_response( conn, (mongo_reply **)&(cursor->reply) );
if( res != MONGO_OK ) {
free( cursor );
return NULL;
}
sl = strlen(ns)+1;
cursor->ns = bson_malloc(sl);
if (!cursor->ns){
free(cursor->reply);
free( cursor );
return NULL;
}
memcpy( (void*)cursor->ns, ns, sl );
cursor->conn = conn;
cursor->current.data = NULL;
cursor->options = options;
return (mongo_cursor*)cursor;
}
开发者ID:Unity-Technologies,项目名称:mongo-c-driver,代码行数:53,代码来源:mongo.c
示例4: test_bson_string
void
test_bson_string (void)
{
bson *b;
/* Test #1: A single string element, with default size. */
b = bson_new ();
ok (bson_append_string (b, "hello", "world", -1),
"bson_append_string() works");
bson_finish (b);
cmp_ok (bson_size (b), "==", 22, "BSON string element size check");
ok (memcmp (bson_data (b),
"\026\000\000\000\002\150\145\154\154\157\000\006\000\000\000"
"\167\157\162\154\144\000\000",
bson_size (b)) == 0,
"BSON string element contents check");
bson_free (b);
/* Test #2: A single string element, with explicit length. */
b = bson_new ();
ok (bson_append_string (b, "goodbye",
"cruel world, this garbage is gone.",
strlen ("cruel world")),
"bson_append_string() with explicit length works");
bson_finish (b);
cmp_ok (bson_size (b), "==", 30, "BSON string element size check, #2");
ok (memcmp (bson_data (b),
"\036\000\000\000\002\147\157\157\144\142\171\145\000\014\000"
"\000\000\143\162\165\145\154\040\167\157\162\154\144\000\000",
bson_size (b)) == 0,
"BSON string element contents check, #2");
bson_free (b);
/* Test #3: Negative test, passing invalid arguments. */
b = bson_new ();
ok (bson_append_string (b, "hello", "world", -42) == FALSE,
"bson_append_string() should fail with invalid length");
ok (bson_append_string (b, "hello", NULL, -1) == FALSE,
"bson_append_string() should fail without a string");
ok (bson_append_string (b, NULL, "world", -1) == FALSE,
"bson_append_string() should fail without a key name");
ok (bson_append_string (NULL, "hello", "world", -1) == FALSE,
"bson_append_string() should fail without a BSON object");
bson_finish (b);
cmp_ok (bson_size (b), "==", 5,
"BSON object should be empty");
ok (bson_append_string (b, "hello", "world", -1) == FALSE,
"Appending to a finished element should fail");
bson_free (b);
}
开发者ID:algernon,项目名称:libmongo-client,代码行数:53,代码来源:bson_append_string.c
示例5: bson_append_code_w_scope_n
int bson_append_code_w_scope_n( bson *b, const char *name,
const char *code, int len, const bson *scope ) {
int sl = len + 1;
int size = 4 + 4 + sl + bson_size( scope );
if ( bson_append_estart( b, BSON_CODEWSCOPE, name, size ) == BSON_ERROR )
return BSON_ERROR;
bson_append32( b, &size );
bson_append32( b, &sl );
bson_append( b, code, sl );
bson_append( b, scope->data, bson_size( scope ) );
return BSON_OK;
}
开发者ID:halayudha,项目名称:kdengine,代码行数:13,代码来源:bson.c
示例6: _bson_append_document_element
/** @internal Append a document-like element to a BSON object.
*
* Arrays and documents are both similar, and differ very little:
* different type, and arrays have restrictions on key names (which
* are not enforced by this library).
*
* This convenience function can append both types.
*
* @param b is the BSON object to append to.
* @param type is the document-like type to append.
* @param name is the key name.
* @param doc is the document-like object to append.
*
* @note The @a doc must be a finished BSON object.
*
* @returns TRUE on success, FALSE otherwise.
*/
static gboolean
_bson_append_document_element (bson *b, bson_type type, const gchar *name,
const bson *doc)
{
if (bson_size (doc) < 0)
return FALSE;
if (!_bson_append_element_header (b, type, name))
return FALSE;
b->data = g_byte_array_append (b->data, bson_data (doc), bson_size (doc));
return TRUE;
}
开发者ID:algernon,项目名称:libmongo-client,代码行数:30,代码来源:bson.c
示例7: f_map_bson_buf
void f_map_bson_buf (void){
buffer_t *buf;
bson b[1];
bson_init_empty(b);
map_to_bson(sp, b);
buf = allocate_buffer(bson_size(b));
memcpy(buf->item, b->data, bson_size(b));
pop_stack();
push_refed_buffer(buf);
bson_destroy( b );
}
开发者ID:carriercomm,项目名称:mudos-1,代码行数:14,代码来源:mg.c
示例8: mongo_cursor_op_query
static int mongo_cursor_op_query( mongo_cursor *cursor ) {
int res;
bson empty;
char *data;
mongo_message *mm;
/* Set up default values for query and fields, if necessary. */
if( ! cursor->query )
cursor->query = bson_empty( &empty );
else if( mongo_cursor_bson_valid( cursor, cursor->query ) != MONGO_OK )
return MONGO_ERROR;
if( ! cursor->fields )
cursor->fields = bson_empty( &empty );
else if( mongo_cursor_bson_valid( cursor, cursor->fields ) != MONGO_OK )
return MONGO_ERROR;
mm = mongo_message_create( 16 + /* header */
4 + /* options */
strlen( cursor->ns ) + 1 + /* ns */
4 + 4 + /* skip,return */
bson_size( cursor->query ) +
bson_size( cursor->fields ) ,
0 , 0 , MONGO_OP_QUERY );
data = &mm->data;
data = mongo_data_append32( data , &cursor->options );
data = mongo_data_append( data , cursor->ns , strlen( cursor->ns ) + 1 );
data = mongo_data_append32( data , &cursor->skip );
data = mongo_data_append32( data , &cursor->limit );
data = mongo_data_append( data , cursor->query->data , bson_size( cursor->query ) );
if ( cursor->fields )
data = mongo_data_append( data , cursor->fields->data , bson_size( cursor->fields ) );
bson_fatal_msg( ( data == ( ( char * )mm ) + mm->head.len ), "query building fail!" );
res = mongo_message_send( cursor->conn , mm );
if( res != MONGO_OK ) {
return MONGO_ERROR;
}
res = mongo_read_response( cursor->conn, ( mongo_reply ** )&( cursor->reply ) );
if( res != MONGO_OK ) {
return MONGO_ERROR;
}
cursor->seen += cursor->reply->fields.num;
cursor->flags |= MONGO_CURSOR_QUERY_SENT;
return MONGO_OK;
}
开发者ID:HackThisSite,项目名称:htspbx-missionfmk,代码行数:50,代码来源:mongo.c
示例9: mongo_find
mongo_cursor* mongo_find(mongo_connection* conn, const char* ns, bson* query, bson* fields, int nToReturn, int nToSkip, int options){
int sl;
mongo_cursor * cursor;
char * data;
mongo_message * mm = mongo_message_create(conn->p,
16 + /* header */
4 + /* options */
strlen( ns ) + 1 + /* ns */
4 + 4 + /* skip,return */
bson_size( query ) +
bson_size( fields ) ,
0 , 0 , mongo_op_query );
data = &mm->data;
data = mongo_data_append32( data , &options );
data = mongo_data_append( data , ns , strlen( ns ) + 1 );
data = mongo_data_append32( data , &nToSkip );
data = mongo_data_append32( data , &nToReturn );
data = mongo_data_append( data , query->data , bson_size( query ) );
if ( fields )
data = mongo_data_append( data , fields->data , bson_size( fields ) );
bson_fatal_msg( (data == ((char*)mm) + mm->head.len), "query building fail!" );
mongo_message_send( conn , mm );
cursor = (mongo_cursor*)apr_palloc(conn->p, sizeof(mongo_cursor));
MONGO_TRY{
cursor->mm = mongo_read_response(conn);
}MONGO_CATCH{
//free(cursor);
MONGO_RETHROW();
}
sl = strlen(ns)+1;
cursor->ns = apr_palloc(conn->p, sl);
if (!cursor->ns){
/*
//free(cursor->mm);
//free(cursor);
*/
return 0;
}
memcpy((void*)cursor->ns, ns, sl); /* cast needed to silence GCC warning */
cursor->conn = conn;
cursor->current.data = NULL;
return cursor;
}
开发者ID:kryton,项目名称:apr-mongo-c-driver,代码行数:50,代码来源:mongo.c
示例10: test_bson_cursor_get_javascript_w_scope
void
test_bson_cursor_get_javascript_w_scope (void)
{
bson *b, *scope = NULL, *valid;
bson_cursor *c;
const gchar *s = "deadbeef";
ok (bson_cursor_get_javascript_w_scope (NULL, &s, &scope) == FALSE,
"bson_cursor_get_javascript_w_scope() with a NULL cursor fails");
b = test_bson_generate_full ();
c = bson_cursor_new (b);
ok (bson_cursor_get_javascript_w_scope (c, NULL, &scope) == FALSE,
"bson_cursor_get_javascript_w_scope() with a NULL js destination fails");
ok (bson_cursor_get_javascript_w_scope (c, &s, NULL) == FALSE,
"bson_cursor_get_javascript_w_scope() with a NULL scope destinatin fails");
ok (bson_cursor_get_javascript_w_scope (c, &s, &scope) == FALSE,
"bson_cursor_get_javascript_w_scope() at the initial position fails");
is (s, "deadbeef",
"destination remains unchanged after failed cursor operations");
bson_cursor_free (c);
c = bson_find (b, "print");
ok (bson_cursor_get_javascript_w_scope (c, &s, &scope),
"bson_cursor_get_javascript_w_scope() works");
is (s, "alert (v);",
"bson_cursor_get_javascript_w_scope() returns the correct result");
valid = bson_new ();
bson_append_string (valid, "v", "hello world", -1);
bson_finish (valid);
cmp_ok (bson_size (scope), "==", bson_size (valid),
"The returned scope's length is correct");
ok (memcmp (bson_data (scope), bson_data (valid),
bson_size (scope)) == 0,
"The returned scope is correct");
bson_free (valid);
bson_cursor_next (c);
ok (bson_cursor_get_javascript_w_scope (c, &s, &scope) == FALSE,
"bson_cursor_get_javascript_w_scope() should fail when the cursor "
"points to non-javascript data");
bson_cursor_free (c);
bson_free (b);
bson_free (scope);
}
开发者ID:algernon,项目名称:libmongo-client,代码行数:49,代码来源:bson_cursor_get_javascript_w_scope.c
示例11: test_mongo_wire_generate_reply
mongo_packet *
test_mongo_wire_generate_reply (gboolean valid, gint32 nreturn,
gboolean with_docs)
{
mongo_reply_packet_header rh;
mongo_packet_header h;
mongo_packet *p;
guint8 *data;
gint data_size = sizeof (mongo_reply_packet_header);
bson *b1 = NULL, *b2 = NULL;
p = mongo_wire_packet_new ();
h.opcode = (valid) ? GINT32_TO_LE (1) : GINT32_TO_LE (42);
h.id = GINT32_TO_LE (1984);
h.resp_to = GINT32_TO_LE (42);
if (with_docs)
{
b1 = test_bson_generate_full ();
b2 = test_bson_generate_full ();
data_size += bson_size (b1) + bson_size (b2);
}
h.length = GINT32_TO_LE (sizeof (mongo_packet_header) + data_size);
mongo_wire_packet_set_header (p, &h);
data = g_try_malloc (data_size);
rh.flags = 0;
rh.cursor_id = GINT64_TO_LE ((gint64)12345);
rh.start = 0;
rh.returned = GINT32_TO_LE (nreturn);
memcpy (data, &rh, sizeof (mongo_reply_packet_header));
if (with_docs)
{
memcpy (data + sizeof (mongo_reply_packet_header),
bson_data (b1), bson_size (b1));
memcpy (data + sizeof (mongo_reply_packet_header) + bson_size (b1),
bson_data (b2), bson_size (b2));
}
mongo_wire_packet_set_data (p, data, data_size);
g_free (data);
bson_free (b1);
bson_free (b2);
return p;
}
开发者ID:chrisrob,项目名称:libmongo-client,代码行数:49,代码来源:test.c
示例12: bson_find
bson_cursor *
bson_find (const bson *b, const gchar *name)
{
bson_cursor *c;
if (bson_size (b) == -1 || !name)
return NULL;
c = bson_cursor_new (b);
if (_bson_cursor_find (b, name, sizeof (gint32), bson_size (c->obj) - 1,
FALSE, c))
return c;
bson_cursor_free (c);
return NULL;
}
开发者ID:algernon,项目名称:libmongo-client,代码行数:15,代码来源:bson.c
示例13: mongo_insert
void mongo_insert( mongo_connection * conn , const char * ns , bson * bson ){
char * data;
mongo_message * mm = mongo_message_create( 16 /* header */
+ 4 /* ZERO */
+ strlen(ns)
+ 1 + bson_size(bson)
, 0, 0, mongo_op_insert);
data = &mm->data;
data = mongo_data_append32(data, &zero);
data = mongo_data_append(data, ns, strlen(ns) + 1);
data = mongo_data_append(data, bson->data, bson_size(bson));
mongo_message_send(conn, mm);
}
开发者ID:chevalun,项目名称:mongo-c-driver,代码行数:15,代码来源:mongo.c
示例14: test_bson_binary
void
test_bson_binary (void)
{
bson *b;
b = bson_new ();
ok (bson_append_binary (b, "binary0", BSON_BINARY_SUBTYPE_GENERIC,
(guint8 *)"foo\0bar", 7),
"bson_append_binary(), type 0 works");
ok (bson_append_binary (b, "binary2", BSON_BINARY_SUBTYPE_BINARY,
(guint8 *)"\0\0\0\7foo\0bar", 11),
"bson_append_binary(), type 2 works");
bson_finish (b);
cmp_ok (bson_size (b), "==", 51, "BSON binary element size check");
ok (memcmp (bson_data (b),
"\063\000\000\000\005\142\151\156\141\162\171\060\000\007\000"
"\000\000\000\146\157\157\000\142\141\162\005\142\151\156\141"
"\162\171\062\000\013\000\000\000\002\000\000\000\007\146\157"
"\157\000\142\141\162\000",
bson_size (b)) == 0,
"BSON binary element contents check");
bson_free (b);
b = bson_new ();
ok (bson_append_binary (b, NULL, BSON_BINARY_SUBTYPE_GENERIC,
(guint8 *)"foo\0bar", 7) == FALSE,
"bson_append_binary() without a key name should fail");
ok (bson_append_binary (b, "binary1", BSON_BINARY_SUBTYPE_GENERIC,
NULL, 10) == FALSE,
"bson_append_binary () without binary data should fail");
ok (bson_append_binary (b, "binary3", BSON_BINARY_SUBTYPE_GENERIC,
(guint8 *)"foo\0bar", -1) == FALSE,
"bson_append_binary () with an invalid length should fail");
ok (bson_append_binary (NULL, "binary1", BSON_BINARY_SUBTYPE_GENERIC,
(guint8 *)"foo\0bar", 7) == FALSE,
"bson_append_binary () without a BSON object should fail");
bson_finish (b);
cmp_ok (bson_size (b), "==", 5,
"BSON object should be empty");
ok (bson_append_binary (b, "binary", BSON_BINARY_SUBTYPE_GENERIC,
(guint8 *)"foo\0bar", 7) == FALSE,
"Appending to a finished element should fail");
bson_free (b);
}
开发者ID:algernon,项目名称:libmongo-client,代码行数:48,代码来源:bson_append_binary.c
示例15: uvmongo_message_serialize_delete
uvmongo_message_t *
uvmongo_message_serialize_delete(buffer_t * fullname, bson * selector) {
char * data;
char * ns = buffer_string(fullname);
size_t nslen = strlen(ns) + 1;
size_t bslen = bson_size(selector);
size_t msglen = 16 + 4 + nslen + 4 + bslen;
uvmongo_message_t * msg = uvmongo_message_new(msglen, 0, 0, OP_DELETE);
data = &msg->data;
data = uvmongo_message_append32(data, &ZERO);
data = uvmongo_message_append(data, ns, nslen);
data = uvmongo_message_append32(data, &ONE);
data = uvmongo_message_append(data, selector->data, bson_size(selector));
return msg;
}
开发者ID:flybird119,项目名称:uv-mongo,代码行数:16,代码来源:message.c
示例16: f_bson_buf_find
void f_bson_buf_find(void){
int size;
bson b[1];
bson sub;
svalue_t v;
bson_iterator it;
size = (sp-1)->u.buf->size;
bson_init_empty(b);
bson_init_size( b, size );
memcpy(b->data, (sp-1)->u.buf->item, size);
b->finished = 1;
/* buff不合法 */
if(bson_size(b) != size){
pop_n_elems(st_num_arg);
push_number(0);
goto free_bson;
}
/* 找不到数据 */
if(!bson_find( &it, b, sp->u.string )){
pop_n_elems(st_num_arg);
push_number(0);
goto free_bson;
}
bson_to_v(&it, &v);
free_buffer((sp-1)->u.buf);
pop_stack();
*sp = v;
free_bson:
bson_destroy( b );
}
开发者ID:carriercomm,项目名称:mudos-1,代码行数:32,代码来源:mg.c
示例17: bson_cursor_next
gboolean
bson_cursor_next (bson_cursor *c)
{
const guint8 *d;
gint32 pos, bs;
if (!c)
return FALSE;
d = bson_data (c->obj);
if (c->pos == 0)
pos = sizeof (guint32);
else
{
bs = _bson_get_block_size (bson_cursor_type (c), d + c->value_pos);
if (bs == -1)
return FALSE;
pos = c->value_pos + bs;
}
if (pos >= bson_size (c->obj) - 1)
return FALSE;
c->pos = pos;
c->key = (gchar *) &d[c->pos + 1];
c->value_pos = c->pos + strlen (c->key) + 2;
return TRUE;
}
开发者ID:algernon,项目名称:libmongo-client,代码行数:30,代码来源:bson.c
示例18: mongo_count
int64_t mongo_count( mongo *conn, const char *db, const char *ns, bson *query ) {
bson cmd;
bson out; // = {NULL, 0};
memset(&out, 0, sizeof(out));
int64_t count = -1;
bson_init( &cmd );
bson_append_string( &cmd, "count", ns );
if ( query && bson_size( query ) > 5 ) /* not empty */
bson_append_bson( &cmd, "query", query );
bson_finish( &cmd );
if( mongo_run_command( conn, db, &cmd, &out ) == MONGO_OK ) {
bson_iterator it;
if( bson_find( &it, &out, "n" ) )
count = bson_iterator_long( &it );
bson_destroy( &cmd );
bson_destroy( &out );
return count;
} else {
bson_destroy( &out );
bson_destroy( &cmd );
return MONGO_ERROR;
}
}
开发者ID:rpuserh,项目名称:nginx-gridfs,代码行数:25,代码来源:mongo.c
示例19: _duo_bson_response
static duo_code_t
_duo_bson_response(struct duo_ctx *ctx, bson *resp)
{
bson obj;
bson_iterator it;
duo_code_t ret;
const char *p;
int code;
bson_init(&obj, (char *)ctx->body, 0);
ret = DUO_SERVER_ERROR;
if (ctx->body_len <= 0 || bson_size(&obj) > ctx->body_len) {
_duo_seterr(ctx, "invalid BSON response");
return (ret);
}
_BSON_FIND(ctx, &it, &obj, "stat", bson_string);
p = bson_iterator_string(&it);
if (strcasecmp(p, "OK") == 0) {
_BSON_FIND(ctx, &it, &obj, "response", bson_object);
if (resp)
bson_iterator_subobject(&it, resp);
ret = DUO_OK;
} else if (strcasecmp(p, "FAIL") == 0) {
_BSON_FIND(ctx, &it, &obj, "code", bson_int);
code = bson_iterator_int(&it);
_BSON_FIND(ctx, &it, &obj, "message", bson_string);
_duo_seterr(ctx, "%d: %s", code, bson_iterator_string(&it));
ret = DUO_FAIL;
}
return (ret);
}
开发者ID:gregster85,项目名称:duo_unix,代码行数:34,代码来源:duo.c
示例20: test_bson_cursor_get_document
void
test_bson_cursor_get_document (void)
{
bson *b, *d = NULL;
bson_cursor *c;
ok (bson_cursor_get_document (NULL, &d) == FALSE,
"bson_cursor_get_document() with a NULL cursor fails");
b = test_bson_generate_full ();
c = bson_cursor_new (b);
ok (bson_cursor_get_document (c, NULL) == FALSE,
"bson_cursor_get_document() with a NULL destination fails");
ok (bson_cursor_get_document (c, &d) == FALSE,
"bson_cursor_get_document() at the initial position fails");
ok (d == NULL,
"destination remains unchanged after failed cursor operations");
bson_cursor_free (c);
c = bson_find (b, "doc");
ok (bson_cursor_get_document (c, &d),
"bson_cursor_get_document() works");
cmp_ok (bson_size (d), ">", 0,
"the returned document is finished");
bson_free (d);
bson_cursor_next (c);
ok (bson_cursor_get_document (c, &d) == FALSE,
"bson_cursor_get_document() fails if the cursor points to "
"non-document data");
bson_cursor_free (c);
bson_free (b);
}
开发者ID:3d0c,项目名称:libmongo-client,代码行数:35,代码来源:bson_cursor_get_document.c
注:本文中的bson_size函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论