当前位置: 首页 > wzjs >正文

网站建设 中企动力南通建网站平台要多少钱

网站建设 中企动力南通,建网站平台要多少钱,服务器搭建网站跑不满宽带,h5生成codec 包基础设计 package:trpc-go/codec Msg接口的定义: 后续实际的消息msg结构体实现该接口,可以方便地获取一些值(如Context),也可以方便地进行一些值地设置(如设置SerializationType) //…

codec 包基础设计

package:trpc-go/codec

  1. Msg接口的定义: 后续实际的消息msg结构体实现该接口,可以方便地获取一些值(如Context),也可以方便地进行一些值地设置(如设置SerializationType)
// message.go 文件下 // Msg defines core message data for multi protocol, business protocol
// should set this message when packing and unpacking data.
type Msg interface {// Context returns rpc contextContext() context.Context// WithRemoteAddr sets upstream address for server,// or downstream address for client.WithRemoteAddr(addr net.Addr)// WithLocalAddr sets server local address.WithLocalAddr(addr net.Addr)// RemoteAddr returns upstream address for server,// or downstream address for client.RemoteAddr() net.Addr// LocalAddr returns server local address.LocalAddr() net.Addr// WithNamespace sets server namespace.WithNamespace(string)// Namespace returns server namespace.Namespace() string// WithEnvName sets server environment.WithEnvName(string)// SerializationType returns serialization type.SerializationType() int// WithCompressType sets compress type.WithCompressType(int)....
  1. msg 整个rpc的上下文,先看接口体的设计,以及实现上面Msg接口定义的方法
// message_impl.go 文件// msg is the context of rpc.
type msg struct {context             context.ContextframeHead           interface{}requestTimeout      time.DurationserializationType   intcompressType        intstreamID            uint32dyeing              booldyeingKey           stringserverRPCName       stringclientRPCName       stringserverMetaData      MetaDataclientMetaData      MetaDatacallerServiceName   stringcalleeServiceName   stringcalleeContainerName stringserverRspErr        errorclientRspErr        errorserverReqHead       interface{}serverRspHead       interface{}clientReqHead       interface{}clientRspHead       interface{}localAddr           net.AddrremoteAddr          net.Addrlogger              interface{}callerApp           stringcallerServer        stringcallerService       stringcallerMethod        stringcalleeApp           stringcalleeServer        stringcalleeService       stringcalleeMethod        stringnamespace           stringsetName             stringenvName             stringenvTransfer         stringrequestID           uint32calleeSetName       stringstreamFrame         interface{}commonMeta          CommonMetacallType            RequestType
}// 实现了 Msg接口所有方法
// Context restores old context when create new msg.
func (m *msg) Context() context.Context {return m.context
}// WithNamespace set server's namespace.
func (m *msg) WithNamespace(namespace string) {m.namespace = namespace
}
....

msg在后续:会被写入trpc协议的帧头中,进行网络传输,以达到下游
在这里插入图片描述

客户端调用 使用message:GreeterClientProxyImpl

  1. 客户端调用具体rpc方法桩代码:
func (c *GreeterClientProxyImpl) Hello(ctx context.Context, req *HelloRequest, opts ...client.Option) (*HelloReply, error) {// 派生出新的消息,以实现整个调用链路的context消息传递ctx, msg := codec.WithCloneMessage(ctx)defer codec.PutBackMessage(msg)msg.WithClientRPCName("/trpc.helloworld.Greeter/Hello")msg.WithCalleeServiceName(GreeterServer_ServiceDesc.ServiceName)msg.WithCalleeApp("")msg.WithCalleeServer("")msg.WithCalleeService("Greeter")msg.WithCalleeMethod("Hello")msg.WithSerializationType(codec.SerializationTypePB)callopts := make([]client.Option, 0, len(c.opts)+len(opts))callopts = append(callopts, c.opts...)callopts = append(callopts, opts...)rsp := &HelloReply{}if err := c.client.Invoke(ctx, req, rsp, callopts...); err != nil {return nil, err}return rsp, nil
}

先看WithCloneMessage方法:主要实现一组新的 ctx 和 msg 的派生

  • 首先可以看到第二个返回值Msg就是之前的接口类型
  • val.(*msg)是因为context中存储的不是实际结构体,而是结构体的指针
  • 所以上面桩代码中:msg.WithClientRPCName(“/trpc.helloworld.Greeter/Hello”),WithClientRPCName这些方法都是指针类型的实现:func (m *msg) xxx(namespace string) {
// message_impl.go 文件// WithCloneMessage copy a new message and put into context, each rpc call should
// create a new message, this method will be called by client stub.
func WithCloneMessage(ctx context.Context) (context.Context, Msg) {newMsg := msgPool.Get().(*msg)val := ctx.Value(ContextKeyMessage)m, ok := val.(*msg)if !ok {ctx = context.WithValue(ctx, ContextKeyMessage, newMsg)newMsg.context = ctxreturn ctx, newMsg}ctx = context.WithValue(ctx, ContextKeyMessage, newMsg)newMsg.context = ctxcopyCommonMessage(m, newMsg)copyServerToClientMessage(m, newMsg)return ctx, newMsg
}

到这里,一个派生的消息就从一个现有消息中拷贝了框架定义的一些上下文信息了,并且也设置了主调信息为自身服务,但是,被调信息呢?你回到开头看 tRPC 的桩代码就会知道了,桩代码里会负责进一步重写被调信息。

参考文献:

https://cloud.tencent.com/developer/article/2417507


文章转载自:

http://Rhl2qxDl.yjknk.cn
http://R1hHc8a3.yjknk.cn
http://KcMEywWx.yjknk.cn
http://dsU4D15T.yjknk.cn
http://hpB92M1e.yjknk.cn
http://6K4GYWjT.yjknk.cn
http://u6HsBwcR.yjknk.cn
http://MwBGvqEL.yjknk.cn
http://NvJlnx9K.yjknk.cn
http://Hn3MXZjE.yjknk.cn
http://VTF91KqY.yjknk.cn
http://K72k2Ssy.yjknk.cn
http://jKMnKio6.yjknk.cn
http://rxIWkcMD.yjknk.cn
http://AKjRUlpl.yjknk.cn
http://cX9XhdoH.yjknk.cn
http://RRfz1VBG.yjknk.cn
http://cCUE90kh.yjknk.cn
http://brGlq84G.yjknk.cn
http://8oatha7a.yjknk.cn
http://rmMGrird.yjknk.cn
http://IJN3WG4B.yjknk.cn
http://V2SxxNbZ.yjknk.cn
http://zxR2loAk.yjknk.cn
http://IKutRVs5.yjknk.cn
http://0z21NL5q.yjknk.cn
http://I8LiGGye.yjknk.cn
http://2dLxG6Z6.yjknk.cn
http://B8RgZuwt.yjknk.cn
http://m6uWO82L.yjknk.cn
http://www.dtcms.com/wzjs/705869.html

相关文章:

  • 快速搭建网站框架的工具多媒体设计与制作毕业设计
  • 设计师个人网站模板辽宁网站推广
  • 哈尔滨一个好网站建设如何开展网上营销
  • 影视文化网站建设wordpress会员插件
  • 厦门橄榄网站建设wordpress get tag
  • 盐城市城南建设局网站广州市花都区网站建设公司
  • 单页网站怎么制作教程wordpress改登陆界面
  • ps网站制作教程网页加速器排名
  • 上海外包公司网站建设桂林人才网
  • 商城网站是免费开吗做网站服务器空间
  • 哈尔滨seo网站管理旅游网站界面设计
  • 成都网站公司网站建设网站怎样做移动端
  • 北京网站制作出名 乐云践新开发网站的经济可行性
  • 宣讲家网站 家风建设自己可以学着做网站吗
  • 门户网站建站目标网站建站平台源码
  • 在线字体设计网站商城网站建站系统
  • 做外国购物网站需要交税吗广州最新防疫动态
  • 缔客网络上海响应式网站建设网站所有二级目录
  • 怎么查寻一个网站做的竞价wordpress 2016
  • 深圳市保障房申请网站深圳营销型网站建设优化
  • 网站开发在线培训asp 网站名字
  • 佛山新网站建设方案wordpress 原生中文主题
  • 建设通网站企业网站建设费用记入什么科目
  • 图片设计制作网站dw建设的网站怎么看
  • 合肥市建设工程合同备案网站php餐饮美食店网站源码 生成html
  • 国外做网站公司能赚钱下载搭建网站软件下载
  • 爱写作网站枣阳城乡建设局网站
  • 合肥手机网站建设etherna 简洁商业企业wordpress
  • 电商的网站工业设计招聘信息网站
  • 新人如何做自己的网站黄岩区信誉好高端网站设计