diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5Iprivate.h | 2 | ||||
-rw-r--r-- | src/H5Ipublic.h | 1 | ||||
-rw-r--r-- | src/H5MPprivate.h | 2 | ||||
-rw-r--r-- | src/H5O.c | 97 | ||||
-rw-r--r-- | src/H5Odtype.c | 2 | ||||
-rw-r--r-- | src/H5Oprivate.h | 2 | ||||
-rw-r--r-- | src/H5Osdspace.c | 4 | ||||
-rw-r--r-- | src/H5T.c | 148 | ||||
-rw-r--r-- | src/H5Tprivate.h | 2 | ||||
-rw-r--r-- | src/H5Tpublic.h | 2 |
10 files changed, 258 insertions, 4 deletions
diff --git a/src/H5Iprivate.h b/src/H5Iprivate.h index 3f6b65c..2f0bdb8 100644 --- a/src/H5Iprivate.h +++ b/src/H5Iprivate.h @@ -26,6 +26,7 @@ /* Private headers needed by this file */ #include "H5private.h" +#include "H5Oprivate.h" /* Macro to determine if a H5I_type_t is a "library type" */ #define H5I_IS_LIB_TYPE( type ) (type > 0 && type < H5I_NTYPES) @@ -65,4 +66,5 @@ H5_DLL int H5I_dec_ref(hid_t id); H5_DLL int H5I_inc_type_ref(H5I_type_t type); H5_DLL herr_t H5I_dec_type_ref(H5I_type_t type); H5_DLL int H5I_get_type_ref(H5I_type_t type); + #endif diff --git a/src/H5Ipublic.h b/src/H5Ipublic.h index c3015e1..9d76d63 100644 --- a/src/H5Ipublic.h +++ b/src/H5Ipublic.h @@ -96,7 +96,6 @@ H5_DLL void *H5Isearch(H5I_type_t type, H5I_search_func_t func, void *key); H5_DLL herr_t H5Inmembers(H5I_type_t type, hsize_t *num_members); H5_DLL htri_t H5Itype_exists(H5I_type_t type); - #ifdef __cplusplus } #endif diff --git a/src/H5MPprivate.h b/src/H5MPprivate.h index 2062f61..771c836 100644 --- a/src/H5MPprivate.h +++ b/src/H5MPprivate.h @@ -183,6 +183,8 @@ #define color_H5Tcommitted "red" #define color_H5Tinsert "red" #define color_H5Tpack "red" +#define color_H5Tencode "red" +#define color_H5Tdecode "red" #define color_H5Tenum_create "red" #define color_H5Tenum_insert "red" #define color_H5Tenum_nameof "red" @@ -3427,6 +3427,103 @@ done: /*------------------------------------------------------------------------- + * Function: H5O_encode + * + * Purpose: Encode an object(data type and simple data space only) + * description into a buffer. + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 13, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, hid_t type_id) +{ + const H5O_class_t *type; /* Actual H5O class type for the ID */ + size_t size; /* size of the message*/ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_encode,FAIL); + + /* check args */ + if(type_id<0 || type_id>=(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0]))) + HGOTO_ERROR (H5E_ARGS, H5E_BADRANGE, FAIL, "invalid object type"); + + /* map the type ID to the actual type object */ + if((type=message_type_g[type_id])==NULL) + HGOTO_ERROR (H5E_OHDR, H5E_BADTYPE, FAIL, "unable to find object type"); + + /* check buffer size */ + if ((size=(type->raw_size)(NULL, obj))<0) + HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message"); + + /* Don't encode if buffer size isn't big enough */ + if(!buf || *nalloc<size) { + *nalloc = size; + HGOTO_DONE(ret_value); + } + + /* Encode */ + if ((type->encode)(NULL, buf, obj)<0) + HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message"); + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5O_decode + * + * Purpose: Decode a binary object(data type and data space only) + * description and return a new object handle. + * + * Return: Success: Object ID(non-negative) + * + * Failure: Negative + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 14, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void* +H5O_decode(unsigned char *buf, hid_t type_id) +{ + const H5O_class_t *type; /* Actual H5O class type for the ID */ + size_t size; /* size of the message*/ + void *ret_value=NULL; /* Return value */ + + FUNC_ENTER_NOAPI(H5O_decode,NULL); + + /* check args */ + if(type_id<0 || type_id>=(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0]))) + HGOTO_ERROR (H5E_ARGS, H5E_BADRANGE, NULL, "invalid object type"); + + /* map the type ID to the actual type object */ + if((type=message_type_g[type_id])==NULL) + HGOTO_ERROR (H5E_OHDR, H5E_BADTYPE, NULL, "unable to find object type"); + + /* decode */ + ret_value = (type->decode)(NULL, 0, buf, NULL); + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + +/*------------------------------------------------------------------------- * Function: H5O_debug_id * * Purpose: Act as a proxy for calling the 'debug' method for a diff --git a/src/H5Odtype.c b/src/H5Odtype.c index c5a9fe8..3c44b26 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -875,7 +875,7 @@ H5O_dtype_encode(H5F_t UNUSED *f, uint8_t *p, const void *mesg) FUNC_ENTER_NOAPI_NOINIT(H5O_dtype_encode); /* check args */ - assert(f); + /*assert(f);*/ assert(p); assert(dt); diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 8de6392..ab52171 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -249,6 +249,8 @@ H5_DLL herr_t H5O_remove(H5G_entry_t *ent, hid_t type_id, int sequence, hid_t dxpl_id); H5_DLL herr_t H5O_reset(hid_t type_id, void *native); H5_DLL void *H5O_free(hid_t type_id, void *mesg); +H5_DLL herr_t H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, hid_t type_id); +H5_DLL void* H5O_decode(unsigned char *buf, hid_t type_id); H5_DLL void *H5O_copy(hid_t type_id, const void *mesg, void *dst); H5_DLL size_t H5O_raw_size(hid_t type_id, H5F_t *f, const void *mesg); H5_DLL herr_t H5O_get_share(hid_t type_id, H5F_t *f, const void *mesg, H5O_shared_t *share); diff --git a/src/H5Osdspace.c b/src/H5Osdspace.c index e130977..7c4bb80 100644 --- a/src/H5Osdspace.c +++ b/src/H5Osdspace.c @@ -210,7 +210,7 @@ done: --------------------------------------------------------------------------*/ static herr_t -H5O_sdspace_encode(H5F_t *f, uint8_t *p, const void *mesg) +H5O_sdspace_encode(H5F_t UNUSED *f, uint8_t *p, const void *mesg) { const H5S_extent_t *sdim = (const H5S_extent_t *) mesg; unsigned u; /* Local counting variable */ @@ -219,7 +219,7 @@ H5O_sdspace_encode(H5F_t *f, uint8_t *p, const void *mesg) FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_sdspace_encode); /* check args */ - assert(f); + /*assert(f);*/ assert(p); assert(sdim); @@ -2550,6 +2550,84 @@ done: FUNC_LEAVE_API(ret_value); } + +/*------------------------------------------------------------------------- + * Function: H5Tencode + * + * Purpose: Given an datatype ID, converts the object description into + * binary in a buffer. + * + * Return: Success: non-negative + * + * Failure: negative + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 14, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5Tencode(hid_t obj_id, unsigned char* buf, size_t* nalloc) +{ + H5T_t *dtype; + herr_t ret_value; + + FUNC_ENTER_API (H5Tencode, FAIL); + + /* Check argument and retrieve object */ + if (NULL==(dtype=H5I_object_verify(obj_id, H5I_DATATYPE))) + HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") + + ret_value = H5T_encode(dtype, buf, nalloc); + +done: + FUNC_LEAVE_API(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5Tdecode + * + * Purpose: Decode a binary object description and return a new object + * handle. + * + * Return: Success: datatype ID(non-negative) + * + * Failure: negative + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 14, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +H5Tdecode(unsigned char* buf) +{ + H5T_t *dt; + hid_t ret_value; + + FUNC_ENTER_API (H5Tdecode, FAIL); + + if (buf==NULL) + HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "empty buffer") + + if((dt = H5T_decode(buf))==NULL) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "can't decode object"); + + /* Register the type and return the ID */ + if ((ret_value=H5I_register (H5I_DATATYPE, dt))<0) + HGOTO_ERROR (H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register data type"); + +done: + FUNC_LEAVE_API(ret_value); +} + /*------------------------------------------------------------------------- * API functions are above; library-private functions are below... *------------------------------------------------------------------------- @@ -2557,6 +2635,76 @@ done: /*------------------------------------------------------------------------- + * Function: H5T_encode + * + * Purpose: Private function for H5Tencode. Converts an object + * description into binary in a buffer. + * + * Return: Success: non-negative + * + * Failure: negative + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 14, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(H5T_encode, FAIL); + + if(H5O_encode(buf, obj, nalloc, H5O_DTYPE_ID)<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode object"); + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5T_decode + * + * Purpose: Private function for H5Tdecode. Reconstructs a binary + * description of datatype and returns a new object handle. + * + * Return: Success: datatype ID(non-negative) + * + * Failure: negative + * + * Programmer: Raymond Lu + * slu@ncsa.uiuc.edu + * July 14, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +H5T_t* +H5T_decode(unsigned char *buf) +{ + H5T_t *dt; + H5T_t *ret_value; + + FUNC_ENTER_NOAPI(H5T_decode, NULL); + + if((dt = H5O_decode(buf, H5O_DTYPE_ID))==NULL) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode object"); + + /* Set return value */ + ret_value=dt; + +done: + FUNC_LEAVE_NOAPI(ret_value); +} + + +/*------------------------------------------------------------------------- * Function: H5T_create * * Purpose: Creates a new data type and initializes it to reasonable diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h index 965ca93..a8840e7 100644 --- a/src/H5Tprivate.h +++ b/src/H5Tprivate.h @@ -93,6 +93,8 @@ H5_DLL htri_t H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc); H5_DLL htri_t H5T_is_sensible(const H5T_t *dt); H5_DLL htri_t H5T_committed(H5T_t *type); H5_DLL int H5T_link(const H5T_t *type, int adjust, hid_t dxpl_id); +H5_DLL herr_t H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc); +H5_DLL H5T_t *H5T_decode(unsigned char *buf); /* Reference specific functions */ H5_DLL H5R_type_t H5T_get_ref_type(const H5T_t *dt); diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index 3fec470..7e5f8eb 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -485,6 +485,8 @@ H5_DLL htri_t H5Tequal(hid_t type1_id, hid_t type2_id); H5_DLL herr_t H5Tlock(hid_t type_id); H5_DLL herr_t H5Tcommit(hid_t loc_id, const char *name, hid_t type_id); H5_DLL htri_t H5Tcommitted(hid_t type_id); +H5_DLL herr_t H5Tencode(hid_t obj_id, unsigned char* buf, size_t* nalloc); +H5_DLL hid_t H5Tdecode(unsigned char* buf); /* Operations defined on compound datatypes */ H5_DLL herr_t H5Tinsert(hid_t parent_id, const char *name, size_t offset, |