Exemple #1
0
// Send sends a message across the channel to a receiver on the
// other side of the transport.
func (s *sender) Send(message interface{}) error {
	s.encodeLock.Lock()
	defer s.encodeLock.Unlock()
	if s.encoder == nil {
		s.buffer = bufio.NewWriter(s.stream)
		s.encoder = msgpack.NewEncoder(s.buffer)
		s.encoder.AddExtensions(s.stream.initializeExtensions())
	}

	if err := s.encoder.Encode(message); err != nil {
		return err
	}

	return s.buffer.Flush()
}
Exemple #2
0
// Send sends a message across the channel to a receiver on the
// other side of the transport.
func (c *channel) Send(message interface{}) error {
	if c.direction == inbound {
		return ErrWrongDirection
	}

	c.encodeLock.Lock()
	defer c.encodeLock.Unlock()
	if c.encoder == nil {
		c.buffer = bufio.NewWriter(c.stream)
		c.encoder = msgpack.NewEncoder(c.buffer)
		c.encoder.AddExtensions(c.initializeExtensions())
	}

	if err := c.encoder.Encode(message); err != nil {
		return err
	}

	return c.buffer.Flush()
}