(dst, src []byte)
| 30 | } |
| 31 | |
| 32 | func encodeGo(dst, src []byte) []byte { |
| 33 | if n := MaxEncodedLen(len(src)); n < 0 { |
| 34 | panic(ErrTooLarge) |
| 35 | } else if len(dst) < n { |
| 36 | dst = make([]byte, n) |
| 37 | } |
| 38 | |
| 39 | // The block starts with the varint-encoded length of the decompressed bytes. |
| 40 | d := binary.PutUvarint(dst, uint64(len(src))) |
| 41 | |
| 42 | if len(src) == 0 { |
| 43 | return dst[:d] |
| 44 | } |
| 45 | if len(src) < minNonLiteralBlockSize { |
| 46 | d += emitLiteral(dst[d:], src) |
| 47 | return dst[:d] |
| 48 | } |
| 49 | var n int |
| 50 | if len(src) < 64<<10 { |
| 51 | n = encodeBlockGo64K(dst[d:], src) |
| 52 | } else { |
| 53 | n = encodeBlockGo(dst[d:], src) |
| 54 | } |
| 55 | if n > 0 { |
| 56 | d += n |
| 57 | return dst[:d] |
| 58 | } |
| 59 | // Not compressible |
| 60 | d += emitLiteral(dst[d:], src) |
| 61 | return dst[:d] |
| 62 | } |
| 63 | |
| 64 | // encodeBlockGo encodes a non-empty src to a guaranteed-large-enough dst. It |
| 65 | // assumes that the varint-encoded length of the decompressed bytes has already |
searching dependent graphs…