Example #1
0
// Receive receives a message sent across the channel from
// a sender on the other side of the transport.
func (r *receiver) Receive(message interface{}) error {
	r.decodeLock.Lock()
	defer r.decodeLock.Unlock()
	if r.decoder == nil {
		r.decoder = msgpack.NewDecoder(r.stream)
		r.decoder.AddExtensions(r.stream.initializeExtensions())
	}

	decodeErr := r.decoder.Decode(message)
	if decodeErr == io.EOF {
		r.stream.Close()
		r.decoder = nil
	}
	return decodeErr
}
Example #2
0
// Receive receives a message sent across the channel from
// a sender on the other side of the transport.
func (c *channel) Receive(message interface{}) error {
	if c.direction == outbound {
		return ErrWrongDirection
	}

	c.decodeLock.Lock()
	defer c.decodeLock.Unlock()
	if c.decoder == nil {
		c.decoder = msgpack.NewDecoder(c.stream)
		c.decoder.AddExtensions(c.initializeExtensions())
	}

	decodeErr := c.decoder.Decode(message)
	if decodeErr == io.EOF {
		c.stream.Close()
		c.decoder = nil
	}
	return decodeErr
}