MCPcopy Create free account
hub / github.com/ceph/ceph / encode

Method encode

src/msg/Message.cc:237–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235#define dout_subsys ceph_subsys_ms
236
237void Message::encode(uint64_t features, int crcflags, bool skip_header_crc)
238{
239 // encode and copy out of *m
240 if (empty_payload()) {
241 ceph_assert(middle.length() == 0);
242 encode_payload(features);
243
244 if (byte_throttler) {
245 byte_throttler->take(payload.length() + middle.length());
246 }
247
248 // if the encoder didn't specify past compatibility, we assume it
249 // is incompatible.
250 if (header.compat_version == 0)
251 header.compat_version = header.version;
252 }
253 if (crcflags & MSG_CRC_HEADER)
254 calc_front_crc();
255
256 // update envelope
257 header.front_len = get_payload().length();
258 header.middle_len = get_middle().length();
259 header.data_len = get_data().length();
260 if (!skip_header_crc && (crcflags & MSG_CRC_HEADER))
261 calc_header_crc();
262
263 footer.flags = CEPH_MSG_FOOTER_COMPLETE;
264
265 if (crcflags & MSG_CRC_DATA) {
266 calc_data_crc();
267
268#ifdef ENCODE_DUMP
269 bufferlist bl;
270 encode(get_header(), bl);
271
272 // dump the old footer format
273 ceph_msg_footer_old old_footer;
274 old_footer.front_crc = footer.front_crc;
275 old_footer.middle_crc = footer.middle_crc;
276 old_footer.data_crc = footer.data_crc;
277 old_footer.flags = footer.flags;
278 encode(old_footer, bl);
279
280 encode(get_payload(), bl);
281 encode(get_middle(), bl);
282 encode(get_data(), bl);
283
284 // this is almost an exponential backoff, except because we count
285 // bits we tend to sample things we encode later, which should be
286 // more representative.
287 static int i = 0;
288 i++;
289 int bits = 0;
290 for (unsigned t = i; t; bits++)
291 t &= t - 1;
292 if (bits <= 2) {
293 char fn[200];
294 int status;

Callers 4

encode_messageFunction · 0.45
send_toMethod · 0.45
prepare_send_messageMethod · 0.45
prepare_send_messageMethod · 0.45

Calls 6

get_dataFunction · 0.85
encodeFunction · 0.70
lengthMethod · 0.45
takeMethod · 0.45
nameMethod · 0.45
write_fdMethod · 0.45

Tested by

no test coverage detected