thrift 网络结构说明
来源:互联网 发布:网络语言9代表什么意思 编辑:程序博客网 时间:2024/06/05 11:59
Thrift network stack
Simple representation of the Apache Thrift networking stack
+-------------------------------------------+
| Server |
| (single-threaded, event-driven etc) |
+-------------------------------------------+
| Processor |
| (compiler generated) |
+-------------------------------------------+
| Protocol |
| (JSON, compact etc) |
+-------------------------------------------+
| Transport |
| (raw TCP, HTTP etc) |
+-------------------------------------------+
Transport
The Transport layer provides a simple abstraction for reading/writing from/to the network. This enables Thrift to decouple the underlying transport from the rest of the system (serialization/deserialization, for instance).
Here are some of the methods exposed by the Transport interface:
open
close
read
write
flush
In addition to the Transport interface above, Thrift also uses a ServerTransport interface used to accept or create primitive transport objects. As the name suggest, ServerTransport is used mainly on the server side to create new Transport objects for incoming connections.
open
listen
accept
close
Here are some of the transports available for majority of the Thrift-supported languages:
file: read/write to/from a file on disk
http: as the name suggests
Protocol
The Protocol abstraction defines a mechanism to map in-memory data structures to a wire-format. In other words, a protocol specifies how datatypes use the underlying Transport to encode/decode themselves. Thus the protocol implementation governs the encoding scheme and is responsible for (de)serialization. Some examples of protocols in this sense include JSON, XML, plain text, compact binary etc.
Here is the Protocol interface:
writeMessageBegin(name, type, seq)
writeMessageEnd()
writeStructBegin(name)
writeStructEnd()
writeFieldBegin(name, type, id)
writeFieldEnd()
writeFieldStop()
writeMapBegin(ktype, vtype, size)
writeMapEnd()
writeListBegin(etype, size)
writeListEnd()
writeSetBegin(etype, size)
writeSetEnd()
writeBool(bool)
writeByte(byte)
writeI16(i16)
writeI32(i32)
writeI64(i64)
writeDouble(double)
writeString(string)
name, type, seq = readMessageBegin()
readMessageEnd()
name = readStructBegin()
readStructEnd()
name, type, id = readFieldBegin()
readFieldEnd()
k, v, size = readMapBegin()
readMapEnd()
etype, size = readListBegin()
readListEnd()
etype, size = readSetBegin()
readSetEnd()
bool = readBool()
byte = readByte()
i16 = readI16()
i32 = readI32()
i64 = readI64()
double = readDouble()
string = readString()
Thrift Protocols are stream oriented by design. There is no need for any explicit framing. For instance, it is not necessary to know the length of a string or the number of items in a list before we start serializing them. Some of the protocols available for majority of the Thrift-supported languages are:
binary: Fairly simple binary encoding – the length and type of a field are encoded as bytes followed by the actual value of the field.
compact: Described in THRIFT-110
json
Processor
A Processor encapsulates the ability to read data from input streams and write to output streams. The input and output streams are represented by Protocol objects. The Processor interface is extremely simple
interface TProcessor {
bool process(TProtocol in, TProtocol out) throws TException
}
Service-specific processor implementations are generated by the compiler. The Processor essentially reads data from the wire (using the input protocol), delegates processing to the handler (implemented by the user) and writes the response over the wire (using the output protocol).
Server
A Server pulls together all of the various features described above:
Create a transport
Create input/output protocols for the transport
Create a processor based on the input/output protocols
Wait for incoming connections and hand them off to the processor
- thrift 网络结构说明
- thrift说明和测试
- Thrift IDL中文说明
- Thrift的层次结构
- windows网络编程-结构体说明
- Thrift 接口描述语言说明
- Thrift C++ server 网络架构
- thrift安装说明(Windows下CYGWIN)
- thrift三种server方式说明
- Thrift 网络通信库 编译部署小结
- Thrift
- thrift
- thrift
- thrift
- Thrift
- Thrift
- thrift
- thrift
- KindEditor插件生成编辑工具
- 算法导论 笔记
- CityEngine Web Viewer IIS 部署
- myeclipse 在线更新 spket
- GROUP BY规则
- thrift 网络结构说明
- Android JNI 编译正确 但是提示程序有错误无法运行 而且还看不到任何错误提示 的解决方法
- C# MVC 自学笔记—2 MVC Movie简介
- Arduino and the SPI bus
- 控制台 看书
- linux 如何获取系统音量修改系统音量
- request_mem_region 申请物理内存函数
- Libgdx实现异步加载网络图片并保存到SD卡或者data/data目录下边
- thrift特点介绍