netcdf-c/libnczarr/obsolete/zjson.h
Dennis Heimbigner d953899559 Move to Version 2 NCZarr Extended Meta-Data
re: https://github.com/zarr-developers/zarr-specs/issues/41

After discussions with the Zarr community, it was decided to
convert to a new representation of the NCZarr meta-data extensions: version 2.
These extensions store information necessary to mapping the Zarr data model
to the netcdf-4 data model.

The basic change is to remove the NCZarr specific objects: .nczarr, .nczgroup, .nczarray, and .nczattr.
The contents of these objects is moved into the corresponding existing Zarr objects as special keys. The mapping is as follows:

* ''.nczarr'' => ''/.zgroup/_NCZARR_SUPERBLOCK_''
* ''.nczgroup => ''.zgroup/_NCZARR_GROUP_''
* ''.nczarray => ''.zarray/_NCZARR_ARRAY_''
* ''.nczattr => ''.zattr/_NCZARR_ATTR_''

Backward compatibility is maintained by looking for the object ''/.nczarr''
and if found, then assuming that the dataset is in the older version 1 format.
This compatibility only supports reading of such version 1 datasets.

Documentation and test cases are also added.

Misc. Other Changes:
1. The json parsing code was added to the general library instead of nczarr only (ncjson.c, ncjson.h).
2. Improved support for different platform paths by allowing conversion
   to a single common path representation.
3. Add some new error codes.
4. Modify nccopy usage to mention the new chunking specification.
2021-07-17 16:55:30 -06:00

94 lines
2.6 KiB
C

/* Copyright 2018, UCAR/Unidata.
See the COPYRIGHT file for more information.
*/
#ifndef NCJSON_H
#define NCJSON_H 1
#include "ncexternl.h"
/* Json object sorts */
#define NCJ_UNDEF 0
#define NCJ_STRING 1
#define NCJ_INT 2
#define NCJ_DOUBLE 3
#define NCJ_BOOLEAN 4
#define NCJ_DICT 5
#define NCJ_ARRAY 6
#define NCJ_NULL 7
/* Don't bother with unions: define
a struct to store primitive values
as unquoted strings. Sort will
provide more info.
Also, this does not use a true hashmap
but rather an envv style list where name
and value alternate. This works under
the assumption that we are generally
iterating over the Dict rather than
probing it.
*/
typedef struct NCjson {
int sort;
char* value;
NClist* contents; /* For array|dict */
} NCjson;
#define NCJF_MULTILINE 1
/* Parse */
EXTERNL int NCJparse(const char* text, unsigned flags, NCjson** jsonp);
/* Build */
EXTERNL int NCJnew(int sort, NCjson** object);
/* Convert a nul terminated string value to an NCjson object */
EXTERNL int NCJnewstring(int sort, const char* value, NCjson** jsonp);
/* Convert a counted string value to an NCjson object (+ nul term)*/
EXTERNL int NCJnewstringn(int sort, size_t len, const char* value, NCjson** jsonp);
/* Insert key-value pair into a dict object.
key will be strdup'd.
*/
EXTERNL int NCJinsert(NCjson* object, char* key, NCjson* value);
/* Remove a key-value pair from a dict object.
*/
EXTERNL int NCJremove(NCjson* object, char* key, NCjson** keyp, NCjson** valuep);
/* Insert a string value into a json Dict|Array */
EXTERNL int NCJaddstring(NCjson* dictarray, int sort, const char* value);
/* Get ith pair from dict */
EXTERNL int NCJdictith(NCjson* object, size_t i, NCjson** keyp, NCjson** valuep);
/* Get value for key from dict */
EXTERNL int NCJdictget(NCjson* object, const char* key, NCjson** valuep);
/* Append value to an array or dict object. */
EXTERNL int NCJappend(NCjson* object, NCjson* value);
/* Get ith element from array */
EXTERNL int NCJarrayith(NCjson* object, size_t i, NCjson** valuep);
/* Unparser to convert NCjson object to text in buffer */
EXTERNL int NCJunparse(const NCjson* json, int flags, char** textp);
/* Utilities */
EXTERNL void NCJreclaim(NCjson*);
EXTERNL int NCJclone(NCjson* json, NCjson** clonep); /* deep clone */
/* dump NCjson* object */
EXTERNL void NCJdump(const NCjson* json, int flags);
/* Macro defined functions */
#define NCJlength(json) \
((json)->sort == NCJ_DICT ? (nclistlength((json)->contents)/2) \
: ((json)->sort == NCJ_ARRAY ? (nclistlength((json)->contents)) \
: 1))
#endif /*NCJSON_H*/