Beispiel #1
0
func (s *session) Read() (internal.Packet, error) {
	var packet internal.Packet
	d := msgpack.NewDecoder(s.r)
	err := d.Decode(&packet)
	if err != nil {
		return internal.Packet{}, err
	}
	if !packet.Verify(s.rkey) {
		return internal.Packet{}, errors.New("receive wrong packet")
	}
	return packet, nil
}
Beispiel #2
0
func (s *session) Write(p internal.Packet) error {
	s.wmutex.Lock()
	defer s.wmutex.Unlock()
	err := p.Sign(s.lkey)
	if err != nil {
		return err
	}
	b, err := msgpack.Marshal(p)
	if err != nil {
		return err
	}
	_, err = s.w.Write(b)
	return err
}