Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg/stanza] Pass buffer by reference so buffer changes are not lost #36252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/stanza/operator/input/windows/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (b *Bookmark) Update(event Event) error {
}

// Render will render the bookmark as xml.
func (b *Bookmark) Render(buffer Buffer) (string, error) {
func (b *Bookmark) Render(buffer *Buffer) (string, error) {
if b.handle == 0 {
return "", fmt.Errorf("bookmark handle is not open")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/operator/input/windows/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (b *Buffer) FirstByte() *byte {
}

// NewBuffer creates a new buffer with the default buffer size
func NewBuffer() Buffer {
return Buffer{
func NewBuffer() *Buffer {
return &Buffer{
buffer: make([]byte, defaultBufferSize),
}
}
11 changes: 0 additions & 11 deletions pkg/stanza/operator/input/windows/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ func TestBufferReadBytes(t *testing.T) {
require.Equal(t, utf8, bytes)
}

func TestBufferReadBytesOverflow(t *testing.T) {
buffer := NewBuffer()
utf8 := []byte("test")
utf16, _ := unicode.UTF16(unicode.LittleEndian, unicode.UseBOM).NewEncoder().Bytes(utf8)
copy(buffer.buffer, utf16)
offset := uint32(len(utf16))
bytes, err := buffer.ReadBytes(offset * 2)
require.NoError(t, err)
require.Equal(t, utf8, bytes)
}

func TestBufferReadWideBytes(t *testing.T) {
buffer := NewBuffer()
utf8 := []byte("test")
Expand Down
6 changes: 3 additions & 3 deletions pkg/stanza/operator/input/windows/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Event struct {
}

// GetPublisherName will get the publisher name of the event.
func (e *Event) GetPublisherName(buffer Buffer) (string, error) {
func (e *Event) GetPublisherName(buffer *Buffer) (string, error) {
if e.handle == 0 {
return "", fmt.Errorf("event handle does not exist")
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func NewEvent(handle uintptr) Event {
}

// RenderSimple will render the event as EventXML without formatted info.
func (e *Event) RenderSimple(buffer Buffer) (*EventXML, error) {
func (e *Event) RenderSimple(buffer *Buffer) (*EventXML, error) {
if e.handle == 0 {
return nil, fmt.Errorf("event handle does not exist")
}
Expand All @@ -100,7 +100,7 @@ func (e *Event) RenderSimple(buffer Buffer) (*EventXML, error) {
}

// RenderDeep will render the event as EventXML with all available formatted info.
func (e *Event) RenderDeep(buffer Buffer, publisher Publisher) (*EventXML, error) {
func (e *Event) RenderDeep(buffer *Buffer, publisher Publisher) (*EventXML, error) {
if e.handle == 0 {
return nil, fmt.Errorf("event handle does not exist")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/input/windows/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type Input struct {
helper.InputOperator
bookmark Bookmark
buffer Buffer
buffer *Buffer
channel string
maxReads int
startAt string
Expand Down
Loading