diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2004-07-21 21:30:26 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2004-07-21 21:30:26 (GMT) |
commit | 7fe5ff1fed0e689486ef0ee46f44d56cf24a1df8 (patch) | |
tree | 555f3327b4a09f973f408d857f126abcb762937f /src/H5O.c | |
parent | c8daece13b12f9023ed7b1433b344dde9d04d2e0 (diff) | |
download | hdf5-7fe5ff1fed0e689486ef0ee46f44d56cf24a1df8.zip hdf5-7fe5ff1fed0e689486ef0ee46f44d56cf24a1df8.tar.gz hdf5-7fe5ff1fed0e689486ef0ee46f44d56cf24a1df8.tar.bz2 |
[svn-r8921] Purpose: new feature
Description: This is the second step of checkin for encoding and decoding objects.
H5Tencode and H5Tdecode have been committed in the previous step. H5Sencode
and H5Sdecode are checked in this time.
Solution: Given object ID, these functions encode and decode object information
into and from binary buffer and return new object ID. They take advantage of the
existing codes of object header message and encode in the same format.
Platforms tested: fuss and h5committest.
Misc. update: RELEASE.txt
Diffstat (limited to 'src/H5O.c')
-rw-r--r-- | src/H5O.c | 54 |
1 files changed, 37 insertions, 17 deletions
@@ -3444,10 +3444,11 @@ done: *------------------------------------------------------------------------- */ herr_t -H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, unsigned type_id) +H5O_encode(unsigned char *buf, void *obj, hid_t type_id) { const H5O_class_t *type; /* Actual H5O class type for the ID */ - size_t size; /* size of the message*/ + size_t extent_size; /* size of the message*/ + H5F_t f; /* fake file structure*/ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5O_encode,FAIL); @@ -3457,19 +3458,23 @@ H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, unsigned type_id) type=message_type_g[type_id]; /* map the type ID to the actual type object */ assert(type); - /* check buffer size */ - if ((size=(type->raw_size)(NULL, obj))<=0) + if(type_id == H5O_SDSPACE_ID) { + /* Fake file structure, needed for space encoding and decoding. */ + f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t)); + f.shared->sizeof_size = H5F_CRT_OBJ_BYTE_NUM_DEF; + + /* Encode this "size of size" */ + *buf = H5F_CRT_OBJ_BYTE_NUM_DEF; + buf++; + } + + /* Encode */ + if ((type->encode)(&f, buf, 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; - else { - /* Encode */ - if ((type->encode)(NULL, buf, obj)<0) - HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message"); - } /* end else */ - + if(type_id == H5O_SDSPACE_ID) + H5MM_free(f.shared); + done: FUNC_LEAVE_NOAPI(ret_value); } @@ -3481,9 +3486,9 @@ done: * Purpose: Decode a binary object(data type and data space only) * description and return a new object handle. * - * Return: Success: Object ID(non-negative) + * Return: Success: Pointer to object(data type or space) * - * Failure: Negative + * Failure: NULL * * Programmer: Raymond Lu * slu@ncsa.uiuc.edu @@ -3497,7 +3502,8 @@ void* H5O_decode(unsigned char *buf, unsigned type_id) { const H5O_class_t *type; /* Actual H5O class type for the ID */ - void *ret_value; /* Return value */ + H5F_t f; /* fake file structure*/ + void *ret_value=NULL; /* Return value */ FUNC_ENTER_NOAPI(H5O_decode,NULL); @@ -3506,8 +3512,22 @@ H5O_decode(unsigned char *buf, unsigned type_id) type=message_type_g[type_id]; /* map the type ID to the actual type object */ assert(type); + if(type_id == H5O_SDSPACE_ID) { + /* Fake file structure, needed for space encoding and decoding. */ + f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t)); + + /* Decode the "size of size", needed for space encoding and decoding */ + f.shared->sizeof_size = *buf; + buf++; + } + /* decode */ - ret_value = (type->decode)(NULL, 0, buf, NULL); + if((ret_value = (type->decode)(&f, 0, buf, NULL))==NULL) + HGOTO_ERROR (H5E_OHDR, H5E_CANTDECODE, NULL, "unable to decode message"); + + if(type_id == H5O_SDSPACE_ID) { + H5MM_free(f.shared); + } done: FUNC_LEAVE_NOAPI(ret_value); |