[refactor] Read protobuf messages

This commit is contained in:
2020-01-01 19:30:34 +01:00
parent 0c318d7e09
commit 572201a213
350 changed files with 248653 additions and 90 deletions

View File

@ -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)
}