Encode returns the encoded form of src. The returned slice may be a sub- slice of dst if dst was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. The dst and src must not overlap. It is valid to pass a nil dst. The blocks will require the same amo
(dst, src []byte)
| 27 | // If you need to encode larger amounts of data, consider using |
| 28 | // the streaming interface which gives all of these features. |
| 29 | func Encode(dst, src []byte) []byte { |
| 30 | if n := MaxEncodedLen(len(src)); n < 0 { |
| 31 | panic(ErrTooLarge) |
| 32 | } else if cap(dst) < n { |
| 33 | dst = make([]byte, n) |
| 34 | } else { |
| 35 | dst = dst[:n] |
| 36 | } |
| 37 | |
| 38 | // The block starts with the varint-encoded length of the decompressed bytes. |
| 39 | d := binary.PutUvarint(dst, uint64(len(src))) |
| 40 | |
| 41 | if len(src) == 0 { |
| 42 | return dst[:d] |
| 43 | } |
| 44 | if len(src) < minNonLiteralBlockSize { |
| 45 | d += emitLiteral(dst[d:], src) |
| 46 | return dst[:d] |
| 47 | } |
| 48 | n := encodeBlock(dst[d:], src) |
| 49 | if n > 0 { |
| 50 | d += n |
| 51 | return dst[:d] |
| 52 | } |
| 53 | // Not compressible |
| 54 | d += emitLiteral(dst[d:], src) |
| 55 | return dst[:d] |
| 56 | } |
| 57 | |
| 58 | var estblockPool [2]sync.Pool |
| 59 |
searching dependent graphs…