const char *bson_iterator_bin_data( const bson_iterator *i ) { return ( bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD ) ? bson_iterator_value( i ) + 9 : bson_iterator_value( i ) + 5; }
const char * bson_iterator_bin_data( const bson_iterator * i ){ return (bson_iterator_bin_type( i ) == 2) ? bson_iterator_value( i ) + 9 : bson_iterator_value( i ) + 5; }
int bson_iterator_bin_len( const bson_iterator *i ) { return ( bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD ) ? bson_iterator_int_raw( i ) - 4 : bson_iterator_int_raw( i ); }
MONGO_EXPORT const char *bson_iterator_bin_data( const bson_iterator *i ) { check_mongo_object( (void*)i ); return ( bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD ) ? bson_iterator_value( i ) + 9 : bson_iterator_value( i ) + 5; }
int bson_iterator_bin_len( const bson_iterator * i ){ return (bson_iterator_bin_type(i) == 2) ? bson_iterator_int_raw( i ) - 4 : bson_iterator_int_raw( i ); }
MONGO_EXPORT int bson_iterator_bin_len( const bson_iterator *i ) { check_mongo_object( (void*)i ); return ( bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD ) ? bson_iterator_int_raw( i ) - 4 : bson_iterator_int_raw( i ); }
int test_bson_generic( void ) { bson_iterator it, it2, it3; bson_oid_t oid; bson_timestamp_t ts; bson_timestamp_t ts_result; bson b[1]; bson copy[1]; bson scope[1]; ts.i = 1; ts.t = 2; bson_init( b ); bson_append_double( b, "d", 3.14 ); bson_append_string( b, "s", "hello" ); bson_append_string_n( b, "s_n", "goodbye cruel world", 7 ); { bson_append_start_object( b, "o" ); bson_append_start_array( b, "a" ); bson_append_binary( b, "0", 8, "w\0rld", 5 ); bson_append_finish_object( b ); bson_append_finish_object( b ); } bson_append_undefined( b, "u" ); bson_oid_from_string( &oid, "010203040506070809101112" ); ASSERT( !memcmp( oid.bytes, "\x001\x002\x003\x004\x005\x006\x007\x008\x009\x010\x011\x012", 12 ) ); bson_append_oid( b, "oid", &oid ); bson_append_bool( b, "b", 1 ); bson_append_date( b, "date", 0x0102030405060708 ); bson_append_null( b, "n" ); bson_append_regex( b, "r", "^asdf", "imx" ); /* no dbref test (deprecated) */ bson_append_code( b, "c", "function(){}" ); bson_append_code_n( b, "c_n", "function(){}garbage", 12 ); bson_append_symbol( b, "symbol", "symbol" ); bson_append_symbol_n( b, "symbol_n", "symbol and garbage", 6 ); { bson_init( scope ); bson_append_int( scope, "i", 123 ); bson_finish( scope ); bson_append_code_w_scope( b, "cws", "function(){return i}", scope ); bson_destroy( scope ); } bson_append_timestamp( b, "timestamp", &ts ); bson_append_long( b, "l", 0x1122334455667788 ); /* Ensure that we can't copy a non-finished object. */ ASSERT( bson_copy( copy, b ) == BSON_ERROR ); bson_finish( b ); ASSERT( b->err == BSON_VALID ); /* Test append after finish. */ ASSERT( bson_append_string( b, "foo", "bar" ) == BSON_ERROR ); ASSERT( b->err & BSON_ALREADY_FINISHED ); ASSERT( bson_copy( copy, b ) == BSON_OK ); ASSERT( 1 == copy->finished ); ASSERT( 0 == copy->err ); bson_destroy( copy ); bson_print( b ); bson_iterator_init( &it, b ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_DOUBLE ); ASSERT( bson_iterator_type( &it ) == BSON_DOUBLE ); ASSERT( !strcmp( bson_iterator_key( &it ), "d" ) ); ASSERT( bson_iterator_double( &it ) == 3.14 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_STRING ); ASSERT( bson_iterator_type( &it ) == BSON_STRING ); ASSERT( !strcmp( bson_iterator_key( &it ), "s" ) ); ASSERT( !strcmp( bson_iterator_string( &it ), "hello" ) ); ASSERT( strcmp( bson_iterator_string( &it ), "" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_STRING ); ASSERT( bson_iterator_type( &it ) == BSON_STRING ); ASSERT( !strcmp( bson_iterator_key( &it ), "s_n" ) ); ASSERT( !strcmp( bson_iterator_string( &it ), "goodbye" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_OBJECT ); ASSERT( bson_iterator_type( &it ) == BSON_OBJECT ); ASSERT( !strcmp( bson_iterator_key( &it ), "o" ) ); bson_iterator_subiterator( &it, &it2 ); ASSERT( bson_iterator_more( &it2 ) ); ASSERT( bson_iterator_next( &it2 ) == BSON_ARRAY ); ASSERT( bson_iterator_type( &it2 ) == BSON_ARRAY ); ASSERT( !strcmp( bson_iterator_key( &it2 ), "a" ) ); bson_iterator_subiterator( &it2, &it3 ); ASSERT( bson_iterator_more( &it3 ) ); ASSERT( bson_iterator_next( &it3 ) == BSON_BINDATA ); ASSERT( bson_iterator_type( &it3 ) == BSON_BINDATA ); ASSERT( !strcmp( bson_iterator_key( &it3 ), "0" ) ); ASSERT( bson_iterator_bin_type( &it3 ) == 8 ); ASSERT( bson_iterator_bin_len( &it3 ) == 5 ); ASSERT( !memcmp( bson_iterator_bin_data( &it3 ), "w\0rld", 5 ) ); ASSERT( bson_iterator_more( &it3 ) ); ASSERT( bson_iterator_next( &it3 ) == BSON_EOO ); ASSERT( bson_iterator_type( &it3 ) == BSON_EOO ); ASSERT( !bson_iterator_more( &it3 ) ); ASSERT( bson_iterator_more( &it2 ) ); ASSERT( bson_iterator_next( &it2 ) == BSON_EOO ); ASSERT( bson_iterator_type( &it2 ) == BSON_EOO ); ASSERT( !bson_iterator_more( &it2 ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_UNDEFINED ); ASSERT( bson_iterator_type( &it ) == BSON_UNDEFINED ); ASSERT( !strcmp( bson_iterator_key( &it ), "u" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_OID ); ASSERT( bson_iterator_type( &it ) == BSON_OID ); ASSERT( !strcmp( bson_iterator_key( &it ), "oid" ) ); ASSERT( !memcmp( bson_iterator_oid( &it )->bytes, "\x001\x002\x003\x004\x005\x006\x007\x008\x009\x010\x011\x012", 12 ) ); ASSERT( bson_iterator_oid( &it )->ints[0] == oid.ints[0] ); ASSERT( bson_iterator_oid( &it )->ints[1] == oid.ints[1] ); ASSERT( bson_iterator_oid( &it )->ints[2] == oid.ints[2] ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_BOOL ); ASSERT( bson_iterator_type( &it ) == BSON_BOOL ); ASSERT( !strcmp( bson_iterator_key( &it ), "b" ) ); ASSERT( bson_iterator_bool( &it ) == 1 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_DATE ); ASSERT( bson_iterator_type( &it ) == BSON_DATE ); ASSERT( !strcmp( bson_iterator_key( &it ), "date" ) ); ASSERT( bson_iterator_date( &it ) == 0x0102030405060708 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_NULL ); ASSERT( bson_iterator_type( &it ) == BSON_NULL ); ASSERT( !strcmp( bson_iterator_key( &it ), "n" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_REGEX ); ASSERT( bson_iterator_type( &it ) == BSON_REGEX ); ASSERT( !strcmp( bson_iterator_key( &it ), "r" ) ); ASSERT( !strcmp( bson_iterator_regex( &it ), "^asdf" ) ); ASSERT( !strcmp( bson_iterator_regex_opts( &it ), "imx" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_CODE ); ASSERT( bson_iterator_type( &it ) == BSON_CODE ); ASSERT( !strcmp( bson_iterator_code(&it), "function(){}") ); ASSERT( !strcmp( bson_iterator_key( &it ), "c" ) ); ASSERT( !strcmp( bson_iterator_string( &it ), "" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_CODE ); ASSERT( bson_iterator_type( &it ) == BSON_CODE ); ASSERT( !strcmp( bson_iterator_key( &it ), "c_n" ) ); ASSERT( !strcmp( bson_iterator_string( &it ), "" ) ); ASSERT( !strcmp( bson_iterator_code( &it ), "function(){}" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_SYMBOL ); ASSERT( bson_iterator_type( &it ) == BSON_SYMBOL ); ASSERT( !strcmp( bson_iterator_key( &it ), "symbol" ) ); ASSERT( !strcmp( bson_iterator_string( &it ), "symbol" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_SYMBOL ); ASSERT( bson_iterator_type( &it ) == BSON_SYMBOL ); ASSERT( !strcmp( bson_iterator_key( &it ), "symbol_n" ) ); ASSERT( !strcmp( bson_iterator_string( &it ), "symbol" ) ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_CODEWSCOPE ); ASSERT( bson_iterator_type( &it ) == BSON_CODEWSCOPE ); ASSERT( !strcmp( bson_iterator_key( &it ), "cws" ) ); ASSERT( !strcmp( bson_iterator_code( &it ), "function(){return i}" ) ); { bson scope; bson_iterator_code_scope( &it, &scope ); bson_iterator_init( &it2, &scope ); ASSERT( bson_iterator_more( &it2 ) ); ASSERT( bson_iterator_next( &it2 ) == BSON_INT ); ASSERT( bson_iterator_type( &it2 ) == BSON_INT ); ASSERT( !strcmp( bson_iterator_key( &it2 ), "i" ) ); ASSERT( bson_iterator_int( &it2 ) == 123 ); ASSERT( bson_iterator_more( &it2 ) ); ASSERT( bson_iterator_next( &it2 ) == BSON_EOO ); ASSERT( bson_iterator_type( &it2 ) == BSON_EOO ); ASSERT( !bson_iterator_more( &it2 ) ); } ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_TIMESTAMP ); ASSERT( bson_iterator_type( &it ) == BSON_TIMESTAMP ); ASSERT( !strcmp( bson_iterator_key( &it ), "timestamp" ) ); ts_result = bson_iterator_timestamp( &it ); ASSERT( ts_result.i == 1 ); ASSERT( ts_result.t == 2 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_LONG ); ASSERT( bson_iterator_type( &it ) == BSON_LONG ); ASSERT( !strcmp( bson_iterator_key( &it ), "l" ) ); ASSERT( bson_iterator_long( &it ) == 0x1122334455667788 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_EOO ); ASSERT( bson_iterator_type( &it ) == BSON_EOO ); ASSERT( !bson_iterator_more( &it ) ); bson_destroy( b ); { bson bsrc[1]; bson_init( bsrc ); bson_append_double( bsrc, "d", 3.14 ); bson_finish( bsrc ); ASSERT( bsrc->err == BSON_VALID ); bson_init( b ); bson_append_double( b, "", 3.14 ); /* test empty name (in general) */ bson_iterator_init( &it, bsrc ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_DOUBLE ); ASSERT( bson_iterator_type( &it ) == BSON_DOUBLE ); bson_append_element( b, "d", &it ); bson_append_element( b, 0, &it ); /* test null */ bson_append_element( b, "", &it ); /* test empty name */ bson_finish( b ); ASSERT( b->err == BSON_VALID ); /* bson_print( b ); */ bson_iterator_init( &it, b ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_DOUBLE ); ASSERT( !strcmp( bson_iterator_key( &it ), "" ) ); ASSERT( bson_iterator_double( &it ) == 3.14 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_DOUBLE ); ASSERT( !strcmp( bson_iterator_key( &it ), "d" ) ); ASSERT( bson_iterator_double( &it ) == 3.14 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_DOUBLE ); ASSERT( !strcmp( bson_iterator_key( &it ), "d" ) ); ASSERT( bson_iterator_double( &it ) == 3.14 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_DOUBLE ); ASSERT( !strcmp( bson_iterator_key( &it ), "" ) ); ASSERT( bson_iterator_double( &it ) == 3.14 ); ASSERT( bson_iterator_more( &it ) ); ASSERT( bson_iterator_next( &it ) == BSON_EOO ); ASSERT( !bson_iterator_more( &it ) ); bson_destroy( bsrc ); bson_destroy( b ); } return 0; }
int main(int argc, char *argv[]) { bson_buffer bb; bson b; bson_iterator it, it2, it3; bson_oid_t oid; bson_buffer_init(&bb); bson_append_double(&bb, "d", 3.14); bson_append_string(&bb, "s", "hello"); { bson_buffer *obj = bson_append_start_object(&bb, "o"); bson_buffer *arr = bson_append_start_array(obj, "a"); bson_append_binary(arr, "0", 8, "w\0rld", 5); bson_append_finish_object(arr); bson_append_finish_object(obj); } bson_append_undefined(&bb, "u"); bson_oid_from_string(&oid, "010203040506070809101112"); ASSERT(!memcmp(oid.bytes, "\x001\x002\x003\x004\x005\x006\x007\x008\x009\x010\x011\x012", 12)); bson_append_oid(&bb, "oid", &oid); bson_append_bool(&bb, "b", 1); bson_append_date(&bb, "date", 0x0102030405060708ULL); bson_append_null(&bb, "n"); bson_append_regex(&bb, "r", "^asdf", "imx"); /* no dbref test (deprecated) */ bson_append_code(&bb, "c", "function(){}"); bson_append_symbol(&bb, "symbol", "SYMBOL"); { bson_buffer scope_buf; bson scope; bson_buffer_init(&scope_buf); bson_append_int(&scope_buf, "i", 123); bson_from_buffer(&scope, &scope_buf); bson_append_code_w_scope(&bb, "cws", "function(){return i}", &scope); bson_destroy(&scope); } /* no timestamp test (internal) */ bson_append_long(&bb, "l", 0x1122334455667788ULL); bson_from_buffer(&b, &bb); bson_iterator_init(&it, b.data); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_double); ASSERT(bson_iterator_type(&it) == bson_double); ASSERT(!strcmp(bson_iterator_key(&it), "d")); ASSERT(bson_iterator_double(&it) == 3.14); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_string); ASSERT(bson_iterator_type(&it) == bson_string); ASSERT(!strcmp(bson_iterator_key(&it), "s")); ASSERT(!strcmp(bson_iterator_string(&it), "hello")); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_object); ASSERT(bson_iterator_type(&it) == bson_object); ASSERT(!strcmp(bson_iterator_key(&it), "o")); bson_iterator_subiterator(&it, &it2); ASSERT(bson_iterator_more(&it2)); ASSERT(bson_iterator_next(&it2) == bson_array); ASSERT(bson_iterator_type(&it2) == bson_array); ASSERT(!strcmp(bson_iterator_key(&it2), "a")); bson_iterator_subiterator(&it2, &it3); ASSERT(bson_iterator_more(&it3)); ASSERT(bson_iterator_next(&it3) == bson_bindata); ASSERT(bson_iterator_type(&it3) == bson_bindata); ASSERT(!strcmp(bson_iterator_key(&it3), "0")); ASSERT(bson_iterator_bin_type(&it3) == 8); ASSERT(bson_iterator_bin_len(&it3) == 5); ASSERT(!memcmp(bson_iterator_bin_data(&it3), "w\0rld", 5)); ASSERT(bson_iterator_more(&it3)); ASSERT(bson_iterator_next(&it3) == bson_eoo); ASSERT(bson_iterator_type(&it3) == bson_eoo); ASSERT(!bson_iterator_more(&it3)); ASSERT(bson_iterator_more(&it2)); ASSERT(bson_iterator_next(&it2) == bson_eoo); ASSERT(bson_iterator_type(&it2) == bson_eoo); ASSERT(!bson_iterator_more(&it2)); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_undefined); ASSERT(bson_iterator_type(&it) == bson_undefined); ASSERT(!strcmp(bson_iterator_key(&it), "u")); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_oid); ASSERT(bson_iterator_type(&it) == bson_oid); ASSERT(!strcmp(bson_iterator_key(&it), "oid")); ASSERT(!memcmp(bson_iterator_oid(&it)->bytes, "\x001\x002\x003\x004\x005\x006\x007\x008\x009\x010\x011\x012", 12)); ASSERT(bson_iterator_oid(&it)->ints[0] == oid.ints[0]); ASSERT(bson_iterator_oid(&it)->ints[1] == oid.ints[1]); ASSERT(bson_iterator_oid(&it)->ints[2] == oid.ints[2]); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_bool); ASSERT(bson_iterator_type(&it) == bson_bool); ASSERT(!strcmp(bson_iterator_key(&it), "b")); ASSERT(bson_iterator_bool(&it) == 1); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_date); ASSERT(bson_iterator_type(&it) == bson_date); ASSERT(!strcmp(bson_iterator_key(&it), "date")); ASSERT(bson_iterator_date(&it) == 0x0102030405060708ULL); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_null); ASSERT(bson_iterator_type(&it) == bson_null); ASSERT(!strcmp(bson_iterator_key(&it), "n")); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_regex); ASSERT(bson_iterator_type(&it) == bson_regex); ASSERT(!strcmp(bson_iterator_key(&it), "r")); ASSERT(!strcmp(bson_iterator_regex(&it), "^asdf")); ASSERT(!strcmp(bson_iterator_regex_opts(&it), "imx")); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_code); ASSERT(bson_iterator_type(&it) == bson_code); ASSERT(!strcmp(bson_iterator_key(&it), "c")); ASSERT(!strcmp(bson_iterator_string(&it), "function(){}")); ASSERT(!strcmp(bson_iterator_code(&it), "function(){}")); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_symbol); ASSERT(bson_iterator_type(&it) == bson_symbol); ASSERT(!strcmp(bson_iterator_key(&it), "symbol")); ASSERT(!strcmp(bson_iterator_string(&it), "SYMBOL")); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_codewscope); ASSERT(bson_iterator_type(&it) == bson_codewscope); ASSERT(!strcmp(bson_iterator_key(&it), "cws")); ASSERT(!strcmp(bson_iterator_code(&it), "function(){return i}")); { bson scope; bson_iterator_code_scope(&it, &scope); bson_iterator_init(&it2, scope.data); ASSERT(bson_iterator_more(&it2)); ASSERT(bson_iterator_next(&it2) == bson_int); ASSERT(bson_iterator_type(&it2) == bson_int); ASSERT(!strcmp(bson_iterator_key(&it2), "i")); ASSERT(bson_iterator_int(&it2) == 123); ASSERT(bson_iterator_more(&it2)); ASSERT(bson_iterator_next(&it2) == bson_eoo); ASSERT(bson_iterator_type(&it2) == bson_eoo); ASSERT(!bson_iterator_more(&it2)); } ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_long); ASSERT(bson_iterator_type(&it) == bson_long); ASSERT(!strcmp(bson_iterator_key(&it), "l")); ASSERT(bson_iterator_long(&it) == 0x1122334455667788ULL); ASSERT(bson_iterator_more(&it)); ASSERT(bson_iterator_next(&it) == bson_eoo); ASSERT(bson_iterator_type(&it) == bson_eoo); ASSERT(!bson_iterator_more(&it)); return 0; }
EXPORT int mongo_bson_iterator_bin_type(struct bson_iterator_* i) { return bson_iterator_bin_type((bson_iterator*)i); }
INT32 _appendValue( CHAR delChar, bson_iterator *pIt, CHAR **ppBuffer, INT32 *pCSVSize, BOOLEAN includeBinary, BOOLEAN includeRegex ) { INT32 rc = SDB_OK ; bson_type type = bson_iterator_type( pIt ) ; INT32 tempSize = 0 ; INT32 base64Size = 0 ; INT32 binType = 0 ; CHAR temp[128] = { 0 } ; const CHAR *pTemp = NULL ; CHAR *pBase64 = NULL ; bson_timestamp_t ts; time_t timer ; struct tm psr; if ( type == BSON_DOUBLE || type == BSON_BOOL || type == BSON_NULL || type == BSON_INT || type == BSON_LONG ) { rc = _appendNonString( delChar, pIt, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else { rc = _appendString( delChar, &delChar, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } if ( type == BSON_TIMESTAMP ) { ts = bson_iterator_timestamp( pIt ) ; timer = (time_t)ts.t; local_time( &timer, &psr ) ; tempSize = ossSnprintf ( temp, 64, "%04d-%02d-%02d-%02d.%02d.%02d.%06d", psr.tm_year + 1900, psr.tm_mon + 1, psr.tm_mday, psr.tm_hour, psr.tm_min, psr.tm_sec, ts.i ) ; rc = _appendString( delChar, temp, tempSize, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_DATE ) { timer = bson_iterator_date( pIt ) / 1000 ; local_time( &timer, &psr ) ; tempSize = ossSnprintf ( temp, 64, "%04d-%02d-%02d", psr.tm_year + 1900, psr.tm_mon + 1, psr.tm_mday ) ; rc = _appendString( delChar, temp, tempSize, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_UNDEFINED ) { rc = _appendString( delChar, CSV_STR_UNDEFINED, CSV_STR_UNDEFINED_SIZE, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_MINKEY ) { rc = _appendString( delChar, CSV_STR_MINKEY, CSV_STR_MINKEY_SIZE, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_MAXKEY ) { rc = _appendString( delChar, CSV_STR_MAXKEY, CSV_STR_MAXKEY_SIZE, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_CODE ) { pTemp = bson_iterator_code( pIt ) ; rc = _appendString( delChar, pTemp, ossStrlen( pTemp ), ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_STRING || type == BSON_SYMBOL ) { pTemp = bson_iterator_string( pIt ) ; rc = _appendString( delChar, pTemp, ossStrlen( pTemp ), ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_BINDATA ) { if( TRUE == includeBinary ) { rc = _appendString( delChar, CSV_STR_LEFTBRACKET, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } binType = (INT32)bson_iterator_bin_type( pIt ) ; tempSize = ossSnprintf ( temp, 64, "%d", binType ) ; rc = _appendString( delChar, &temp, tempSize, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } rc = _appendString( delChar, CSV_STR_RIGHTBRACKET, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } pTemp = bson_iterator_bin_data( pIt ) ; tempSize = bson_iterator_bin_len ( pIt ) ; base64Size = getEnBase64Size ( tempSize ) ; pBase64 = (CHAR *)SDB_OSS_MALLOC( base64Size ) ; if( NULL == pBase64 ) { rc = SDB_OOM ; goto error ; } ossMemset( pBase64, 0, base64Size ) ; if ( !base64Encode( pTemp, tempSize, pBase64, base64Size ) ) { rc = SDB_OOM ; goto error ; } rc = _appendString( delChar, pBase64, base64Size - 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_REGEX ) { if( TRUE == includeRegex ) { rc = _appendString( delChar, CSV_STR_BACKSLASH, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } pTemp = bson_iterator_regex( pIt ) ; rc = _appendString( delChar, pTemp, ossStrlen( pTemp ), ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } if( TRUE == includeRegex ) { rc = _appendString( delChar, CSV_STR_BACKSLASH, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } pTemp = bson_iterator_regex_opts( pIt ) ; rc = _appendString( delChar, pTemp, ossStrlen( pTemp ), ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } } else if ( type == BSON_OID ) { bson_oid_to_string( bson_iterator_oid( pIt ), temp ) ; rc = _appendString( delChar, temp, 24, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else { rc = _appendObj( delChar, pIt, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } rc = _appendString( delChar, &delChar, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } done: SAFE_OSS_FREE( pBase64 ) ; return rc ; error: goto done ; }