Skip to content

Commit

Permalink
Revert change to Reassembler.Push from elastic#116 (elastic#122)
Browse files Browse the repository at this point in the history
Reassembler.Push has always made a copy of the provided byte slice.

It elastic#116 it was modified to not copy the slice. But this was a breaking change
to its behavior and causes bugs for existing users. The typical use of this
function is to parse data from AuditClient.Receive which explicitly documents
that caller must make a copy of the data if they are going to retain it beyond
the next Receive call.

Relates elastic#116
  • Loading branch information
andrewkroh authored Aug 24, 2022
1 parent 2f073b9 commit accf9b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Reduce allocations when converting bytes to strings for received messages. [#116](https://github.com/elastic/go-libaudit/pull/116)
- Reduce allocations when converting bytes to strings for received messages. [#116](https://github.com/elastic/go-libaudit/pull/116) [#122](https://github.com/elastic/go-libaudit/pull/122)

### Removed

Expand Down
9 changes: 4 additions & 5 deletions reassembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"time"

"github.com/elastic/go-libaudit/v2/auparse"
"github.com/elastic/go-libaudit/v2/internal"
)

var errReassemblerClosed = errors.New("reassembler closed")
Expand Down Expand Up @@ -94,12 +93,12 @@ func (r *Reassembler) PushMessage(msg *auparse.AuditMessage) {
r.callback(evicted, lost)
}

// Push pushes a new audit message into the Reassembler. This is a convenence
// Push pushes a new audit message into the Reassembler. This is a convenience
// function that handles calling auparse.Parse() to extract the message's
// timestamp and sequence number. If parsing fails then an error will be
// returned. See PushMessage.
// timestamp and sequence number. It copies the rawData contents. If parsing
// fails then an error will be returned. See PushMessage.
func (r *Reassembler) Push(typ auparse.AuditMessageType, rawData []byte) error {
msg, err := auparse.Parse(typ, internal.UnsafeByteSlice2String(rawData))
msg, err := auparse.Parse(typ, string(rawData))
if err != nil {
return err
}
Expand Down

0 comments on commit accf9b4

Please sign in to comment.