aboutsummaryrefslogtreecommitdiffstats
path: root/core/stream.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/stream.go')
-rw-r--r--core/stream.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/core/stream.go b/core/stream.go
index edc3f2b..171b201 100644
--- a/core/stream.go
+++ b/core/stream.go
@@ -62,8 +62,23 @@ func (c *Connection) NewStream(ctx context.Context) (api.Stream, error) {
}
func (c *Connection) Invoke(ctx context.Context, req api.Message, reply api.Message) error {
- // TODO: implement invoke
- panic("not implemented")
+ stream, err := c.NewStream(ctx)
+ if err != nil {
+ return err
+ }
+ if err := stream.SendMsg(req); err != nil {
+ return err
+ }
+ msg, err := stream.RecvMsg()
+ if err != nil {
+ return err
+ }
+ if msg.GetMessageName() != reply.GetMessageName() ||
+ msg.GetCrcString() != reply.GetCrcString() {
+ return fmt.Errorf("unexpected reply: %T %+v", msg, msg)
+ }
+ reflect.ValueOf(reply).Elem().Set(reflect.ValueOf(msg).Elem())
+ return nil
}
func (s *Stream) Context() context.Context {