func checkArrayType(tid C.hid_t, bid C.hid_t) error { if cid := C.H5Tget_class(tid); cid < 0 { return errors.New("cannot get a data class") } else if cid != C.H5T_ARRAY { return errors.New("expected an array datatype") } if tid := C.H5Tget_super(tid); tid < 0 { // Close? return errors.New("cannot get the base type of a datatype") } else if C.H5Tequal(bid, tid) == 0 { return errors.New("the types do not match") } return nil }
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 }
// Class returns the TypeClass of the DataType func (t *Datatype) Class() TypeClass { return TypeClass(C.H5Tget_class(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 }