From a105d2d0ea5fb96d8bb6bbcd62e3fdf6b2247bb3 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Thu, 20 Oct 2022 15:19:32 -0400 Subject: [PATCH] add wrapper --- p2p/types.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/p2p/types.go b/p2p/types.go index b1e5266c6..bab051639 100644 --- a/p2p/types.go +++ b/p2p/types.go @@ -14,3 +14,17 @@ type Envelope struct { Message proto.Message // message payload ChannelID byte } + +// Wrapper is a Protobuf message that can contain a variety of inner messages +// (e.g. via oneof fields). If a Channel's message type implements Wrapper, the +// Router will automatically wrap outbound messages and unwrap inbound messages, +// such that reactors do not have to do this themselves. +type Wrapper interface { + proto.Message + + // Wrap will take a message and wrap it in this one if possible. + Wrap(proto.Message) error + + // Unwrap will unwrap the inner message contained in this message. + Unwrap() (proto.Message, error) +}