Skip to content

Commit

Permalink
kgo record formatter: accept %v{} to be a no-op (plain read/format)
Browse files Browse the repository at this point in the history
  • Loading branch information
twmb committed Sep 2, 2023
1 parent 37edfb9 commit 055e2d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/kgo/record_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ func NewRecordFormatter(layout string) (*RecordFormatter, error) {
var appendFn func([]byte, []byte) []byte
if handledBrace = isOpenBrace; handledBrace {
switch {
case strings.HasPrefix(layout, "}"):
layout = layout[len("}"):]
appendFn = appendPlain
case strings.HasPrefix(layout, "base64}"):
appendFn = appendBase64
layout = layout[len("base64}"):]
Expand Down Expand Up @@ -1298,6 +1301,8 @@ func (r *RecordReader) parseReadLayout(layout string) error {
var isJson bool
if handledBrace = isOpenBrace; handledBrace {
switch {
case strings.HasPrefix(layout, "}"):
layout = layout[len("}"):]
case strings.HasPrefix(layout, "base64}"):
decodeFn = decodeBase64
layout = layout[len("base64}"):]
Expand Down
9 changes: 9 additions & 0 deletions pkg/kgo/record_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func TestRecordFormatter(t *testing.T) {
layout: "%v",
expR: "value",
},
{
layout: "%v{}",
expR: "value",
},

{
layout: "%T{hex16}%t %V{ascii} %v %V{little16} %k %K{big32} %o",
Expand Down Expand Up @@ -233,6 +237,11 @@ func TestRecordReader(t *testing.T) {
in: "foo bar biz\nbaz",
exp: []*Record{StringRecord("foo bar biz\nbaz")},
},
{
layout: "%v{}",
in: "foo bar biz\nbaz",
exp: []*Record{StringRecord("foo bar biz\nbaz")},
},

{
layout: "%k %v",
Expand Down

0 comments on commit 055e2d8

Please sign in to comment.