MCPcopy Create free account
hub / github.com/MariaDB/server / Serialize

Method Serialize

storage/connect/bson.cpp:592–663  ·  view source on GitHub ↗

/ Serialize a BJSON document tree: */ /

Source from the content-addressed store, hash-verified

590/* Serialize a BJSON document tree: */
591/***********************************************************************/
592PSZ BDOC::Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty)
593{
594 PSZ str = NULL;
595 bool b = false, err = true;
596 FILE* fs = NULL;
597
598 G->Message[0] = 0;
599
600 try {
601 if (!bvp) {
602 safe_strcpy(g->Message, sizeof(g->Message), "Null json tree");
603 throw 1;
604 } else if (!fn) {
605 // Serialize to a string
606 jp = new(g) JOUTSTR(g);
607 b = pretty == 1;
608 } else {
609 if (!(fs = fopen(fn, "wb"))) {
610 snprintf(g->Message, sizeof(g->Message), MSG(OPEN_MODE_ERROR) ": %s",
611 "w", (int)errno, fn, strerror(errno));
612 throw 2;
613 } else if (pretty >= 2) {
614 // Serialize to a pretty file
615 jp = new(g)JOUTPRT(g, fs);
616 } else {
617 // Serialize to a flat file
618 b = true;
619 jp = new(g)JOUTFILE(g, fs, pretty);
620 } // endif's
621
622 } // endif's
623
624 switch (bvp->Type) {
625 case TYPE_JAR:
626 err = SerializeArray(bvp->To_Val, b);
627 break;
628 case TYPE_JOB:
629 err = ((b && jp->Prty()) && jp->WriteChr('\t'));
630 err |= SerializeObject(bvp->To_Val);
631 break;
632 case TYPE_JVAL:
633 err = SerializeValue(MVP(bvp->To_Val));
634 break;
635 default:
636 err = SerializeValue(bvp, true);
637 } // endswitch Type
638
639 if (fs) {
640 fputs(EL, fs);
641 fclose(fs);
642 str = (err) ? NULL : strcpy(g->Message, "Ok");
643 } else if (!err) {
644 str = ((JOUTSTR*)jp)->Strp;
645 jp->WriteChr('\0');
646 PlugSubAlloc(g, NULL, ((JOUTSTR*)jp)->N);
647 } else if (G->Message[0])
648 strcpy(g->Message, "Error in Serialize");
649 else

Callers 15

bsonvalueFunction · 0.45
bson_make_arrayFunction · 0.45
bson_make_objectFunction · 0.45
bson_object_nonullFunction · 0.45
bson_object_keyFunction · 0.45
bson_object_listFunction · 0.45
bson_object_valuesFunction · 0.45
bson_array_grpFunction · 0.45
bson_object_grpFunction · 0.45
bson_testFunction · 0.45
bson_get_itemFunction · 0.45
bson_fileFunction · 0.45

Calls 5

safe_strcpyFunction · 0.85
PlugSubAllocFunction · 0.85
PrtyMethod · 0.80
WriteChrMethod · 0.80
htrcFunction · 0.70

Tested by

no test coverage detected