summaryrefslogtreecommitdiffhomepage
path: root/pkg/eventchannel/event.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/eventchannel/event.go')
-rw-r--r--pkg/eventchannel/event.go40
1 files changed, 19 insertions, 21 deletions
diff --git a/pkg/eventchannel/event.go b/pkg/eventchannel/event.go
index 9a29c58bd..7172ce75d 100644
--- a/pkg/eventchannel/event.go
+++ b/pkg/eventchannel/event.go
@@ -24,8 +24,8 @@ import (
"fmt"
"syscall"
- "github.com/golang/protobuf/proto"
- "github.com/golang/protobuf/ptypes"
+ "google.golang.org/protobuf/encoding/prototext"
+ "google.golang.org/protobuf/proto"
pb "gvisor.dev/gvisor/pkg/eventchannel/eventchannel_go_proto"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/sync"
@@ -118,22 +118,6 @@ func (me *multiEmitter) Close() error {
return err
}
-func marshal(msg proto.Message) ([]byte, error) {
- anypb, err := ptypes.MarshalAny(msg)
- if err != nil {
- return nil, err
- }
-
- // Wire format is uvarint message length followed by binary proto.
- bufMsg, err := proto.Marshal(anypb)
- if err != nil {
- return nil, err
- }
- p := make([]byte, binary.MaxVarintLen64)
- n := binary.PutUvarint(p, uint64(len(bufMsg)))
- return append(p[:n], bufMsg...), nil
-}
-
// socketEmitter emits proto messages on a socket.
type socketEmitter struct {
socket *unet.Socket
@@ -155,10 +139,19 @@ func SocketEmitter(fd int) (Emitter, error) {
// Emit implements Emitter.Emit.
func (s *socketEmitter) Emit(msg proto.Message) (bool, error) {
- p, err := marshal(msg)
+ any, err := newAny(msg)
if err != nil {
return false, err
}
+ bufMsg, err := proto.Marshal(any)
+ if err != nil {
+ return false, err
+ }
+
+ // Wire format is uvarint message length followed by binary proto.
+ p := make([]byte, binary.MaxVarintLen64)
+ n := binary.PutUvarint(p, uint64(len(bufMsg)))
+ p = append(p[:n], bufMsg...)
for done := 0; done < len(p); {
n, err := s.socket.Write(p[done:])
if err != nil {
@@ -166,6 +159,7 @@ func (s *socketEmitter) Emit(msg proto.Message) (bool, error) {
}
done += n
}
+
return false, nil
}
@@ -189,9 +183,13 @@ func DebugEmitterFrom(inner Emitter) Emitter {
}
func (d *debugEmitter) Emit(msg proto.Message) (bool, error) {
+ text, err := prototext.Marshal(msg)
+ if err != nil {
+ return false, err
+ }
ev := &pb.DebugEvent{
- Name: proto.MessageName(msg),
- Text: proto.MarshalTextString(msg),
+ Name: string(msg.ProtoReflect().Descriptor().FullName()),
+ Text: string(text),
}
return d.inner.Emit(ev)
}