Skip to content

Commit

Permalink
rpk: set value of produced record to empty byte slice
Browse files Browse the repository at this point in the history
To differentiate a record with an empty string-value (`""`) in
`rpk topic produce` from a record with a null value (`null`, as produced
by `rpk topic produce -Z`), assign the empty-string to an empty-byte slice.
  • Loading branch information
WillemKauf committed Sep 10, 2024
1 parent 02c86b3 commit f8f1ce2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/go/rpk/pkg/cli/topic/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,16 @@ func newProduceCommand(fs afero.Fs, p *config.Params) *cobra.Command {
if topicName == "" {
topicName = r.Topic
}
if tombstone && len(r.Value) == 0 {
r.Value = nil
if len(r.Value) == 0 {
if tombstone {
// `null` value
r.Value = nil
} else {
// empty byte-slice
r.Value = []byte{}
}
}

if defaultKeySerde != nil || isKeyTopicName {
keySerde := defaultKeySerde
if isKeyTopicName && keySerde == nil {
Expand Down

0 comments on commit f8f1ce2

Please sign in to comment.