MCPcopy Index your code
hub / github.com/RsyncProject/rsync / write_ndx

Function write_ndx

io.c:2318–2362  ·  view source on GitHub ↗

Send a file-list index using a byte-reduction method. */

Source from the content-addressed store, hash-verified

2316
2317/* Send a file-list index using a byte-reduction method. */
2318void write_ndx(int f, int32 ndx)
2319{
2320 static int32 prev_positive = -1, prev_negative = 1;
2321 int32 diff, cnt = 0;
2322 char b[6];
2323
2324 if (protocol_version < 30 || read_batch) {
2325 write_int(f, ndx);
2326 return;
2327 }
2328
2329 /* Send NDX_DONE as a single-byte 0 with no side effects. Send
2330 * negative nums as a positive after sending a leading 0xFF. */
2331 if (ndx >= 0) {
2332 diff = ndx - prev_positive;
2333 prev_positive = ndx;
2334 } else if (ndx == NDX_DONE) {
2335 *b = 0;
2336 write_buf(f, b, 1);
2337 return;
2338 } else {
2339 b[cnt++] = (char)0xFF;
2340 ndx = -ndx;
2341 diff = ndx - prev_negative;
2342 prev_negative = ndx;
2343 }
2344
2345 /* A diff of 1 - 253 is sent as a one-byte diff; a diff of 254 - 32767
2346 * or 0 is sent as a 0xFE + a two-byte diff; otherwise we send 0xFE
2347 * & all 4 bytes of the (non-negative) num with the high-bit set. */
2348 if (diff < 0xFE && diff > 0)
2349 b[cnt++] = (char)diff;
2350 else if (diff < 0 || diff > 0x7FFF) {
2351 b[cnt++] = (char)0xFE;
2352 b[cnt++] = (char)((ndx >> 24) | 0x80);
2353 b[cnt++] = (char)ndx;
2354 b[cnt++] = (char)(ndx >> 8);
2355 b[cnt++] = (char)(ndx >> 16);
2356 } else {
2357 b[cnt++] = (char)0xFE;
2358 b[cnt++] = (char)(diff >> 8);
2359 b[cnt++] = (char)diff;
2360 }
2361 write_buf(f, b, cnt);
2362}
2363
2364/* Receive a file-list index using a byte-reduction method. */
2365int32 read_ndx(int f)

Callers 11

write_ndx_and_attrsFunction · 0.85
send_filesFunction · 0.85
send_extra_file_listFunction · 0.85
send_file_listFunction · 0.85
itemizeFunction · 0.85
recv_generatorFunction · 0.85
check_for_finished_filesFunction · 0.85
generate_filesFunction · 0.85
write_del_statsFunction · 0.85
read_final_goodbyeFunction · 0.85
do_recvFunction · 0.85

Calls 2

write_intFunction · 0.85
write_bufFunction · 0.85

Tested by

no test coverage detected