12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package go_zrfu
- import (
- "io"
- "unsafe"
- )
- var _ = io.ReadWriter(&BytesVec{})
- type BytesVec struct {
- lib *ZRFUDyLib
- h uint64
- }
- func NewBytesVec(lib *ZRFUDyLib) (*BytesVec, error) {
- v := &BytesVec{
- lib: lib,
- h: 0,
- }
- var hbuf uint64
- hptr := uintptr(unsafe.Pointer(&hbuf))
- _, err := lib.procCall(lib.procBVNew, hptr)
- if err != nil {
- return nil, err
- }
- v.h = hbuf
- return v, nil
- }
- func (b BytesVec) Read(p []byte) (n int, err error) {
- hptr := uintptr(unsafe.Pointer(&b.h))
- l := len(p)
- bufptr := uintptr(unsafe.Pointer(&p[0]))
- r, err := b.lib.procCall(b.lib.procBVRead, hptr, bufptr, uintptr(l))
- if err != nil {
- return 0, err
- }
- if r == 0 {
- return 0, io.EOF
- }
- return int(r), nil
- }
- func (b BytesVec) Write(p []byte) (n int, err error) {
- hptr := uintptr(unsafe.Pointer(&b.h))
- l := len(p)
- bufptr := uintptr(unsafe.Pointer(&p[0]))
- r, err := b.lib.procCall(b.lib.procBVWrite, hptr, bufptr, uintptr(l))
- if err != nil {
- return 0, err
- }
- return int(r), nil
- }
- func (b BytesVec) Close() error {
- hptr := uintptr(unsafe.Pointer(&b.h))
- _, err := b.lib.procCall(b.lib.procBVDel, hptr)
- if err != nil {
- return err
- }
- return nil
- }
- func (b BytesVec) Len() (int, error) {
- hptr := uintptr(unsafe.Pointer(&b.h))
- l, err := b.lib.procCall(b.lib.procBVLen, hptr)
- if err != nil {
- return 0, err
- }
- return int(l), nil
- }
- func (b BytesVec) Handle() uint64 {
- return b.h
- }
- func (b BytesVec) HandlePtr() uintptr {
- return uintptr(unsafe.Pointer(&b.h))
- }
|