EncodeSnappy 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 output is Snappy compatible and will likely decompress faster. The dst and src must not ove
(dst, src []byte)
| 202 | // If you need to encode larger amounts of data, consider using |
| 203 | // the streaming interface which gives all of these features. |
| 204 | func EncodeSnappy(dst, src []byte) []byte { |
| 205 | if n := MaxEncodedLen(len(src)); n < 0 { |
| 206 | panic(ErrTooLarge) |
| 207 | } else if cap(dst) < n { |
| 208 | dst = make([]byte, n) |
| 209 | } else { |
| 210 | dst = dst[:n] |
| 211 | } |
| 212 | |
| 213 | // The block starts with the varint-encoded length of the decompressed bytes. |
| 214 | d := binary.PutUvarint(dst, uint64(len(src))) |
| 215 | |
| 216 | if len(src) == 0 { |
| 217 | return dst[:d] |
| 218 | } |
| 219 | if len(src) < minNonLiteralBlockSize { |
| 220 | d += emitLiteral(dst[d:], src) |
| 221 | return dst[:d] |
| 222 | } |
| 223 | |
| 224 | n := encodeBlockSnappy(dst[d:], src) |
| 225 | if n > 0 { |
| 226 | d += n |
| 227 | return dst[:d] |
| 228 | } |
| 229 | // Not compressible |
| 230 | d += emitLiteral(dst[d:], src) |
| 231 | return dst[:d] |
| 232 | } |
| 233 | |
| 234 | // EncodeSnappyBetter returns the encoded form of src. The returned slice may be a sub- |
| 235 | // slice of dst if dst was large enough to hold the entire encoded block. |
searching dependent graphs…