示例#1
0
文件: h5a.go 项目: jonlawlor/go-hdf5
// Write writes raw data from a buffer to an attribute.
func (s *Attribute) Write(data interface{}, dtype *Datatype) error {
	var addr unsafe.Pointer
	v := reflect.ValueOf(data)
	switch v.Kind() {

	case reflect.Array:
		addr = unsafe.Pointer(v.UnsafeAddr())

	case reflect.String:
		str := (*reflect.StringHeader)(unsafe.Pointer(v.UnsafeAddr()))
		addr = unsafe.Pointer(str.Data)

	case reflect.Ptr:
		addr = unsafe.Pointer(v.Pointer())

	default:
		addr = unsafe.Pointer(v.UnsafeAddr())
	}

	rc := C.H5Awrite(s.id, dtype.id, addr)
	err := h5err(rc)
	return err
}
示例#2
0
文件: h5a.go 项目: sbinet/go-hdf5
// Write writes raw data from a buffer to an attribute.
func (s *Attribute) Write(data interface{}, dtype *Datatype) error {
	var addr unsafe.Pointer
	v := reflect.Indirect(reflect.ValueOf(data))
	switch v.Kind() {

	case reflect.Array:
		addr = unsafe.Pointer(v.UnsafeAddr())

	case reflect.String:
		str := C.CString(v.Interface().(string))
		defer C.free(unsafe.Pointer(str))
		addr = unsafe.Pointer(&str)

	case reflect.Ptr:
		addr = unsafe.Pointer(v.Pointer())

	default:
		addr = unsafe.Pointer(v.UnsafeAddr())
	}

	rc := C.H5Awrite(s.id, dtype.id, addr)
	err := h5err(rc)
	return err
}