|
| 1 | +package encoding |
| 2 | + |
| 3 | +import ( |
| 4 | + "io" |
| 5 | + "reflect" |
| 6 | + |
| 7 | + "github.com/docker/libchan" |
| 8 | +) |
| 9 | + |
| 10 | +// ChannelFactory represents an object which is able to create new |
| 11 | +// channels and streams. This interface is used by an encoder |
| 12 | +// create a channel or stream, copy the encoded type, and |
| 13 | +// encode the identifier. |
| 14 | +type ChannelFactory interface { |
| 15 | + // CreateSender creates a new send channel and returns |
| 16 | + // the identifier associated with the sender. This |
| 17 | + // identifier can be used to get the Receiver on |
| 18 | + // the receiving side by calling GetReceiver. |
| 19 | + CreateSender() (libchan.Sender, uint64, error) |
| 20 | + |
| 21 | + // CreateReceiver creates a new receive channel and |
| 22 | + // returns the identifier associated with the receiver. |
| 23 | + // This identifier can be used to get the Sender on |
| 24 | + // the receiving side by calling GetSender. |
| 25 | + CreateReceiver() (libchan.Receiver, uint64, error) |
| 26 | + |
| 27 | + // CreateStream createsa new byte stream and returns |
| 28 | + // the identifier associate with the stream. This |
| 29 | + // identifier can be used to get the byte stream |
| 30 | + // by calling GetStream on the receiving side. |
| 31 | + CreateStream() (io.ReadWriteCloser, uint64, error) |
| 32 | +} |
| 33 | + |
| 34 | +// ChannelReceiver represents an object which is able to receive |
| 35 | +// new channels and streams and retrieve by an integer identifer. |
| 36 | +type ChannelReceiver interface { |
| 37 | + // GetSender gets a remotely created sender referenced |
| 38 | + // by the given identifier. |
| 39 | + GetSender(uint64) (libchan.Sender, error) |
| 40 | + |
| 41 | + // GetReceiver gets a remotely created receiver referenced |
| 42 | + // by the given identifier. |
| 43 | + GetReceiver(uint64) (libchan.Receiver, error) |
| 44 | + |
| 45 | + // GetStream gets a remotely created byte stream |
| 46 | + // referenced by the given identifier. |
| 47 | + GetStream(uint64) (io.ReadWriteCloser, error) |
| 48 | +} |
| 49 | + |
| 50 | +// Encoder represents an object which can encode an interface |
| 51 | +// into data stream to be decoded. This Encoder must be able |
| 52 | +// to encode interfaces by converting to libchan channels and |
| 53 | +// streams and encoding the identifier. |
| 54 | +type Encoder interface { |
| 55 | + Encode(v ...interface{}) error |
| 56 | +} |
| 57 | + |
| 58 | +// Decoder represents an object which can decode from a data |
| 59 | +// stream into an interface. The decoder must have support |
| 60 | +// for decoding stream and channel identifiers into a libchan |
| 61 | +// Sender or Receiver as well as io Readers and Writers. |
| 62 | +type Decoder interface { |
| 63 | + Decode(v ...interface{}) error |
| 64 | +} |
| 65 | + |
| 66 | +// ChannelCodec represents a libchan codec capable of encoding |
| 67 | +// Go interfaces into data streams supporting libchan types as |
| 68 | +// well as decode into libchan supported interfaces. In addition |
| 69 | +// to encoding and decoding, the codec must provide a transit |
| 70 | +// type which is capable of copying a data stream in order to |
| 71 | +// delay decoding into an object until finally received. |
| 72 | +// The RawMessage must return an object similar to json.RawMessage |
| 73 | +// with the capability of decoding itself into an object. |
| 74 | +type ChannelCodec interface { |
| 75 | + NewEncoder(io.Writer, ChannelFactory) Encoder |
| 76 | + NewDecoder(io.Reader, ChannelReceiver, reflect.Type, reflect.Type, reflect.Type) Decoder |
| 77 | + NewRawMessage() Decoder |
| 78 | +} |
0 commit comments