JsonbValue *key)
{
JEntry *children = container->children;
- int count = (container->header & JB_CMASK);
+ int count = JsonContainerSize(container);
JsonbValue *result;
Assert((flags & ~(JB_FARRAY | JB_FOBJECT)) == 0);
result = palloc(sizeof(JsonbValue));
- if (flags & JB_FARRAY & container->header)
+ if ((flags & JB_FARRAY) && JsonContainerIsArray(container))
{
char *base_addr = (char *) (children + count);
uint32 offset = 0;
JBE_ADVANCE_OFFSET(offset, children[i]);
}
}
- else if (flags & JB_FOBJECT & container->header)
+ else if ((flags & JB_FOBJECT) && JsonContainerIsObject(container))
{
/* Since this is an object, account for *Pairs* of Jentrys */
char *base_addr = (char *) (children + count * 2);
char *base_addr;
uint32 nelements;
- if ((container->header & JB_FARRAY) == 0)
+ if (!JsonContainerIsArray(container))
elog(ERROR, "not a jsonb array");
- nelements = container->header & JB_CMASK;
+ nelements = JsonContainerSize(container);
base_addr = (char *) &container->children[nelements];
if (i >= nelements)
it = palloc(sizeof(JsonbIterator));
it->container = container;
it->parent = parent;
- it->nElems = container->header & JB_CMASK;
+ it->nElems = JsonContainerSize(container);
/* Array starts just after header */
it->children = container->children;
case JB_FARRAY:
it->dataProper =
(char *) it->children + it->nElems * sizeof(JEntry);
- it->isScalar = (container->header & JB_FSCALAR) != 0;
+ it->isScalar = JsonContainerIsScalar(container);
/* This is either a "raw scalar", or an array */
Assert(!it->isScalar || it->nElems == 1);
uint32 nelements;
/* Container must be array, but make sure */
- if ((container->header & JB_FARRAY) == 0)
+ if (!JsonContainerIsArray(container))
elog(ERROR, "not a jsonb array");
- nelements = container->header & JB_CMASK;
+ nelements = JsonContainerSize(container);
if (-lindex > nelements)
PG_RETURN_NULL();
#define JB_FOBJECT 0x20000000
#define JB_FARRAY 0x40000000
+/* convenience macros for accessing a JsonbContainer struct */
+#define JsonContainerSize(jc) ((jc)->header & JB_CMASK)
+#define JsonContainerIsScalar(jc) (((jc)->header & JB_FSCALAR) != 0)
+#define JsonContainerIsObject(jc) (((jc)->header & JB_FOBJECT) != 0)
+#define JsonContainerIsArray(jc) (((jc)->header & JB_FARRAY) != 0)
+
/* The top-level on-disk format for a jsonb datum. */
typedef struct
{
} Jsonb;
/* convenience macros for accessing the root container in a Jsonb datum */
-#define JB_ROOT_COUNT(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_CMASK)
-#define JB_ROOT_IS_SCALAR(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_FSCALAR)
-#define JB_ROOT_IS_OBJECT(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_FOBJECT)
-#define JB_ROOT_IS_ARRAY(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_FARRAY)
+#define JB_ROOT_COUNT(jbp_) (*(uint32 *) VARDATA(jbp_) & JB_CMASK)
+#define JB_ROOT_IS_SCALAR(jbp_) ((*(uint32 *) VARDATA(jbp_) & JB_FSCALAR) != 0)
+#define JB_ROOT_IS_OBJECT(jbp_) ((*(uint32 *) VARDATA(jbp_) & JB_FOBJECT) != 0)
+#define JB_ROOT_IS_ARRAY(jbp_) ((*(uint32 *) VARDATA(jbp_) & JB_FARRAY) != 0)
enum jbvType
*/
struct JsonbValue
{
- enum jbvType type; /* Influences sort order */
+ enum jbvType type; /* Influences sort order */
union
{