@@ -101,7 +101,8 @@ static void appendElement(JsonbParseState *pstate, const JsonbValue *scalarVal);
101
101
static int lengthCompareJsonbPair (const void * a , const void * b , void * arg );
102
102
static void uniqueifyJsonbObject (JsonbValue * object );
103
103
static JsonbValue * pushSingleScalarJsonbValue (JsonbParseState * * pstate ,
104
- const JsonbValue * jbval );
104
+ const JsonbValue * jbval ,
105
+ bool unpackBinary );
105
106
static void jsonbInitContainer (JsonContainerData * jc , JsonbContainer * jbc , int len );
106
107
107
108
JsonValue *
@@ -163,7 +164,7 @@ JsonValueFlatten(const JsonValue *val, JsonValueEncoder encoder,
163
164
if (IsAJsonbScalar (val ))
164
165
{
165
166
JsonbParseState * pstate = NULL ;
166
- val = pushSingleScalarJsonbValue (& pstate , val );
167
+ val = pushSingleScalarJsonbValue (& pstate , val , true );
167
168
}
168
169
else
169
170
{
@@ -695,16 +696,16 @@ JsonbParseStateClone(JsonbParseState *state)
695
696
* are unpacked before being added to the result.
696
697
*/
697
698
JsonbValue *
698
- pushJsonbValue (JsonbParseState * * pstate , JsonbIteratorToken seq ,
699
- const JsonbValue * jbval )
699
+ pushJsonbValueExt (JsonbParseState * * pstate , JsonbIteratorToken seq ,
700
+ const JsonbValue * jbval , bool unpackBinary )
700
701
{
701
702
JsonIterator * it ;
702
703
JsonbValue * res = NULL ;
703
704
JsonbValue v ;
704
705
JsonbIteratorToken tok ;
705
706
706
707
if (!jbval || (seq != WJB_ELEM && seq != WJB_VALUE ) ||
707
- jbval -> type != jbvBinary )
708
+ jbval -> type != jbvBinary || ! unpackBinary )
708
709
{
709
710
/* drop through */
710
711
return pushJsonbValueScalar (pstate , seq , jbval );
@@ -772,7 +773,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
772
773
appendValue (* pstate , scalarVal );
773
774
break ;
774
775
case WJB_ELEM :
775
- Assert (IsAJsonbScalar (scalarVal ));
776
+ /* Assert(IsAJsonbScalar(scalarVal)); */
776
777
appendElement (* pstate , scalarVal );
777
778
break ;
778
779
case WJB_END_OBJECT :
@@ -811,7 +812,8 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
811
812
}
812
813
813
814
static JsonbValue *
814
- pushSingleScalarJsonbValue (JsonbParseState * * pstate , const JsonbValue * jbval )
815
+ pushSingleScalarJsonbValue (JsonbParseState * * pstate , const JsonbValue * jbval ,
816
+ bool unpackBinary )
815
817
{
816
818
/* single root scalar */
817
819
JsonbValue va ;
@@ -821,20 +823,21 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval)
821
823
va .val .array .nElems = 1 ;
822
824
823
825
pushJsonbValue (pstate , WJB_BEGIN_ARRAY , & va );
824
- pushJsonbValue (pstate , WJB_ELEM , jbval );
826
+ pushJsonbValueExt (pstate , WJB_ELEM , jbval , unpackBinary );
825
827
return pushJsonbValue (pstate , WJB_END_ARRAY , NULL );
826
828
}
827
829
828
830
static JsonbValue *
829
831
pushNestedScalarJsonbValue (JsonbParseState * * pstate , const JsonbValue * jbval ,
830
- bool isKey )
832
+ bool isKey , bool unpackBinary )
831
833
{
832
834
switch ((* pstate )-> contVal .type )
833
835
{
834
836
case jbvArray :
835
- return pushJsonbValue (pstate , WJB_ELEM , jbval );
837
+ return pushJsonbValueExt (pstate , WJB_ELEM , jbval , unpackBinary );
836
838
case jbvObject :
837
- return pushJsonbValue (pstate , isKey ? WJB_KEY : WJB_VALUE , jbval );
839
+ return pushJsonbValueExt (pstate , isKey ? WJB_KEY : WJB_VALUE , jbval ,
840
+ unpackBinary );
838
841
default :
839
842
elog (ERROR , "unexpected parent of nested structure" );
840
843
return NULL ;
@@ -843,11 +846,11 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
843
846
844
847
JsonbValue *
845
848
pushScalarJsonbValue (JsonbParseState * * pstate , const JsonbValue * jbval ,
846
- bool isKey )
849
+ bool isKey , bool unpackBinary )
847
850
{
848
851
return * pstate == NULL
849
- ? pushSingleScalarJsonbValue (pstate , jbval )
850
- : pushNestedScalarJsonbValue (pstate , jbval , isKey );
852
+ ? pushSingleScalarJsonbValue (pstate , jbval , unpackBinary )
853
+ : pushNestedScalarJsonbValue (pstate , jbval , isKey , unpackBinary );
851
854
852
855
}
853
856
@@ -2155,5 +2158,5 @@ jsonbContainerOps =
2155
2158
jsonbFindValueInArray ,
2156
2159
jsonbGetArrayElement ,
2157
2160
NULL ,
2158
- JsonbToCString ,
2161
+ JsonbToCStringRaw ,
2159
2162
};
0 commit comments