winlin

add graph comments for size of request and response.

@@ -150,13 +150,29 @@ void SrsKafkaRequestHeader::set_api_key(SrsKafkaApiKey key) @@ -150,13 +150,29 @@ void SrsKafkaRequestHeader::set_api_key(SrsKafkaApiKey key)
150 api_key = (int16_t)key; 150 api_key = (int16_t)key;
151 } 151 }
152 152
153 -SrsKafkaResponse::SrsKafkaResponse() 153 +SrsKafkaResponseHeader::SrsKafkaResponseHeader()
154 { 154 {
  155 + size = 0;
155 correlation_id = 0; 156 correlation_id = 0;
156 } 157 }
157 158
158 -SrsKafkaResponse::~SrsKafkaResponse() 159 +SrsKafkaResponseHeader::~SrsKafkaResponseHeader()
  160 +{
  161 +}
  162 +
  163 +int SrsKafkaResponseHeader::header_size()
  164 +{
  165 + return 4;
  166 +}
  167 +
  168 +int SrsKafkaResponseHeader::message_size()
  169 +{
  170 + return size - header_size();
  171 +}
  172 +
  173 +int SrsKafkaResponseHeader::total_size()
159 { 174 {
  175 + return 4 + size;
160 } 176 }
161 177
162 SrsKafkaMessage::SrsKafkaMessage() 178 SrsKafkaMessage::SrsKafkaMessage()
@@ -179,18 +179,24 @@ public: @@ -179,18 +179,24 @@ public:
179 virtual ~SrsKafkaRequestHeader(); 179 virtual ~SrsKafkaRequestHeader();
180 public: 180 public:
181 /** 181 /**
182 - * the size of header, exclude the 4bytes size.  
183 - * @remark total_size = 4 + header_size + message_size. 182 + * the layout of request:
  183 + * +-----------+----------------------------------+
  184 + * | 4B size | [size] bytes |
  185 + * +-----------+------------+---------------------+
  186 + * | 4B size | header | message |
  187 + * +-----------+------------+---------------------+
  188 + * | total size = 4 + header + message |
  189 + * +----------------------------------------------+
  190 + * where the header is specifies this request header without the start 4B size.
  191 + * @remark size = 4 + header + message.
184 */ 192 */
185 virtual int header_size(); 193 virtual int header_size();
186 /** 194 /**
187 * the size of message, the bytes left after the header. 195 * the size of message, the bytes left after the header.
188 - * @remark total_size = 4 + header_size + message_size.  
189 */ 196 */
190 virtual int message_size(); 197 virtual int message_size();
191 /** 198 /**
192 - * the total size of the request, 4bytes + size of header and message.  
193 - * @remark total_size = 4 + header_size + message_size. 199 + * the total size of the request, includes the 4B size.
194 */ 200 */
195 virtual int total_size(); 201 virtual int total_size();
196 public: 202 public:
@@ -210,21 +216,53 @@ public: @@ -210,21 +216,53 @@ public:
210 }; 216 };
211 217
212 /** 218 /**
213 - * the common kafka response. 219 + * the header of response, include the size of response.
214 * The response will always match the paired request (e.g. we will 220 * The response will always match the paired request (e.g. we will
215 * send a MetadataResponse in return to a MetadataRequest). 221 * send a MetadataResponse in return to a MetadataRequest).
216 * @see https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-Responses 222 * @see https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-Responses
217 */ 223 */
218 -class SrsKafkaResponse 224 +class SrsKafkaResponseHeader
219 { 225 {
220 -protected: 226 +private:
221 /** 227 /**
222 - * The server passes back whatever integer the client supplied as the correlation in the request. 228 + * The MessageSize field gives the size of the subsequent request or response
  229 + * message in bytes. The client can read requests by first reading this 4 byte
  230 + * size as an integer N, and then reading and parsing the subsequent N bytes
  231 + * of the request.
  232 + */
  233 + int32_t size;
  234 +private:
  235 + /**
  236 + * This is a user-supplied integer. It will be passed back in
  237 + * the response by the server, unmodified. It is useful for matching
  238 + * request and response between the client and server.
223 */ 239 */
224 int32_t correlation_id; 240 int32_t correlation_id;
225 public: 241 public:
226 - SrsKafkaResponse();  
227 - virtual ~SrsKafkaResponse(); 242 + SrsKafkaResponseHeader();
  243 + virtual ~SrsKafkaResponseHeader();
  244 +public:
  245 + /**
  246 + * the layout of response:
  247 + * +-----------+----------------------------------+
  248 + * | 4B size | [size] bytes |
  249 + * +-----------+------------+---------------------+
  250 + * | 4B size | 4B header | message |
  251 + * +-----------+------------+---------------------+
  252 + * | total size = 4 + 4 + message |
  253 + * +----------------------------------------------+
  254 + * where the header is specifies this request header without the start 4B size.
  255 + * @remark size = 4 + 4 + message.
  256 + */
  257 + virtual int header_size();
  258 + /**
  259 + * the size of message, the bytes left after the header.
  260 + */
  261 + virtual int message_size();
  262 + /**
  263 + * the total size of the request, includes the 4B size.
  264 + */
  265 + virtual int total_size();
228 }; 266 };
229 267
230 /** 268 /**
@@ -316,6 +354,15 @@ public: @@ -316,6 +354,15 @@ public:
316 virtual ~SrsKafkaTopicMetadataRequest(); 354 virtual ~SrsKafkaTopicMetadataRequest();
317 }; 355 };
318 356
  357 +class SrsKafkaTopicMetadataResponse
  358 +{
  359 +private:
  360 + SrsKafkaRequestHeader header;
  361 +public:
  362 + SrsKafkaTopicMetadataResponse();
  363 + virtual ~SrsKafkaTopicMetadataResponse();
  364 +};
  365 +
319 /** 366 /**
320 * the kafka protocol stack, use to send and recv kakfa messages. 367 * the kafka protocol stack, use to send and recv kakfa messages.
321 */ 368 */