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/mcap: Fix scenario where schemaID equals 0 #992

Merged
merged 2 commits into from
Feb 21, 2024
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 go/mcap/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestIndexedReaderBreaksTiesOnChunkOffset(t *testing.T) {
assert.Nil(t, err)
assert.Nil(t, writer.WriteHeader(&Header{}))
assert.Nil(t, writer.WriteSchema(&Schema{
ID: 0,
ID: 1,
Name: "",
Encoding: "",
Data: []byte{},
Expand Down Expand Up @@ -586,7 +586,7 @@ func TestReadingMessageOrderWithOverlappingChunks(t *testing.T) {
assert.Nil(t, err)
assert.Nil(t, writer.WriteHeader(&Header{}))
assert.Nil(t, writer.WriteSchema(&Schema{
ID: 0,
ID: 1,
Name: "",
Encoding: "",
Data: []byte{},
Expand Down
7 changes: 7 additions & 0 deletions go/mcap/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ func (w *Writer) WriteFooter(f *Footer) error {
// WriteSchema writes a schema record to the output. Schema records are uniquely
// identified within a file by their schema ID. A Schema record must occur at
// least once in the file prior to any Channel Info referring to its ID.
// A unique identifier for this schema within the file. Must not be zero.
func (w *Writer) WriteSchema(s *Schema) (err error) {
if s == nil {
return errors.New("schema struct can not be nil")
}
if s.ID == 0 {
return errors.New("schemaID must not be zero")
}
msglen := 2 + 4 + len(s.Name) + 4 + len(s.Encoding) + 4 + len(s.Data)
w.ensureSized(msglen)
offset := putUint16(w.msg, s.ID)
Expand Down
Loading