-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: JSON output option for cat (#289)
Adds a ros1msg JSON transcoder to the ros utilities package, and calls it from the CLI's cat command when the --json switch is supplied.
- Loading branch information
Showing
11 changed files
with
1,545 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,6 @@ lint: | |
|
||
test: | ||
go test ./... | ||
|
||
bench: | ||
make -C cmd bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
"io/ioutil" | ||
"math" | ||
"testing" | ||
|
||
"github.com/foxglove/mcap/go/mcap" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func BenchmarkCat(b *testing.B) { | ||
ctx := context.Background() | ||
cases := []struct { | ||
assertion string | ||
inputfile string | ||
formatJSON bool | ||
}{ | ||
{ | ||
"demo.bag", | ||
"../../../../testdata/mcap/demo.mcap", | ||
true, | ||
}, | ||
} | ||
for _, c := range cases { | ||
input, err := ioutil.ReadFile(c.inputfile) | ||
assert.Nil(b, err) | ||
w := io.Discard | ||
r := bytes.NewReader(input) | ||
b.Run(c.assertion, func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
reader, err := mcap.NewReader(r) | ||
assert.Nil(b, err) | ||
it, err := reader.Messages(0, math.MaxInt64, []string{}, true) | ||
assert.Nil(b, err) | ||
err = printMessages(ctx, w, it, c.formatJSON) | ||
assert.Nil(b, err) | ||
r.Reset(input) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.