diff --git a/ros1msg/json_transcoder.go b/ros1msg/json_transcoder.go index b735122..9d91114 100644 --- a/ros1msg/json_transcoder.go +++ b/ros1msg/json_transcoder.go @@ -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) } diff --git a/ros1msg/json_transcoder_test.go b/ros1msg/json_transcoder_test.go index 6cd8c0d..e268ba7 100644 --- a/ros1msg/json_transcoder_test.go +++ b/ros1msg/json_transcoder_test.go @@ -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) }) } } @@ -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",