// 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 GUIDIDataWriter string = "64b89265-d341-4922-b38a-dd4af8808c4e"
const SignatureIDataWriter string = "{64b89265-d341-4922-b38a-dd4af8808c4e}"

type IDataWriter struct {
	ole.IInspectable
}

type IDataWriterVtbl struct {
	ole.IInspectableVtbl

	GetUnstoredBufferLength uintptr
	GetUnicodeEncoding      uintptr
	SetUnicodeEncoding      uintptr
	GetByteOrder            uintptr
	SetByteOrder            uintptr
	WriteByte               uintptr
	WriteBytes              uintptr
	WriteBuffer             uintptr
	WriteBufferRange        uintptr
	WriteBoolean            uintptr
	WriteGuid               uintptr
	WriteInt16              uintptr
	WriteInt32              uintptr
	WriteInt64              uintptr
	WriteUInt16             uintptr
	WriteUInt32             uintptr
	WriteUInt64             uintptr
	WriteSingle             uintptr
	WriteDouble             uintptr
	WriteDateTime           uintptr
	WriteTimeSpan           uintptr
	WriteString             uintptr
	MeasureString           uintptr
	StoreAsync              uintptr
	FlushAsync              uintptr
	DetachBuffer            uintptr
	DetachStream            uintptr
}

func (v *IDataWriter) VTable() *IDataWriterVtbl {
	return (*IDataWriterVtbl)(unsafe.Pointer(v.RawVTable))
}

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

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

	return nil
}

func (v *IDataWriter) DetachBuffer() (*IBuffer, error) {
	var out *IBuffer
	hr, _, _ := syscall.SyscallN(
		v.VTable().DetachBuffer,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out IBuffer
	)

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

	return out, nil
}
