Пример #1
0
// Wraps encoder.DeserializeRawToValue and traps panics as an error
func (self *Serializer) deserializeMessage(messageData []byte, reflectValue reflect.Value) (usedBytesCount int, err error) {
	defer func() {
		if r := recover(); r != nil {
			switch x := r.(type) {
			case string:
				err = errors.New(x)
			case error:
				err = x
			default:
				err = errors.New("interface{} deserialization failed")
			}
		}
	}()
	usedBytesCount, err = encoder.DeserializeRawToValue(messageData, reflectValue)
	return
}
Пример #2
0
// Wraps encoder.DeserializeRawToValue and traps panics as an error
func deserializeMessage(msg []byte, v reflect.Value) (n int, e error) {
	defer func() {
		if r := recover(); r != nil {
			logger.Debug("Recovering from deserializer panic: %v", r)
			switch x := r.(type) {
			case string:
				e = errors.New(x)
			case error:
				e = x
			default:
				e = errors.New("Message deserialization failed")
			}
		}
	}()
	n, e = encoder.DeserializeRawToValue(msg, v)
	return
}
Пример #3
0
func (s *UDPTransport) receiveMessage(buffer []byte) {
	if s.crypto != nil {
		buffer = s.crypto.Decrypt(buffer)
	}
	var v reflect.Value = reflect.New(reflect.TypeOf([]byte{}))
	_, err := encoder.DeserializeRawToValue(buffer, v)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error on DeserializeRawToValue: %v\n", err)
		return
	}
	m, succ := (v.Elem().Interface()).(interface{})
	if !succ {
		fmt.Fprintf(os.Stderr, "Error on Interface()\n")
		return
	}
	recv_chan := s.messagesReceived
	if recv_chan != nil {
		recv_chan <- m.([]byte)
	}
}
Пример #4
0
// Wraps encoder.DeserializeRawToValue and traps panics as an error
func deserializeMessage(msg []byte, v reflect.Value) (n int, e error) {
	n, e = encoder.DeserializeRawToValue(msg, v)
	return
}