12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package test
- import (
- "fmt"
- "github.com/foxglove/go-rosbag"
- "os"
- "testing"
- )
- func TestWriteRosBag(t *testing.T) {
- // Check if the file exists, if not create it
- f, err := os.OpenFile("my-bag.bag", os.O_RDWR|os.O_CREATE, 0644)
- if err != nil {
- panic(err)
- }
- defer func(f *os.File) {
- err := f.Close()
- if err != nil {
- fmt.Printf("Error closing file: %s\n", err)
- }
- }(f)
- writer, err := rosbag.NewWriter(f)
- if err != nil {
- panic(err)
- }
- err = writer.WriteConnection(&rosbag.Connection{
- Conn: 1,
- Topic: "/foo",
- Data: rosbag.ConnectionHeader{
- Topic: "/foo",
- Type: "Foo",
- MD5Sum: "abc",
- MessageDefinition: []byte{0x01, 0x02, 0x03},
- //// optional fields
- //CallerID: &callerID,
- //Latching: &latching,
- },
- })
- if err != nil {
- panic(err)
- }
- for i := 0; i < 100; i++ {
- err = writer.WriteMessage(&rosbag.Message{
- Conn: 0,
- Time: uint64(i),
- Data: []byte("hello"),
- })
- if err != nil {
- panic(err)
- }
- }
- }
|