Encode will encode the content, with a dictionary if initialized for it.
(blk *blockEnc, src []byte)
| 676 | |
| 677 | // Encode will encode the content, with a dictionary if initialized for it. |
| 678 | func (e *doubleFastEncoderDict) Encode(blk *blockEnc, src []byte) { |
| 679 | const ( |
| 680 | // Input margin is the number of bytes we read (8) |
| 681 | // and the maximum we will read ahead (2) |
| 682 | inputMargin = 8 + 2 |
| 683 | minNonLiteralBlockSize = 16 |
| 684 | ) |
| 685 | |
| 686 | // Protect against e.cur wraparound. |
| 687 | for e.cur >= e.bufferReset-int32(len(e.hist)) { |
| 688 | if len(e.hist) == 0 { |
| 689 | for i := range e.table[:] { |
| 690 | e.table[i] = tableEntry{} |
| 691 | } |
| 692 | for i := range e.longTable[:] { |
| 693 | e.longTable[i] = tableEntry{} |
| 694 | } |
| 695 | e.markAllShardsDirty() |
| 696 | e.cur = e.maxMatchOff |
| 697 | break |
| 698 | } |
| 699 | // Shift down everything in the table that isn't already too far away. |
| 700 | minOff := e.cur + int32(len(e.hist)) - e.maxMatchOff |
| 701 | for i := range e.table[:] { |
| 702 | v := e.table[i].offset |
| 703 | if v < minOff { |
| 704 | v = 0 |
| 705 | } else { |
| 706 | v = v - e.cur + e.maxMatchOff |
| 707 | } |
| 708 | e.table[i].offset = v |
| 709 | } |
| 710 | for i := range e.longTable[:] { |
| 711 | v := e.longTable[i].offset |
| 712 | if v < minOff { |
| 713 | v = 0 |
| 714 | } else { |
| 715 | v = v - e.cur + e.maxMatchOff |
| 716 | } |
| 717 | e.longTable[i].offset = v |
| 718 | } |
| 719 | e.markAllShardsDirty() |
| 720 | e.cur = e.maxMatchOff |
| 721 | break |
| 722 | } |
| 723 | |
| 724 | s := e.addBlock(src) |
| 725 | blk.size = len(src) |
| 726 | if len(src) < minNonLiteralBlockSize { |
| 727 | blk.extraLits = len(src) |
| 728 | blk.literals = blk.literals[:len(src)] |
| 729 | copy(blk.literals, src) |
| 730 | return |
| 731 | } |
| 732 | |
| 733 | // Override src |
| 734 | src = e.hist |
| 735 | sLimit := int32(len(src)) - inputMargin |
nothing calls this directly
no test coverage detected