// Retrieves the offset of a field of a compound datatype. // size_t H5Tget_member_offset( hid_t dtype_id, unsigned memb_no ) func (t *CompType) MemberOffset(mbr_idx int) int { return int(C.H5Tget_member_offset(t.id, C.uint(mbr_idx))) }
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 }