> For the complete documentation index, see [llms.txt](https://298073941.gitbook.io/memo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://298073941.gitbook.io/memo/dubbo/codec.md).

# codec

#### AbstractEndpoint 这个类 是所有client和Server的抽象父类，内部有个编码器codec通过这个来序列化和反序列化

#### 查看构造器发现codec通过url来获取的

#### 看过上面spi的话，应该就很容易了解dubbo的codec编码器机制

#### dubbo默认一般使用dubbo协议，直接观看DubboProtocol类

* 查看createServer
* 发现url参数设置的CODE\_KEY为DubboCodec.NAME

所以可以推测dubboCodec是dubbo解码器和编码器，查看内部实现

#### DubboCountCodec

* 内部持有dubbocodec
* 主要讲下序列化，发现内部有个CodecSupport
* 内部核心调用getSerialization
* 也是通过spi机制，不过有个缓存已经预加载了所有序列化工具
* body序列化默认是hession2

#### dubbo请求结构

* 请求头HEAD\_LENGTH:16字节
  * MAGIC  0xdabb 2字节
  * flag
    * 高位
      * 0x20 FLAG\_EVENT
      * 0x40 FLAG\_TWOWAY
      * 0x80 FLAG\_REQUEST
    * 低位
      * 序列器id
  * 响应状态status 1字节，枚举查看response类
  * 请求id 8字节
  * DATA\_LENGTH  offSet 4字节
* 解析body，通过CodecSupport序列化

#### CodecSupport

* 里面的通过序列器id寻找序列化工具
* 查看方法可以发现使用默认hession2序列工具


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://298073941.gitbook.io/memo/dubbo/codec.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
