Skip to content

Commit

Permalink
Enveloper: ToWire() now returns (Value, error)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav committed May 23, 2016
1 parent 65bc007 commit 695425f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions envelope/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ import (
type Enveloper interface {
MethodName() string
EnvelopeType() wire.EnvelopeType
ToWire() wire.Value
ToWire() (wire.Value, error)
}

// Write writes an Envelope to the given writer.
func Write(p protocol.Protocol, w io.Writer, seqID int32, e Enveloper) error {
body, err := e.ToWire()
if err != nil {
return err
}
return p.EncodeEnveloped(wire.Envelope{
SeqID: seqID,
Name: e.MethodName(),
Type: e.EnvelopeType(),
Value: e.ToWire(),
Value: body,
}, w)
}
6 changes: 4 additions & 2 deletions gen/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ func TestServiceTypesEnveloper(t *testing.T) {

expected := tt.wantEnvelope
expected.SeqID = 1234
expected.Value = tt.s.ToWire()
assert.Equal(t, expected, envelope, "Envelope mismatch for %v", tt)
expected.Value, err = tt.s.ToWire()
if assert.NoError(t, err, "Error serializing %v", tt.s) {
assert.Equal(t, expected, envelope, "Envelope mismatch for %v", tt)
}
}
}

0 comments on commit 695425f

Please sign in to comment.