MCPcopy Create free account
hub / github.com/apache/dubbo-go / EncodeHeader

Method EncodeHeader

protocol/dubbo/impl/codec.go:108–129  ·  view source on GitHub ↗
(p DubboPackage)

Source from the content-addressed store, hash-verified

106}
107
108func (c *ProtocolCodec) EncodeHeader(p DubboPackage) []byte {
109 header := p.Header
110 bs := make([]byte, 0)
111 switch header.Type {
112 case PackageHeartbeat:
113 if header.ResponseStatus == Zero {
114 bs = append(bs, hessian.DubboRequestHeartbeatHeader[:]...)
115 } else {
116 bs = append(bs, hessian.DubboResponseHeartbeatHeader[:]...)
117 }
118 case PackageResponse:
119 bs = append(bs, hessian.DubboResponseHeaderBytes[:]...)
120 if header.ResponseStatus != 0 {
121 bs[3] = header.ResponseStatus
122 }
123 case PackageRequest_TwoWay:
124 bs = append(bs, hessian.DubboRequestHeaderBytesTwoWay[:]...)
125 }
126 bs[2] |= header.SerialID & hessian.SERIAL_MASK
127 binary.BigEndian.PutUint64(bs[4:], uint64(header.ID))
128 return bs
129}
130
131func (c *ProtocolCodec) Encode(p DubboPackage) ([]byte, error) {
132 // header

Calls

no outgoing calls

Tested by 4

TestEncodeHeaderResponseFunction · 0.64