本文整理汇总了Golang中net/rpc.Request.Seq方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Seq方法的具体用法?Golang Request.Seq怎么用?Golang Request.Seq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/rpc.Request
的用法示例。
在下文中一共展示了Request.Seq方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ReadRequestHeader
func (c *serverCodec) ReadRequestHeader(request *rpc.Request) error {
name, messageType, seq, err := c.protocol.ReadMessageBegin(c.transport)
if err != nil {
return err
}
if messageType != MessageTypeCall { // Currently don't support one way
return errors.New("thrift: expected Call message type")
}
// TODO: should use a limited size cache for the nameCache to avoid a possible
// memory overflow from nefarious or broken clients
newName := c.nameCache[name]
if newName == "" {
newName = CamelCase(name)
if !strings.ContainsRune(newName, '.') {
newName = "Thrift." + newName
}
c.nameCache[name] = newName
}
c.mu.Lock()
c.methodName[uint64(seq)] = name
c.mu.Unlock()
request.ServiceMethod = newName
request.Seq = uint64(seq)
return nil
}
示例2: ReadRequestHeader
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
var sz uint16
err := binary.Read(c.c, binary.BigEndian, &sz)
if err != nil {
return err
}
log.Print("sz: ", sz)
raw_message := make([]byte, sz)
n, err := io.ReadFull(c.c, raw_message)
if err != nil || n != int(sz) {
return err
}
c.req.reset()
log.Print("raw_message: ", string(raw_message))
err = json.Unmarshal(raw_message, &(c.req))
log.Print("after unmarshal: ", c.req)
if err != nil {
log.Print("err: ", err)
return err
}
r.ServiceMethod = c.req.Method
c.mutex.Lock()
c.seq++
c.pending[c.seq] = c.req.Id
c.req.Id = nil
r.Seq = c.seq
c.mutex.Unlock()
return nil
}
示例3: innerReadRequestHeader
func (c *RedisServerCodec) innerReadRequestHeader(r *rpc.Request) (err error) {
defer func() {
if ret := recover(); ret != nil {
err = errors.Errorf("Read Header:%s", ret)
}
}()
m, err := bufioReadMessage(c.r)
if err != nil {
return
}
arr, err := m.Array()
if err != nil {
err = errors.Errorf("must by array type:%v", m.Type)
return
}
op, _ := arr[0].Str()
op = strings.ToLower(op)
method, ok := methodMap[op]
if !ok {
err = errors.Errorf("method not supported:%s", op)
return
}
r.ServiceMethod = method
c.seq++
r.Seq = c.seq
c.msg = m
return nil
}
示例4: Call
func (this *Client) Call(method string, arg interface{}, reply interface{}) (e error) {
clientConn := new(clientConn)
clientConn.rest()
this.codec = NewClientCodec(clientConn)
req := rpc.Request{}
req.Seq = defaultIdCreator.NewId()
req.ServiceMethod = method
e = this.codec.WriteRequest(&req, arg)
buffer := bytes.NewBuffer(clientConn.Data)
resp, e := http.Post(this.addr, "application/json", buffer)
if e != nil {
return
}
clientConn.SetResponse(resp)
tmp := &rpc.Response{}
e = this.codec.ReadResponseHeader(tmp)
if e != nil {
return
}
e = this.codec.ReadResponseBody(reply)
if e != nil {
return
}
fmt.Println(string(clientConn.Data))
return
}
示例5: ReadRequestHeader
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
var req protorpcpb.Request
if err := readFrame(c.rwc, &req); err != nil {
return err
}
r.ServiceMethod = req.GetMethod()
r.Seq = req.GetSeq()
return nil
}
示例6: writeRequest
func writeRequest(c *clientCodec) error {
head := rpc.Request{}
head.ServiceMethod = "TestFunc"
head.Seq = 1
body := testpb.Request{}
body.Query = proto.String("ping www.tencent.com")
return c.WriteRequest(&head, &body)
}
示例7: ReadRequestHeader
func (c *codec) ReadRequestHeader(r *rpc.Request) error {
c.header = internal.Header{} // reset
if err := c.decode(&c.header); err != nil {
return err
}
r.ServiceMethod = c.header.Method
r.Seq = c.header.SeqID
return nil
}
示例8: ReadRequestHeader
// ReadRequestHeader receives and decodes a net/rpc request header r.
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
// This is almost identical to ReadResponseHeader(), above.
var err error
var hdr ProtoRPCRequestHeader
if err = c.m.ReadMessage(&hdr); err != nil {
// Don't log an error here, since this is where normal EOF
// happens over net/rpc channels, e.g., if a client finishes and
// disconnects.
return err
}
r.Seq = *hdr.Seq
r.ServiceMethod = *hdr.Op
return nil
}
示例9: ReadRequestHeader
// ReadRequestHeader reads the header protobuf (which is prefixed by a uvarint
// indicating its size) from the connection, decodes it, and stores the fields
// in the given request.
func (s *ServerCodec) ReadRequestHeader(req *rpc.Request) error {
var header wire.Header
if err := ReadProto(s.r, &header); err != nil {
return err
}
if header.Method == nil {
return fmt.Errorf("header missing method: %s", header)
}
if header.Seq == nil {
return fmt.Errorf("header missing seq: %s", header)
}
req.ServiceMethod = *header.Method
req.Seq = *header.Seq
return nil
}
示例10: ReadRequestHeader
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
msg := <-c.msgs
c.req.reset()
if err := json.Unmarshal(msg.Body, &c.req); err != nil {
return err
}
r.ServiceMethod = c.req.Method
c.Lock()
c.seq++
c.pending[c.seq] = prop{msg.CorrelationId, msg.ReplyTo}
r.Seq = c.seq
c.Unlock()
return nil
}
示例11: ReadRequestHeader
func (this *ServerCodec) ReadRequestHeader(r *rpc.Request) (e error) {
data, e := ioutil.ReadAll(this.conn)
if e != nil {
log.Println(e.Error())
return
}
e = json.Unmarshal(data, &this.req)
if e != nil {
this.resp.Error = e.Error()
return
}
r.Seq = this.req.Id
r.ServiceMethod = this.req.Method
log.Println("req:", string(*this.req.Params))
return
}
示例12: ReadRequestHeader
func (server *serverCodec) ReadRequestHeader(r *rpc.Request) error {
server.curDelivery = <-server.message
if server.curDelivery.CorrelationId == "" {
return errors.New("no routing key in delivery")
}
r.Seq = atomic.AddUint64(&server.seq, 1)
server.lock.Lock()
server.calls[r.Seq] = route{server.curDelivery.MessageId, server.curDelivery.CorrelationId}
server.lock.Unlock()
r.ServiceMethod = server.curDelivery.ReplyTo
return nil
}
示例13: ReadRequestHeader
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
header := wire.RequestHeader{}
err := readRequestHeader(c.r, &header)
if err != nil {
return err
}
c.mutex.Lock()
c.seq++
c.pending[c.seq] = header.GetId()
r.ServiceMethod = header.GetMethod()
r.Seq = c.seq
c.mutex.Unlock()
c.reqHeader = header
return nil
}
示例14: TestRW
func TestRW(t *testing.T) {
var buf bufc
var c codec
c.w = &buf
var req rpc.Request
req.Seq = 1
req.ServiceMethod = "foo"
c.WriteRequest(&req, nil)
c.r = bufio.NewReader(&buf)
c.ReadRequestHeader(&req)
if req.Seq != 1 || req.ServiceMethod != "foo" {
t.Errorf("Request decode/encode mismatch")
}
}
示例15: ReadRequestHeader
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
c.req.Reset()
packer, err := readPack(c.r, &c.req)
if err != nil {
return err
}
c.packer = packer
r.ServiceMethod = c.req.Method
c.mutex.Lock()
c.seq++
c.pending[c.seq] = c.req.Id
c.req.Id = 0
r.Seq = c.seq
c.mutex.Unlock()
return nil
}