This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define interface for mutable and immutable messages
- Loading branch information
1 parent
a442017
commit 4bbce0a
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package transport | ||
|
||
import "io" | ||
|
||
// ImmutableMessage defines an interface for read-only messages received by a | ||
// Transport. | ||
type ImmutableMessage interface { | ||
// ImmutableMessage implements io.Closer. All messages should be closed | ||
// when they are no longer being used. | ||
io.Closer | ||
|
||
// Sender returns the name of the service that sent the mesage. | ||
Sender() string | ||
|
||
// Receiver returns the name of the service that will receive the message. | ||
Receiver() string | ||
|
||
// Endpoint returns the receiving service endpoint where the message | ||
// will be routed to. The receiving service name combined with the | ||
// endpoint name should be unique among all running services. | ||
Endpoint() string | ||
|
||
// Headers returns a map of header values associated with the message. | ||
Headers() map[string]string | ||
|
||
// Payload returns the payload associated with the message as a byte | ||
// slice or an error if one is encoded in the message. | ||
Payload() ([]byte, error) | ||
} | ||
|
||
// Message defines an interface for messages whose headers and payload can be | ||
// modified by the sender. Message instances are typically used by clients to | ||
// send RPC requests or by servers to respond to incoming messages. | ||
type Message interface { | ||
ImmutableMessage | ||
|
||
// SetPayload sets the content of this message. The content may be either | ||
// a byte slice or an error message. | ||
SetPayload(payload []byte, err error) | ||
|
||
// SetHeader sets the content of a message header to the specified value. | ||
// If the specified header already exists, its value will be overwritten | ||
// by the new value. | ||
SetHeader(name, value string) | ||
|
||
// SetHeaders sets the contents of a batch of headers. This is equivalent | ||
// to iterating the map and calling SetHeader for each key/value. | ||
SetHeaders(headers map[string]string) | ||
} |