예제 #1
0
func (c *clientCodec) ReadHeader(m *codec.Message) error {
	c.resp.reset()
	if err := c.dec.Decode(&c.resp); err != nil {
		return err
	}

	c.Lock()
	m.Method = c.pending[c.resp.ID]
	delete(c.pending, c.resp.ID)
	c.Unlock()

	m.Error = ""
	m.Id = c.resp.ID
	if c.resp.Error != nil {
		x, ok := c.resp.Error.(string)
		if !ok {
			return fmt.Errorf("invalid error %v", c.resp.Error)
		}
		if x == "" {
			x = "unspecified error"
		}
		m.Error = x
	}
	return nil
}
예제 #2
0
파일: codec.go 프로젝트: micro/go-plugins
func (s *serverCodec) ReadHeader(m *codec.Message) error {
	r := &request{}
	if err := bson.UnmarshalFromStream(s.rwc, r); err != nil {
		return err
	}
	m.Id = r.Seq
	m.Method = r.ServiceMethod
	return nil
}
예제 #3
0
파일: codec.go 프로젝트: micro/go-plugins
func (c *clientCodec) ReadHeader(m *codec.Message) error {
	r := &response{}
	if err := bson.UnmarshalFromStream(c.rwc, r); err != nil {
		return err
	}
	m.Id = r.Seq
	m.Method = r.ServiceMethod
	m.Error = r.Error
	return nil
}
예제 #4
0
func (c *serverCodec) ReadHeader(m *codec.Message) error {
	c.req.reset()
	if err := c.dec.Decode(&c.req); err != nil {
		return err
	}
	m.Method = c.req.Method

	c.Lock()
	c.seq++
	c.pending[c.seq] = c.req.ID
	c.req.ID = nil
	m.Id = c.seq
	c.Unlock()

	return nil
}
예제 #5
0
파일: codec.go 프로젝트: micro/go-plugins
// ReadHeader reads the header from the wire.
func (c *msgpackCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error {
	c.mt = mt

	switch mt {
	case codec.Request:
		var h Request

		if err := msgp.Decode(c.rwc, &h); err != nil {
			return err
		}

		c.body = h.hasBody
		m.Id = uint64(h.ID)
		m.Method = h.Method

	case codec.Response:
		var h Response

		if err := msgp.Decode(c.rwc, &h); err != nil {
			return err
		}

		c.body = h.hasBody
		m.Id = uint64(h.ID)
		m.Error = h.Error

	case codec.Publication:
		var h Notification

		if err := msgp.Decode(c.rwc, &h); err != nil {
			return err
		}

		c.body = h.hasBody
		m.Method = h.Method

	default:
		return errors.New("Unrecognized message type")
	}

	return nil
}
예제 #6
0
func (c *rpcPlusCodec) ReadRequestHeader(r *request, first bool) error {
	m := codec.Message{Header: c.req.Header}

	if !first {
		var tm transport.Message
		if err := c.socket.Recv(&tm); err != nil {
			return err
		}
		c.buf.rbuf.Reset()
		if _, err := c.buf.rbuf.Write(tm.Body); err != nil {
			return err
		}

		m.Header = tm.Header
	}

	err := c.codec.ReadHeader(&m, codec.Request)
	r.ServiceMethod = m.Method
	r.Seq = m.Id
	return err
}
예제 #7
0
func (c *protoCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error {
	c.buf.Reset()
	c.mt = mt

	switch mt {
	case codec.Request:
		data, err := ReadNetString(c.rwc)
		if err != nil {
			return err
		}
		rtmp := new(Request)
		err = proto.Unmarshal(data, rtmp)
		if err != nil {
			return err
		}
		m.Method = *rtmp.ServiceMethod
		m.Id = *rtmp.Seq
	case codec.Response:
		data, err := ReadNetString(c.rwc)
		if err != nil {
			return err
		}
		rtmp := new(Response)
		err = proto.Unmarshal(data, rtmp)
		if err != nil {
			return err
		}
		m.Method = *rtmp.ServiceMethod
		m.Id = *rtmp.Seq
		m.Error = *rtmp.Error
	case codec.Publication:
		io.Copy(c.buf, c.rwc)
	default:
		return fmt.Errorf("Unrecognised message type: %v", mt)
	}
	return nil
}
예제 #8
0
파일: mercury.go 프로젝트: micro/go-plugins
func (c *mercuryCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error {
	c.buf.Reset()
	c.mt = mt

	switch mt {
	case codec.Request:
		m.Method = m.Header["Endpoint"]
		io.Copy(c.buf, c.rwc)
	case codec.Response:
		io.Copy(c.buf, c.rwc)
	case codec.Publication:
		io.Copy(c.buf, c.rwc)
	default:
		return fmt.Errorf("Unrecognised message type: %v", mt)
	}
	return nil
}