Hello,
I am trying to create Packet table that contains a structure with
variable length buffer and a date.
So far it does not work (crash on memcpy). My environment is VS2005
(windows XP) and I am using HDF5 1.8.4 library.
Here is a description of my structure:
typedef struct s1 {
long long date;
hvl_t data;
} s1;
s1 st;
I am filling the structure with a date and a buffer passed as arguments
of my method
(int TestCompoundDataPT(long long date, unsigned char *buffer, unsigned
int lgdata)
st.date = date;
st.data.len = lgdata;
st.data.p = buffer;
Then, I am filling a hvl_t variable that needs to be passed to
H5PTappend method.
hvl_t writebuffer;
writebuffer.len = sizeof(long long) + lgdata;
writebuffer.p = &st;
Here is the C code I used to create the table:
/* Create a file using default properties */
fid=H5Fcreate("packet_table_compound_VL.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5
P_DEFAULT);
/* Create a variable-length packet table within the file */
ptable = H5PTcreate_vl(fid, "MY_PACKET_TABLE", 1);
if(ptable == H5I_INVALID_HID)
goto out;
/* Write the entire buffer to the packet table */
err = H5PTappend(ptable, 1, writebuffer);
if(err < 0)
goto out;
err = H5PTclose(ptable);
Here is the code for reading back the packet:
hvl_t readbuffer[1];
fid=H5Fopen("packet_table_compound_VL.h5", H5F_ACC_RDONLY,
H5P_DEFAULT);
ptable = H5PTopen(fid, "MY_PACKET_TABLE");
if(ptable == H5I_INVALID_HID)
goto out;
err = H5PTread_packets(ptable, 0, 1, readbuffer);
if(err < 0)
goto out;
memcpy(&st, readbuffer[0].p, readbuffer[0].len);
printf("Read Date: %lld; Packet len: %d; Data= ", st.date,
(int)(st.data.len));
for(j=0; j < (int)st.data.len; j++)
printf("%2.2X ", ((unsigned
char*)st.data.p)[j]);
printf("\n");
err = H5PTfree_vlen_readbuff(ptable, 1, readbuffer);
H5PTclose(ptable);
H5Fclose(fid);
The memcpy will fail because of data alignment in structure.
Does Packet table support structures datatypes? How to solve this
problem with a variable length buffer?
Thanks for you help.
Vincent