static int check_bin2(as_record * rec, scan_check * check) { as_val * bin = (as_val *) as_record_get(rec, "bin2"); if ( !bin ) { error("Expected a value in bin('%s'), but got null", "bin2"); return !(check->failed = true); } as_string * string = as_string_fromval(bin); if ( !string ) { error("Expected a string in bin('%s'), but got type %d", "bin2", as_val_type(bin)); return !(check->failed = true); } char * str = as_string_get(string); if ( !str ) { error("Expected a string value but it is NULL"); return !(check->failed = true); } // Check the string bin char expected[SET_STRSZ]; int64_t bin1 = as_record_get_int64(rec, "bin1", INT64_MIN); sprintf(expected, "str-%s-%" PRId64, rec->key.set[0] == '\0' ? "noset" : rec->key.set, bin1); if (strcmp(expected, str) != 0) { error("Expected '%s' in bin('%s'), but got '%s'", expected, "bin2", str); return !(check->failed = true); } return !(check->failed = false); }
void asval_to_clobject(as_val * val, cl_object * obj) { switch(val->type) { case AS_NIL: { citrusleaf_object_init_null(obj); break; } case AS_INTEGER: { as_integer * v = as_integer_fromval(val); citrusleaf_object_init_int(obj, as_integer_toint(v)); break; } case AS_STRING: { as_string * v = as_string_fromval(val); citrusleaf_object_init_str(obj, as_string_get(v)); break; } case AS_BYTES: { as_bytes * v = as_bytes_fromval(val); citrusleaf_object_init_blob2(obj, v->value, v->size, (cl_type)v->type); break; } case AS_LIST:{ as_buffer buffer; as_buffer_init(&buffer); as_serializer ser; as_msgpack_init(&ser); as_serializer_serialize(&ser, val, &buffer); as_serializer_destroy(&ser); citrusleaf_object_init_blob_handoff(obj, buffer.data, buffer.size, CL_LIST); break; } case AS_MAP: { as_buffer buffer; as_buffer_init(&buffer); as_serializer ser; as_msgpack_init(&ser); as_serializer_serialize(&ser, val, &buffer); as_serializer_destroy(&ser); citrusleaf_object_init_blob_handoff(obj, buffer.data, buffer.size, CL_MAP); break; } default: { // raise an error break; } } }