diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-01-25 13:28:38 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-01-25 13:28:38 -0500 |
commit | f7c62462402972b13d10e43f104ca0c0fecb6d08 (patch) | |
tree | 6bf90792ec1a9ada9a5f0ca2f670d36c37260f77 /src/include/utils/jsonb.h | |
parent | 049ac809a790a9bde478e371da2b68d6b18c5df7 (diff) |
Introduce convenience macros to hide JsonbContainer header accesses better.
This improves readability a bit and may make future improvements easier.
In passing, make sure that the JB_ROOT_IS_XXX macros deliver boolean (0/1)
results; the previous coding was a bug hazard, though no actual bugs are
known.
Nikita Glukhov, extended a bit by me
Discussion: https://postgr.es/m/9e21a39c-c1d7-b9b5-44a0-c5345a5029f6@postgrespro.ru
Diffstat (limited to 'src/include/utils/jsonb.h')
-rw-r--r-- | src/include/utils/jsonb.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/include/utils/jsonb.h b/src/include/utils/jsonb.h index e402b9e3a70..411e158d6c1 100644 --- a/src/include/utils/jsonb.h +++ b/src/include/utils/jsonb.h @@ -205,6 +205,12 @@ typedef struct JsonbContainer #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 { @@ -213,10 +219,10 @@ 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 @@ -241,7 +247,7 @@ enum jbvType */ struct JsonbValue { - enum jbvType type; /* Influences sort order */ + enum jbvType type; /* Influences sort order */ union { |