From 048bed0cd1b924436b59b2374918e9b445344d47 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sun, 11 May 2014 18:47:54 +0000 Subject: [PATCH] inmem: a message is simply 1 opcode + an array of binary strings. Remove redundant `Data` field. Every argument can be arbitrary data. Signed-off-by: Solomon Hykes --- inmem/inmem.go | 1 - inmem/inmem_test.go | 23 ++++++++++------------- inmem/stack.go | 4 ++-- inmem/stack_test.go | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/inmem/inmem.go b/inmem/inmem.go index d1766f2aec..e5b240b8ff 100644 --- a/inmem/inmem.go +++ b/inmem/inmem.go @@ -18,7 +18,6 @@ type Receiver interface { type Message struct { Name string Args []string - Data []byte } const ( diff --git a/inmem/inmem_test.go b/inmem/inmem_test.go index 8e216e4ddb..aee864cd13 100644 --- a/inmem/inmem_test.go +++ b/inmem/inmem_test.go @@ -27,18 +27,15 @@ func TestSimpleSend(t *testing.T) { if err != nil { t.Fatal(err) } - if string(msg.Data) != "hello world" { - t.Fatalf("%#v", *msg) - } if msg.Name != "print" { t.Fatalf("%#v", *msg) } - if len(msg.Args) != 0 { + if msg.Args[0] != "hello world" { t.Fatalf("%#v", *msg) } assertMode(t, in, out, 0) }() - in, out, err := w.Send(&Message{Name: "print", Data: []byte("hello world")}, 0) + in, out, err := w.Send(&Message{Name: "print", Args: []string{"hello world"}}, 0) if err != nil { t.Fatal(err) } @@ -94,7 +91,7 @@ func TestSendReply(t *testing.T) { // Send go func() { // Send a message with mode=R - in, out, err := w.Send(&Message{Data: []byte("this is the request")}, R) + in, out, err := w.Send(&Message{Args: []string{"this is the request"}}, R) if err != nil { t.Fatal(err) } @@ -104,7 +101,7 @@ func TestSendReply(t *testing.T) { if err != nil { t.Fatal(err) } - if string(resp.Data) != "this is the reply" { + if resp.Args[0] != "this is the reply" { t.Fatalf("%#v", resp) } }() @@ -113,12 +110,12 @@ func TestSendReply(t *testing.T) { if err != nil { t.Fatal(err) } - if string(msg.Data) != "this is the request" { + if msg.Args[0] != "this is the request" { t.Fatalf("%#v", msg) } assertMode(t, in, out, W) // Send a reply - _, _, err = out.Send(&Message{Data: []byte("this is the reply")}, 0) + _, _, err = out.Send(&Message{Args: []string{"this is the reply"}}, 0) if err != nil { t.Fatal(err) } @@ -133,13 +130,13 @@ func TestSendNested(t *testing.T) { // Send go func() { // Send a message with mode=W - in, out, err := w.Send(&Message{Data: []byte("this is the request")}, W) + in, out, err := w.Send(&Message{Args: []string{"this is the request"}}, W) if err != nil { t.Fatal(err) } assertMode(t, in, out, W) // Send a nested message - _, _, err = out.Send(&Message{Data: []byte("this is the nested message")}, 0) + _, _, err = out.Send(&Message{Args: []string{"this is the nested message"}}, 0) if err != nil { t.Fatal(err) } @@ -149,7 +146,7 @@ func TestSendNested(t *testing.T) { if err != nil { t.Fatal(err) } - if string(msg.Data) != "this is the request" { + if msg.Args[0] != "this is the request" { t.Fatalf("%#v", msg) } assertMode(t, in, out, R) @@ -158,7 +155,7 @@ func TestSendNested(t *testing.T) { if err != nil { t.Fatal(err) } - if string(nested.Data) != "this is the nested message" { + if nested.Args[0] != "this is the nested message" { t.Fatalf("%#v", nested) } }) diff --git a/inmem/stack.go b/inmem/stack.go index 90b66e87ed..87378ca7f0 100644 --- a/inmem/stack.go +++ b/inmem/stack.go @@ -8,7 +8,7 @@ import ( // StackSender forwards beam messages to a dynamic list of backend receivers. // New backends are stacked on top. When a message is sent, each backend is -// tried until one succeeds. Any failing backends encountered along the way +// tried until one succeeds. Any failing backends encountered along the way // are removed from the queue. type StackSender struct { stack *list.List @@ -92,7 +92,7 @@ func (s *StackSender) Len() int { return s.stack.Len() } var len int - for e := s.front; e != nil ; e = e.Next() { + for e := s.front; e != nil; e = e.Next() { len++ } return len diff --git a/inmem/stack_test.go b/inmem/stack_test.go index 5c406ac1d9..1a37eeebff 100644 --- a/inmem/stack_test.go +++ b/inmem/stack_test.go @@ -25,7 +25,7 @@ func TestSendStack(t *testing.T) { t.Fatalf("%#v", msg) } }() - _, _, err := s.Send(&Message{"hello", []string{"wonderful", "world"}, nil}, 0) + _, _, err := s.Send(&Message{"hello", []string{"wonderful", "world"}}, 0) if err != nil { t.Fatal(err) }