Skip to content

Commit

Permalink
Resolve integer deserialization issue in topic consume (#2242)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgagniere authored Sep 7, 2023
1 parent 34bec9a commit 4330387
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions internal/kafka/command_topic_produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ func (c *command) produce(cmd *cobra.Command, args []string) error {
return err
}

parseKey, err := cmd.Flags().GetBool("parse-key")
if err != nil {
return err
}

if cmd.Flags().Changed("key-format") && !parseKey {
return errors.New("`--parse-key` must be set when `key-format` is set")
}

configFile, err := cmd.Flags().GetString("config-file")
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions internal/kafka/command_topic_produce_onprem.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ func (c *command) produceOnPrem(cmd *cobra.Command, args []string) error {
return err
}

parseKey, err := cmd.Flags().GetBool("parse-key")
if err != nil {
return err
}

if cmd.Flags().Changed("key-format") && !parseKey {
return errors.New("`--parse-key` must be set when `key-format` is set")
}

keySchema, err := cmd.Flags().GetString("key-schema")
if err != nil {
return err
Expand Down
6 changes: 5 additions & 1 deletion pkg/serdes/integer_deserialization_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ func (s *IntegerDeserializationProvider) LoadSchema(_ string, _ map[string]strin
}

func (s *IntegerDeserializationProvider) Deserialize(data []byte) (string, error) {
return fmt.Sprintf("%d", binary.BigEndian.Uint32(data)), nil
if len(data) == 0 {
return "", nil
}

return fmt.Sprintf("%d", binary.LittleEndian.Uint32(data)), nil
}

0 comments on commit 4330387

Please sign in to comment.