Commit 5e4ced97 authored by BenceJanosSzabo's avatar BenceJanosSzabo
Browse files

Implemented json2bson and bson2json (Bug 519755)



Change-Id: Ieaa55c3625746aff9e56820ba3a733c136f0a51a
Signed-off-by: default avatarBenceJanosSzabo <bence.janos.szabo@ericsson.com>
parent 7ffd25a8
......@@ -183,6 +183,7 @@ namespace Common {
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -196,6 +197,7 @@ namespace Common {
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......@@ -534,6 +536,7 @@ namespace Common {
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -547,6 +550,7 @@ namespace Common {
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......@@ -939,6 +943,7 @@ namespace Common {
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -952,6 +957,7 @@ namespace Common {
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......@@ -1726,6 +1732,7 @@ namespace Common {
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -1739,6 +1746,7 @@ namespace Common {
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......@@ -1973,6 +1981,7 @@ namespace Common {
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -1986,6 +1995,7 @@ namespace Common {
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......@@ -2342,6 +2352,7 @@ namespace Common {
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -2355,6 +2366,7 @@ namespace Common {
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......@@ -3536,6 +3548,7 @@ namespace Common {
case OPTYPE_OCT2UNICHAR:
case OPTYPE_ENCVALUE_UNICHAR:
case OPTYPE_ANY2UNISTR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
return Type::T_USTR;
case OPTYPE_INT2BIT:
......@@ -3550,6 +3563,7 @@ namespace Common {
case OPTYPE_STR2HEX:
return Type::T_HSTR;
case OPTYPE_INT2OCT:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_CHAR2OCT:
case OPTYPE_HEX2OCT:
......@@ -3826,6 +3840,8 @@ namespace Common {
return "bit2oct()";
case OPTYPE_BIT2STR:
return "bit2str()";
case OPTYPE_BSON2JSON:
return "bson2json()";
case OPTYPE_CBOR2JSON:
return "cbor2json()";
case OPTYPE_CHAR2INT:
......@@ -3852,6 +3868,8 @@ namespace Common {
return "int2str()";
case OPTYPE_INT2UNICHAR:
return "int2unichar()";
case OPTYPE_JSON2BSON:
return "json2bson()";
case OPTYPE_JSON2CBOR:
return "json2cbor()";
case OPTYPE_OCT2BIT:
......@@ -6994,6 +7012,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
}
break;
case OPTYPE_OCT2BIT:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_OCT2HEX:
case OPTYPE_OCT2STR:
......@@ -7111,6 +7130,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
chk_expr_eval_value(v1, t_chk, refch, exp_val);
}
break;
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR: // v1
v1=u.expr.v1;
{
......@@ -7859,6 +7879,8 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_ISTEMPLATEKIND: // ti1 v2
case OPTYPE_CBOR2JSON: // v1
case OPTYPE_JSON2CBOR: // v1
case OPTYPE_BSON2JSON: // v1
case OPTYPE_JSON2BSON: // v1
break;
case OPTYPE_TESTCASENAME: { // -
if (!my_scope) FATAL_ERROR("Value::evaluate_value()");
......@@ -9163,6 +9185,8 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_ISTEMPLATEKIND: // ti1 v2
case OPTYPE_CBOR2JSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_BSON2JSON:
case OPTYPE_JSON2BSON:
return true;
case OPTYPE_COMP_NULL: // -
return false;
......@@ -10396,6 +10420,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -10409,6 +10434,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......@@ -10808,6 +10834,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_BIT2INT: // v1
case OPTYPE_BIT2OCT: // v1
case OPTYPE_BIT2STR: // v1
case OPTYPE_BSON2JSON: // v1
case OPTYPE_CBOR2JSON: // v1
case OPTYPE_CHAR2INT: // v1
case OPTYPE_CHAR2OCT: // v1
......@@ -10821,6 +10848,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_INT2FLOAT: // v1
case OPTYPE_INT2STR: // v1
case OPTYPE_INT2UNICHAR: // v1
case OPTYPE_JSON2BSON: // v1
case OPTYPE_JSON2CBOR: // v1
case OPTYPE_OCT2BIT: // v1
case OPTYPE_OCT2CHAR: // v1
......@@ -11212,6 +11240,8 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
return create_stringRepr_predef1("bit2oct");
case OPTYPE_BIT2STR:
return create_stringRepr_predef1("bit2str");
case OPTYPE_BSON2JSON:
return create_stringRepr_predef1("bson2json");
case OPTYPE_CBOR2JSON:
return create_stringRepr_predef1("cbor2json");
case OPTYPE_CHAR2INT:
......@@ -11236,6 +11266,8 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
return create_stringRepr_predef1("int2float");
case OPTYPE_INT2STR:
return create_stringRepr_predef1("int2str");
case OPTYPE_JSON2BSON:
return create_stringRepr_predef1("json2bson");
case OPTYPE_JSON2CBOR:
return create_stringRepr_predef1("json2cbor");
case OPTYPE_INT2UNICHAR:
......@@ -12211,6 +12243,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -12224,6 +12257,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......@@ -12518,6 +12552,9 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_BIT2STR:
generate_code_expr_predef1(expr, "bit2str", u.expr.v1);
break;
case OPTYPE_BSON2JSON:
generate_code_expr_predef1(expr, "bson2json", u.expr.v1);
break;
case OPTYPE_CBOR2JSON:
generate_code_expr_predef1(expr, "cbor2json", u.expr.v1);
break;
......@@ -12557,6 +12594,9 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_INT2UNICHAR:
generate_code_expr_predef1(expr, "int2unichar", u.expr.v1);
break;
case OPTYPE_JSON2BSON:
generate_code_expr_predef1(expr, "json2bson", u.expr.v1);
break;
case OPTYPE_JSON2CBOR:
generate_code_expr_predef1(expr, "json2cbor", u.expr.v1);
break;
......@@ -14665,6 +14705,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_BIT2INT:
case OPTYPE_BIT2OCT:
case OPTYPE_BIT2STR:
case OPTYPE_BSON2JSON:
case OPTYPE_CBOR2JSON:
case OPTYPE_CHAR2INT:
case OPTYPE_CHAR2OCT:
......@@ -14678,6 +14719,7 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
case OPTYPE_INT2FLOAT:
case OPTYPE_INT2STR:
case OPTYPE_INT2UNICHAR:
case OPTYPE_JSON2BSON:
case OPTYPE_JSON2CBOR:
case OPTYPE_OCT2BIT:
case OPTYPE_OCT2CHAR:
......
......@@ -275,6 +275,8 @@ namespace Common {
OPTYPE_CBOR2JSON, // v1
OPTYPE_JSON2CBOR, // v1
OPTYPE_BSON2JSON, // v1
OPTYPE_JSON2BSON, // v1
NUMBER_OF_OPTYPES // must be last
};
......
......@@ -540,6 +540,7 @@ bit2hex RETURN(bit2hexKeyword);
bit2int RETURN(bit2intKeyword);
bit2oct RETURN(bit2octKeyword);
bit2str RETURN(bit2strKeyword);
bson2json RETURN(bson2JsonKeyword);
cbor2json RETURN(cbor2JsonKeyword);
char2int RETURN(char2intKeyword);
char2oct RETURN(char2octKeyword);
......@@ -563,6 +564,7 @@ isbound RETURN(isboundKeyword);
ischosen RETURN(ischosenKeyword);
ispresent RETURN(ispresentKeyword);
istemplatekind RETURN(istemplatekindKeyword);
json2bson RETURN(json2bsonKeyword);
json2cbor RETURN(json2CborKeyword);
lengthof RETURN(lengthofKeyword);
oct2bit RETURN(oct2bitKeyword);
......
......@@ -837,6 +837,7 @@ static const string anyname("anytype");
%token bit2intKeyword
%token bit2octKeyword
%token bit2strKeyword
%token bson2JsonKeyword
%token cbor2JsonKeyword
%token char2intKeyword
%token char2octKeyword
......@@ -859,6 +860,7 @@ static const string anyname("anytype");
%token ischosenKeyword
%token ispresentKeyword
%token istemplatekindKeyword
%token json2bsonKeyword
%token json2CborKeyword
%token lengthofKeyword
%token oct2bitKeyword
......@@ -9874,6 +9876,7 @@ PredefinedOpKeyword1:
| bit2octKeyword { $$ = Value::OPTYPE_BIT2OCT; }
| bit2strKeyword { $$ = Value::OPTYPE_BIT2STR; }
| cbor2JsonKeyword { $$ = Value::OPTYPE_CBOR2JSON; }
| bson2JsonKeyword { $$ = Value::OPTYPE_BSON2JSON; }
| char2intKeyword { $$ = Value::OPTYPE_CHAR2INT; }
| char2octKeyword { $$ = Value::OPTYPE_CHAR2OCT; }
| float2intKeyword { $$ = Value::OPTYPE_FLOAT2INT; }
......@@ -9887,6 +9890,7 @@ PredefinedOpKeyword1:
| int2strKeyword { $$ = Value::OPTYPE_INT2STR; }
| int2unicharKeyword { $$ = Value::OPTYPE_INT2UNICHAR; }
| json2CborKeyword { $$ = Value::OPTYPE_JSON2CBOR; }
| json2bsonKeyword { $$ = Value::OPTYPE_JSON2BSON; }
| oct2bitKeyword { $$ = Value::OPTYPE_OCT2BIT; }
| oct2charKeyword { $$ = Value::OPTYPE_OCT2CHAR; }
| oct2hexKeyword { $$ = Value::OPTYPE_OCT2HEX; }
......
......@@ -3170,3 +3170,31 @@ UNIVERSAL_CHARSTRING cbor2json(const OCTETSTRING& value) {
result.decode_utf8(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer());
return result;
}
UNIVERSAL_CHARSTRING bson2json(const OCTETSTRING& value) {
UNIVERSAL_CHARSTRING result;
TTCN_Buffer buff;
buff.put_os(value);
JSON_Tokenizer tok;
bson2json_coding(buff, tok, false, false);
result.decode_utf8(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer());
return result;
}
OCTETSTRING json2bson(const UNIVERSAL_CHARSTRING& value) {
OCTETSTRING result;
TTCN_Buffer buff;
value.encode_utf8(buff);
const unsigned char* ustr = buff.get_data();
const size_t ustr_len = buff.get_len();
char* json_str = mcopystr((const char*)ustr);
JSON_Tokenizer tok(json_str, ustr_len);
Free(json_str);
buff.clear();
INTEGER length = 0;
CHARSTRING cs;
bool is_special;
json2bson_coding(buff, tok, false, false, length, cs, is_special);
buff.get_string(result);
return result;
}
......@@ -488,4 +488,7 @@ extern OCTETSTRING decode_base64(const CHARSTRING& b64);
extern OCTETSTRING json2cbor(const UNIVERSAL_CHARSTRING& value);
extern UNIVERSAL_CHARSTRING cbor2json(const OCTETSTRING& value);
extern OCTETSTRING json2bson(const UNIVERSAL_CHARSTRING& value);
extern UNIVERSAL_CHARSTRING bson2json(const OCTETSTRING& value);
#endif
This diff is collapsed.
......@@ -18,6 +18,8 @@
class TTCN_Buffer;
class JSON_Tokenizer;
class CHARSTRING;
class INTEGER;
/** Descriptor for JSON encoding/decoding during runtime */
struct TTCN_JSONdescriptor_t
......@@ -145,5 +147,9 @@ enum json_metainfo_t {
void json2cbor_coding(TTCN_Buffer& buff, JSON_Tokenizer& tok, size_t& num_of_items);
void cbor2json_coding(TTCN_Buffer& buff, JSON_Tokenizer& tok, bool in_object);
// Functions for conversion between json and bson and vice versa
void json2bson_coding(TTCN_Buffer& buff, JSON_Tokenizer& tok, bool in_object, bool in_array, INTEGER& length, CHARSTRING& f_name, bool& is_special);
void bson2json_coding(TTCN_Buffer& buff, JSON_Tokenizer& tok, bool in_object, bool in_array);
#endif /* JSON_HH_ */
......@@ -16,5 +16,7 @@ Types*.cc
Types*.hh
Cbor*.cc
Cbor*.hh
Bson*.cc
Bson*.hh
logs
compile
module Bson {
type component EmptyCT {
}
testcase tc_bson_encdec() runs on EmptyCT {
var octetstring os, expected_os;
var universal charstring json, decoded, decoded_json;
json := "{}"
expected_os := '0500000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"a\":\"b\"}"
expected_os := '0E00000002610002000000620000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"aaaab\":\"bbbbbbc\"}"
expected_os := '180000000261616161620008000000626262626262630000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"ááá\":\"óóó\"}"
expected_os := '1800000002C3A1C3A1C3A10007000000C3B3C3B3C3B30000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"a\":\"b\",\"c\":\"d\"}"
expected_os := '1700000002610002000000620002630002000000640000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"a\":1}"
expected_os := '0C0000001061000100000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":15614615}"
expected_os := '0E00000010616263009742EE0000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":-15614615}"
expected_os := '0E000000106162630069BD11FF00'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":4586797657}"
expected_os := '12000000126162630059FA64110100000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":-4586797657}"
expected_os := '120000001261626300A7059BEEFEFFFFFF00'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":1.120000}"
expected_os := '090000000161626300EC51B81E85EBF13F00'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":-11321.120465}"
expected_os := '090000000161626300A8A9656B8F1CC6C000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":true}"
expected_os := '0900000008616263000100'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":false}"
expected_os := '0900000008616263000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":null}"
expected_os := '090000000A6162630000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":[1]}"
expected_os := '1600000004616263000C000000103000010000000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":[1,2,\"abc\"]}"
expected_os := '2800000004616263001E000000103000010000001031000200000002320004000000616263000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":[1,2,[3,4],\"abc\"]}"
expected_os := '3E00000004616263003400000010300001000000103100020000000432001300000010300003000000103100040000000002320004000000616263000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":{\"def\":4}}"
expected_os := '1800000003616263000E0000001064656600040000000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":{\"a\":[2]}}"
expected_os := '1E0000000361626300140000000461000C00000010300002000000000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":[2,{\"a\":4}]}"
expected_os := '2500000004616263001B000000103000020000000331000C00000010610004000000000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}
json := "{\"abc\":{\"def\":4,\"dd\":[1,2,3,{\"q\":3},3]},\"w\":[{\"a\":3}]}"
expected_os := '6300000003616263004200000010646566000400000004646400300000001030000100000010310002000000103200030000000333000C0000001071000300000000103400030000000000047700140000000330000C00000010610003000000000000'O;
os := json2bson(json);log(os);
if (not match(os, expected_os)) {
setverdict(fail, match(os, expected_os));
}
decoded := bson2json(os);
if (not match(decoded, json)) {
setverdict(fail, match(decoded, json));
}