| 141 | } |
| 142 | |
| 143 | static void SerializeSofaHeaderAndMeta( |
| 144 | butil::IOBuf* out, const SofaRpcMeta& meta, int payload_size) { |
| 145 | const uint32_t meta_size = GetProtobufByteSize(meta); |
| 146 | if (meta_size <= 232) { // most common cases |
| 147 | char header_and_meta[24 + meta_size]; |
| 148 | PackSofaHeader(header_and_meta, meta_size, payload_size); |
| 149 | ::google::protobuf::io::ArrayOutputStream arr_out(header_and_meta + 24, meta_size); |
| 150 | ::google::protobuf::io::CodedOutputStream coded_out(&arr_out); |
| 151 | meta.SerializeWithCachedSizes(&coded_out); // not calling ByteSize again |
| 152 | CHECK(!coded_out.HadError()); |
| 153 | out->append(header_and_meta, sizeof(header_and_meta)); |
| 154 | } else { |
| 155 | char header[24]; |
| 156 | PackSofaHeader(header, meta_size, payload_size); |
| 157 | out->append(header, sizeof(header)); |
| 158 | butil::IOBufAsZeroCopyOutputStream buf_stream(out); |
| 159 | ::google::protobuf::io::CodedOutputStream coded_out(&buf_stream); |
| 160 | meta.SerializeWithCachedSizes(&coded_out); |
| 161 | CHECK(!coded_out.HadError()); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | ParseResult ParseSofaMessage(butil::IOBuf* source, Socket* socket, |
| 166 | bool /*read_eof*/, const void* /*arg*/) { |
no test coverage detected