Ejemplo n.º 1
0
// Handle handles the given binary payload.
func (s Server) Handle(data []byte) ([]byte, error) {
	request, err := s.p.DecodeEnveloped(bytes.NewReader(data))
	if err != nil {
		return nil, err
	}

	response := wire.Envelope{
		Name:  request.Name,
		SeqID: request.SeqID,
		Type:  wire.Reply,
	}

	response.Value, err = s.h.Handle(request.Name, request.Value)
	if err != nil {
		response.Type = wire.Exception
		switch err.(type) {
		case ErrUnknownMethod:
			response.Value, err = tappExc(err, exception.ExceptionTypeUnknownMethod)
		default:
			response.Value, err = tappExc(err, exception.ExceptionTypeInternalError)
		}

		if err != nil {
			return nil, err
		}
	}

	var buff bytes.Buffer
	if err := s.p.EncodeEnveloped(response, &buff); err != nil {
		return nil, err
	}

	return buff.Bytes(), nil
}
Ejemplo n.º 2
0
func (bw *Reader) readStrictNameType(initial int32, off int64) (wire.Envelope, int64, error) {
	var e wire.Envelope

	if v := uint32(initial) & versionMask; v != version1 {
		return e, off, fmt.Errorf("cannot decode envelope of version: %v", v)
	}

	// This will truncate the bits that are not required.
	e.Type = wire.EnvelopeType(initial)

	var err error
	e.Name, off, err = bw.readString(off)
	return e, off, err
}
Ejemplo n.º 3
0
func (bw *Reader) readNonStrictNameType() (wire.Envelope, int64, error) {
	var e wire.Envelope

	name, off, err := bw.readString(0)
	if err != nil {
		return e, off, err
	}
	e.Name = name

	typeID, off, err := bw.readByte(off)
	if err != nil {
		return e, off, err
	}
	e.Type = wire.EnvelopeType(typeID)

	return e, off, nil
}
Ejemplo n.º 4
0
func (m multiplexedOutboundProtocol) EncodeEnveloped(e wire.Envelope, w io.Writer) error {
	e.Name = m.Service + ":" + e.Name
	return m.Protocol.EncodeEnveloped(e, w)
}