func initializeStructToGet(object *object, value reflect.Value) error { if tid := C.H5Tget_class(object.tid); tid < 0 { return errors.New("cannot get a data class") } else if tid != C.H5T_COMPOUND { return errors.New("expected a compound datatype") } size := C.H5Tget_size(object.tid) if size < 0 { return errors.New("cannot get the size of a compound datatype") } object.data = C.malloc(size) if object.data == nil { return errors.New("cannot allocate memory") } object.flag |= flagOwnedMemory return nil }
// Returns the size of a datatype. // size_t H5Tget_size( hid_t dtype_id ) func (t *DataType) Size() int { return int(C.H5Tget_size(t.id)) }
// Size returns the size of the Datatype. func (t *Datatype) Size() uint { return uint(C.H5Tget_size(t.id)) }
func finalizeStructToGet(object *object, value reflect.Value) error { typo := value.Type() count := typo.NumField() for i := 0; i < count; i++ { field := typo.Field(i) if len(field.PkgPath) > 0 { continue } cname := C.CString(field.Name) defer C.free(unsafe.Pointer(cname)) j := C.H5Tget_member_index(object.tid, cname) if j < 0 { continue } o := object.new() o.tid = C.H5Tget_member_type(object.tid, C.uint(j)) if o.tid < 0 { return errors.New("cannot get the datatype of a field") } if cid := C.H5Tget_class(o.tid); cid < 0 { return errors.New("cannot get the data class of a field") } else if cid == C.H5T_VLEN { if tid := C.H5Tget_super(o.tid); tid < 0 { // Close? return errors.New("cannot get the base type of a field") } else { o = object.new() o.tid = tid } } if err := initializeToGet(o, value.Field(i)); err != nil { return err } size := C.H5Tget_size(o.tid) if size < 0 { return errors.New("cannot get a size") } offset := C.H5Tget_member_offset(object.tid, C.uint(j)) address := unsafe.Pointer(uintptr(object.data) + uintptr(offset)) if o.flag&flagVariableLength != 0 { h := (*C.hvl_t)(address) if h.len != 1 { return errors.New("expected a variable-length datatype with a single element") } address = h.p } C.memcpy(o.data, address, size) if err := finalizeToGet(o, value.Field(i)); err != nil { return err } } return nil }