// Code generated by winrt-go-gen. DO NOT EDIT.

//go:build windows

//nolint:all
package streams

import (
	"syscall"
	"unsafe"

	"github.com/go-ole/go-ole"
)

const GUIDIDataReader string = "e2b50029-b4c1-4314-a4b8-fb813a2f275e"
const SignatureIDataReader string = "{e2b50029-b4c1-4314-a4b8-fb813a2f275e}"

type IDataReader struct {
	ole.IInspectable
}

type IDataReaderVtbl struct {
	ole.IInspectableVtbl

	GetUnconsumedBufferLength uintptr
	GetUnicodeEncoding        uintptr
	SetUnicodeEncoding        uintptr
	GetByteOrder              uintptr
	SetByteOrder              uintptr
	GetInputStreamOptions     uintptr
	SetInputStreamOptions     uintptr
	ReadByte                  uintptr
	ReadBytes                 uintptr
	ReadBuffer                uintptr
	ReadBoolean               uintptr
	ReadGuid                  uintptr
	ReadInt16                 uintptr
	ReadInt32                 uintptr
	ReadInt64                 uintptr
	ReadUInt16                uintptr
	ReadUInt32                uintptr
	ReadUInt64                uintptr
	ReadSingle                uintptr
	ReadDouble                uintptr
	ReadString                uintptr
	ReadDateTime              uintptr
	ReadTimeSpan              uintptr
	LoadAsync                 uintptr
	DetachBuffer              uintptr
	DetachStream              uintptr
}

func (v *IDataReader) VTable() *IDataReaderVtbl {
	return (*IDataReaderVtbl)(unsafe.Pointer(v.RawVTable))
}

func (v *IDataReader) ReadBytes(valueSize uint32) ([]uint8, error) {
	var value []uint8 = make([]uint8, valueSize)
	hr, _, _ := syscall.SyscallN(
		v.VTable().ReadBytes,
		uintptr(unsafe.Pointer(v)),         // this
		uintptr(valueSize),                 // in uint32
		uintptr(unsafe.Pointer(&value[0])), // out uint8
	)

	if hr != 0 {
		return nil, ole.NewError(hr)
	}

	return value, nil
}
