thrift原理记录

栏目: 服务器 · 发布时间: 6年前

内容简介:1,整体网络栈2,具体Transport [传输层]

1,整体网络栈

+-------------------------------------------+
  | Server                                    |
  | (single-threaded, event-driven etc)       |
  +-------------------------------------------+
  | Processor                                 |
  | (compiler generated)                      |
  +-------------------------------------------+
  | Protocol                                  |
  | (JSON, compact etc)                       |
  +-------------------------------------------+
  | Transport                                 |
  | (raw TCP, HTTP etc)                       |
  +-------------------------------------------+

2,具体

Transport [传输层]

传输层对 网络读写 做了简单的抽象,它使thrift与其他系统层的传输层解耦。

thrift原理记录

golang thrift,定义基础结构体 TTransport,其他的transport都继承了该结构体。

主要暴露的方法有:

open,close,read,write,flush

同时,在传输层上层,还有ServerTransport,在服务端,构建接受请求的传输层。完成网络监听,请求接收等。

thrift原理记录

Protocol[协议层]

定义了数据编码解码的方式。完成数据的序列化/反序列化工作。主要包括 JSON, XML, plain text, compact binary 等方式。

thrift原理记录

thrift protocol实现流式输入输出。所以在序列化之前不需要知道字符的长度或者列表的个数。

Processor[处理器]

实现了将数据写入输出流,从输入流中读取数据。

type TProcessor interface {
       Process(in, out TProtocol) (bool, TException)
}

Server[服务器]

完成以下工作

1,创建一个传输层

2,为传输层创建协议模块【读写协议】

3,基于协议模块创建处理器

4,等待请求,并将请求交给处理器

示例:

thrift原理记录


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to the Design and Analysis of Algorithms

Introduction to the Design and Analysis of Algorithms

Anany Levitin / Addison Wesley / 2006-2-24 / USD 122.00

Based on a Based on a new classification of algorithm design techniques and a clear delineation of analysis methods, "Introduction to the Design and Analysis of Algorithms" presents the subject in a c......一起来看看 《Introduction to the Design and Analysis of Algorithms》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具