Skip to content

Commit

Permalink
Merge pull request #5 from wkalt/task/fix-uint64-bug-json-transcoder
Browse files Browse the repository at this point in the history
Fix uint64 bug in JSON transcoder
  • Loading branch information
defunctzombie authored Apr 22, 2024
2 parents 6da1307 + afe5195 commit e231891
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ros1msg/json_transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ func (t *JSONTranscoder) int64(w io.Writer, r io.Reader) error {
}

func (t *JSONTranscoder) uint64(w io.Writer, r io.Reader) error {
if _, err := io.ReadFull(r, t.buf[:4]); err != nil {
if _, err := io.ReadFull(r, t.buf[:8]); err != nil {
return fmt.Errorf("failed to read uint64: %w", err)
}
x := binary.LittleEndian.Uint64(t.buf[:8])
t.formattedNumber = strconv.AppendInt(t.formattedNumber, int64(x), 10)
t.formattedNumber = strconv.AppendUint(t.formattedNumber, x, 10)
if _, err := w.Write(t.formattedNumber); err != nil {
return fmt.Errorf("failed to write formatted uint64: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions ros1msg/json_transcoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func TestJSONTranscoding(t *testing.T) {
err = transcoder.Transcode(buf, bytes.NewReader(c.input))
assert.Nil(t, err)
assert.Equal(t, c.expectedJSON, buf.String())
transcoder.buf = make([]byte, 8)
})
}
}
Expand Down Expand Up @@ -309,8 +310,8 @@ func TestSingleRecordConversion(t *testing.T) {
converter: transcoder.uint64,
},
},
[]byte{0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07},
`{"foo":506381209866536711}`,
[]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
`{"foo":18446744073709551615}`,
},
{
"float32",
Expand Down

0 comments on commit e231891

Please sign in to comment.