EncodeSnappyBetter 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 n
(dst, src []byte)
| 246 | // If you need to encode larger amounts of data, consider using |
| 247 | // the streaming interface which gives all of these features. |
| 248 | func EncodeSnappyBetter(dst, src []byte) []byte { |
| 249 | if n := MaxEncodedLen(len(src)); n < 0 { |
| 250 | panic(ErrTooLarge) |
| 251 | } else if cap(dst) < n { |
| 252 | dst = make([]byte, n) |
| 253 | } else { |
| 254 | dst = dst[:n] |
| 255 | } |
| 256 | |
| 257 | // The block starts with the varint-encoded length of the decompressed bytes. |
| 258 | d := binary.PutUvarint(dst, uint64(len(src))) |
| 259 | |
| 260 | if len(src) == 0 { |
| 261 | return dst[:d] |
| 262 | } |
| 263 | if len(src) < minNonLiteralBlockSize { |
| 264 | d += emitLiteral(dst[d:], src) |
| 265 | return dst[:d] |
| 266 | } |
| 267 | |
| 268 | n := encodeBlockBetterSnappy(dst[d:], src) |
| 269 | if n > 0 { |
| 270 | d += n |
| 271 | return dst[:d] |
| 272 | } |
| 273 | // Not compressible |
| 274 | d += emitLiteral(dst[d:], src) |
| 275 | return dst[:d] |
| 276 | } |
| 277 | |
| 278 | // EncodeSnappyBest returns the encoded form of src. The returned slice may be a sub- |
| 279 | // slice of dst if dst was large enough to hold the entire encoded block. |
searching dependent graphs…