[refactor] Read protobuf messages
This commit is contained in:
11
vendor/github.com/cyrilix/robocar-base/testtools/testtools.go
generated
vendored
11
vendor/github.com/cyrilix/robocar-base/testtools/testtools.go
generated
vendored
@ -3,6 +3,8 @@ package testtools
|
||||
import (
|
||||
"github.com/cyrilix/robocar-base/mqttdevice"
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/golang/protobuf/proto"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@ -71,3 +73,12 @@ func NewFakeMessage(topic string, payload []byte) mqtt.Message {
|
||||
acked: false,
|
||||
}
|
||||
}
|
||||
|
||||
func NewFakeMessageFromProtobuf(topic string, msg proto.Message) mqtt.Message{
|
||||
payload, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
log.Errorf("unable to marshal protobuf message %T: %v", msg, err)
|
||||
return nil
|
||||
}
|
||||
return NewFakeMessage(topic, payload)
|
||||
}
|
||||
|
Reference in New Issue
Block a user