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

Function send_zstd_token

token.c:732–832  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

730static ZSTD_CCtx *zstd_cctx;
731
732static void send_zstd_token(int f, int32 token, struct map_struct *buf, OFF_T offset, int32 nb)
733{
734 static int comp_init_done, flush_pending;
735 ZSTD_EndDirective flush = ZSTD_e_continue;
736 int32 n, r;
737
738 /* initialization */
739 if (!comp_init_done) {
740 zstd_cctx = ZSTD_createCCtx();
741 if (!zstd_cctx) {
742 rprintf(FERROR, "compression init failed\n");
743 exit_cleanup(RERR_PROTOCOL);
744 }
745
746 obuf = new_array(char, OBUF_SIZE);
747
748 ZSTD_CCtx_setParameter(zstd_cctx, ZSTD_c_compressionLevel, do_compression_level);
749 ZSTD_CCtx_setParameter(zstd_cctx, ZSTD_c_nbWorkers, do_compression_threads);
750
751 zstd_out_buff.dst = obuf + 2;
752
753 comp_init_done = 1;
754 }
755
756 if (last_token == -1) {
757 last_run_end = 0;
758 run_start = token;
759 flush_pending = 0;
760 } else if (last_token == -2) {
761 run_start = token;
762 } else if (nb != 0 || token != last_token + 1 || token >= run_start + 65536) {
763 /* output previous run */
764 r = run_start - last_run_end;
765 n = last_token - run_start;
766
767 if (r >= 0 && r <= 63) {
768 write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r);
769 } else {
770 write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG));
771 write_int(f, run_start);
772 }
773 if (n != 0) {
774 write_byte(f, n);
775 write_byte(f, n >> 8);
776 }
777 last_run_end = last_token;
778 run_start = token;
779 }
780
781 last_token = token;
782
783 if (nb || flush_pending) {
784
785 zstd_in_buff.src = map_ptr(buf, offset, nb);
786 zstd_in_buff.size = nb;
787 zstd_in_buff.pos = 0;
788
789 int finished;

Callers 1

send_tokenFunction · 0.85

Calls 5

write_byteFunction · 0.85
write_intFunction · 0.85
map_ptrFunction · 0.85
write_bufFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected