Skip to content

Commit

Permalink
write ros time to message indexes, clarify docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
james-rms committed Nov 8, 2024
1 parent 4628267 commit 7f060d5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
14 changes: 7 additions & 7 deletions rosbag.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ type ConnectionHeader struct {
// to be decodable using the message_definition field of the connection record
// associated with "connID".
type Message struct {
Conn uint32 // ID for connection on which emssage arrived
Time uint64 // time at which the message was received
Conn uint32 // ID for connection on which message arrived
Time uint64 // time at which the message was received in nanoseconds
Data []byte // serialized message data in ROS serialization format
}

Expand All @@ -107,8 +107,8 @@ type Message struct {
// offset.
type ChunkInfo struct {
ChunkPos uint64 // offset of the chunk record
StartTime uint64 // timestamp of earliest message in the chunk
EndTime uint64 // timestamp of latest message in the chunk
StartTime uint64 // timestamp of earliest message in the chunk in nanoseconds
EndTime uint64 // timestamp of latest message in the chunk in nanoseconds
Count uint32 // number of connections in the chunk
Data map[uint32]uint32 // map of connID to message count
}
Expand All @@ -118,11 +118,11 @@ type ChunkInfo struct {
type IndexData struct {
Conn uint32 // connection ID
Count uint32 // number of messages on *conn* in the preceding chunk
Data []MessageIndexEntry // *count* repeating occurrences of timestamps (uint64) and message offsets (uint32)
Data []MessageIndexEntry // *count* repeating occurrences of timestamps and message offsets
}

// MessageIndexEntry is an entry in the data section of an IndexData record.
type MessageIndexEntry struct {
Time uint64 // time at which the message was recorded
Offset uint32 // offset of the message, relative to the start of the chunk data that contains it
Time uint64 // time at which the message was recorded in nanoseconds
Offset uint32 // byte offset of the message within the uncompressed chunk data
}
2 changes: 1 addition & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (b *Writer) writeIndexData(indexData IndexData) error {
data := make([]byte, 12*len(indexData.Data))
offset := 0
for _, entry := range indexData.Data {
offset += putU64(data[offset:], entry.Time)
offset += putRostime(data[offset:], entry.Time)
offset += putU32(data[offset:], entry.Offset)
}

Expand Down
30 changes: 30 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func testBagIsReadable(t *testing.T, rs io.Reader) {
Expand Down Expand Up @@ -133,6 +134,35 @@ func TestWriter(t *testing.T) {
}
}

func TestCorrectMessageIndexes(t *testing.T) {
buf := &bytes.Buffer{}
timestamp := uint64(10_000_000_020)
writer, err := NewWriter(buf)
require.NoError(t, err)
require.NoError(t, writer.WriteConnection(connection(13, "/chat")))
require.NoError(t, writer.WriteMessage(message(13, timestamp, []byte("hello"))))
require.NoError(t, writer.Close())

reader := bytes.NewBuffer(buf.Bytes())
_, err = reader.Read(make([]byte, len(Magic)))
require.NoError(t, err)

for {
op, record, err := ReadRecord(reader)
require.NoError(t, err)
if op != OpIndexData {
continue
}
index, err := ParseIndexData(record)
require.NoError(t, err)
assert.Equal(t, index.Conn, uint32(13))
require.Len(t, index.Data, 1)
entry := index.Data[0]
require.Equal(t, entry.Time, timestamp)
break
}
}

func TestWriterIsDeterministic(t *testing.T) {
hashes := []string{}

Expand Down

0 comments on commit 7f060d5

Please sign in to comment.