Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uint64 bug in JSON transcoder #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading