#include "utils/memutils.h"
#include "utils/jsonb.h"
-#define JENTRY_ISSTRING (0x00000000)
-#define JENTRY_ISNUMERIC (0x10000000)
-#define JENTRY_ISNEST (0x20000000)
-#define JENTRY_ISNULL (0x40000000)
-#define JENTRY_ISBOOL (0x10000000 | 0x20000000)
-#define JENTRY_ISFALSE JENTRY_ISBOOL
-#define JENTRY_ISTRUE (0x10000000 | 0x20000000 | 0x40000000)
-
-/* Note possible multiple evaluations, also access to prior array element */
-#define JBE_ISFIRST(he_) (((he_).header & JENTRY_ISFIRST) != 0)
-#define JBE_ISSTRING(he_) (((he_).header & JENTRY_TYPEMASK) == JENTRY_ISSTRING)
-#define JBE_ISNUMERIC(he_) (((he_).header & JENTRY_TYPEMASK) == JENTRY_ISNUMERIC)
-#define JBE_ISNEST(he_) (((he_).header & JENTRY_TYPEMASK) == JENTRY_ISNEST)
-#define JBE_ISNULL(he_) (((he_).header & JENTRY_TYPEMASK) == JENTRY_ISNULL)
-#define JBE_ISBOOL(he_) (((he_).header & JENTRY_TYPEMASK & JENTRY_ISBOOL) == JENTRY_ISBOOL)
-#define JBE_ISBOOL_TRUE(he_) (((he_).header & JENTRY_TYPEMASK) == JENTRY_ISTRUE)
-#define JBE_ISBOOL_FALSE(he_) (JBE_ISBOOL(he_) && !JBE_ISBOOL_TRUE(he_))
-
/*
* State used while converting an arbitrary JsonbValue into a Jsonb value
* (4-byte varlena uncompressed representation of a Jsonb)
- */
-
-/*
+ *
* ConvertLevel: Bookkeeping around current level when converting.
*/
typedef struct convertLevel
{
r->type = jbvNumeric;
r->numeric = (Numeric) (data + INTALIGN(JBE_OFF(*e)));
-
r->size = 2 * sizeof(JEntry) + VARSIZE_ANY(r->numeric);
}
else if (JBE_ISNULL(*e))
#include "utils/array.h"
#include "utils/numeric.h"
-#define JENTRY_POSMASK 0x0FFFFFFF
-#define JENTRY_ISFIRST 0x80000000
-#define JENTRY_TYPEMASK (~(JENTRY_POSMASK | JENTRY_ISFIRST))
-
-/*
- * determined by the size of "endpos" (ie JENTRY_POSMASK)
- */
-#define JSONB_MAX_STRING_LEN JENTRY_POSMASK
-
/*
- * It's not possible to get more than 2^28 items into an Jsonb.
+ * JB_CMASK is used to extract count of items
*
- * JB_CMASK is count of items mask
+ * It's not possible to get more than 2^28 items into an Jsonb.
*/
#define JB_CMASK 0x0FFFFFFF
#define JB_ROOT_IS_ARRAY(jbp_) (JB_ISEMPTY(jbp_) ? \
0: ( *(uint32*) VARDATA(jbp_) & JB_FARRAY))
+/* Jentry macros */
+#define JENTRY_POSMASK 0x0FFFFFFF
+#define JENTRY_ISFIRST 0x80000000
+#define JENTRY_TYPEMASK (~(JENTRY_POSMASK | JENTRY_ISFIRST))
+#define JENTRY_ISSTRING (0x00000000)
+#define JENTRY_ISNUMERIC (0x10000000)
+#define JENTRY_ISNEST (0x20000000)
+#define JENTRY_ISNULL (0x40000000)
+#define JENTRY_ISBOOL (0x10000000 | 0x20000000)
+#define JENTRY_ISFALSE JENTRY_ISBOOL
+#define JENTRY_ISTRUE (0x10000000 | 0x20000000 | 0x40000000)
+/* Note possible multiple evaluations, also access to prior array element */
+#define JBE_ISFIRST(je_) (((je_).header & JENTRY_ISFIRST) != 0)
+#define JBE_ISSTRING(je_) (((je_).header & JENTRY_TYPEMASK) == JENTRY_ISSTRING)
+#define JBE_ISNUMERIC(je_) (((je_).header & JENTRY_TYPEMASK) == JENTRY_ISNUMERIC)
+#define JBE_ISNEST(je_) (((je_).header & JENTRY_TYPEMASK) == JENTRY_ISNEST)
+#define JBE_ISNULL(je_) (((je_).header & JENTRY_TYPEMASK) == JENTRY_ISNULL)
+#define JBE_ISBOOL(je_) (((je_).header & JENTRY_TYPEMASK & JENTRY_ISBOOL) == JENTRY_ISBOOL)
+#define JBE_ISBOOL_TRUE(je_) (((je_).header & JENTRY_TYPEMASK) == JENTRY_ISTRUE)
+#define JBE_ISBOOL_FALSE(je_) (JBE_ISBOOL(je_) && !JBE_ISBOOL_TRUE(je_))
+
+/* Get offset for Jentry */
+#define JBE_ENDPOS(je_) ((je_).header & JENTRY_POSMASK)
+#define JBE_OFF(je_) (JBE_ISFIRST(je_) ? 0 : JBE_ENDPOS((&(je_))[-1]))
+#define JBE_LEN(je_) (JBE_ISFIRST(je_) ? \
+ JBE_ENDPOS(je_) \
+ : JBE_ENDPOS(je_) - JBE_ENDPOS((&(je_))[-1]))
+
/* Flags indicating a stage of sequential Jsonb processing */
#define WJB_DONE 0x000
#define WJB_KEY 0x001
#define WJB_BEGIN_OBJECT 0x020
#define WJB_END_OBJECT 0x040
-/* Get offset for Jentry */
-#define JBE_ENDPOS(he_) ((he_).header & JENTRY_POSMASK)
-#define JBE_OFF(he_) (JBE_ISFIRST(he_) ? 0 : JBE_ENDPOS((&(he_))[-1]))
-#define JBE_LEN(he_) (JBE_ISFIRST(he_) ? \
- JBE_ENDPOS(he_) \
- : JBE_ENDPOS(he_) - JBE_ENDPOS((&(he_))[-1]))
-
/*
* When using a GIN index for jsonb, we choose to index both keys and values.
* The storage format is "text" values, with K, V, or N prepended to the string
typedef struct JsonbValue JsonbValue;
typedef char* JsonbSuperHeader;
-
/*
* Jsonbs are varlena objects, so must meet the varlena convention that the
* first int32 of the object contains the total object size in bytes. Be sure
{
enum
{
- /* Scalar types (influences sort order) */
+ /* Scalar types */
jbvNull = 0x0,
jbvString,
jbvNumeric,
jbvObject,
/* Binary form of jbvArray/jbvObject/scalar */
jbvBinary
- } type;
+ } type; /* Influences sort order */
- Size size; /* Estimation size of node (including
+ Size size; /* Estimated size of node (including
* subnodes) */
union
bool boolean;
struct
{
- uint32 len;
+ Size len;
char *val; /* Not necessarily null-terminated */
} string; /* String primitive type */
struct
{
- uint32 len;
+ Size len;
char *data;
} binary;
};
/* Current item in buffer ("nElems-wise" count) */
int i;
-
/*
* Data proper. Note that this points just past end of meta array. We use
* "meta" metadata (Jentrys) with JBE_OFF() macro to find appropriate