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

[go/cli] Fix uint64 bug in mcap cat #1159

Merged
merged 4 commits into from
Apr 22, 2024

Conversation

bradsquicciarini-coco
Copy link
Contributor

Changelog

mcap cat is not reading uint64 ros1 msgs properly

Description

Super minor, but looks like the JSONTranscoder for ros1msg is only reading 4 bytes for the uint64 type.

@jtbandes
Copy link
Member

Thanks for the fix! Could you add some tests for this? Looks like there are existing tests in https://github.com/foxglove/mcap/blob/main/go/cli/mcap/utils/ros/json_transcoder_test.go

@bradsquicciarini-coco
Copy link
Contributor Author

bradsquicciarini-coco commented Apr 18, 2024

Kinda of interesting there already was a test, but...

Running all the existing tests worked

$ go test ./utils/ros -count=1                                           
ok      github.com/foxglove/mcap/go/cli/mcap/utils/ros  0.115s

Running just the uint64 test didn't

$ go test ./utils/ros -run TestSingleRecordConversion/uint64  -count=1
--- FAIL: TestSingleRecordConversion (0.00s)
    --- FAIL: TestSingleRecordConversion/uint64 (0.00s)
        json_transcoder_test.go:532: 
                Error Trace:    /Users/bradsquicciarini/mcap/go/cli/mcap/utils/ros/json_transcoder_test.go:532
                Error:          Not equal: 
                                expected: "{\"foo\":506381209866536711}"
                                actual  : "{\"foo\":117901063}"
                                
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -{"foo":506381209866536711}
                                +{"foo":117901063}
                Test:           TestSingleRecordConversion/uint64
FAIL
FAIL    github.com/foxglove/mcap/go/cli/mcap/utils/ros  0.117s
FAIL

Looks like the test was reading some well placed garbage from prior tests. So just zeroed out the buffer between test cases.

@jtbandes
Copy link
Member

lol…amazing 🙌

Copy link
Contributor

@bryfox bryfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

It looks like there's also an incorrect conversion a few lines below; would you like to deal with that in this PR (and maybe use a larger value in the test to catch it)?

https://github.com/foxglove/mcap/blob/main/go/cli/mcap/utils/ros/json_transcoder.go#L285

https://pkg.go.dev/strconv#AppendUint

Copy link
Contributor

@bryfox bryfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

wkalt added a commit to wkalt/go-rosbag that referenced this pull request Apr 22, 2024
@wkalt
Copy link
Contributor

wkalt commented Apr 22, 2024

@bryfox @jtbandes I ported this to the copy of this code at foxglove/go-rosbag#5

IIRC the foxglove CLI tool consumes that version so you will probably want to update its deps once that goes in. The MCAP CLI tool should probably also be updated to refer to that code instead.

wkalt added a commit to wkalt/go-rosbag that referenced this pull request Apr 22, 2024
@bryfox bryfox merged commit 02cc054 into foxglove:main Apr 22, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants