Source File
decode_other.go
Belonging Package
github.com/klauspost/compress/internal/snapref
// Copyright 2016 The Snappy-Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package snapref// decode writes the decoding of src to dst. It assumes that the varint-encoded// length of the decompressed bytes has already been read, and that len(dst)// equals that length.//// It returns 0 on success or a decodeErrCodeXxx error code on failure.func decode(, []byte) int {var , , , intfor < len() {switch [] & 0x03 {case tagLiteral::= uint32([] >> 2)switch {case < 60:++case == 60:+= 2if uint() > uint(len()) { // The uint conversions catch overflow from the previous line.return decodeErrCodeCorrupt}= uint32([-1])case == 61:+= 3if uint() > uint(len()) { // The uint conversions catch overflow from the previous line.return decodeErrCodeCorrupt}= uint32([-2]) | uint32([-1])<<8case == 62:+= 4if uint() > uint(len()) { // The uint conversions catch overflow from the previous line.return decodeErrCodeCorrupt}= uint32([-3]) | uint32([-2])<<8 | uint32([-1])<<16case == 63:+= 5if uint() > uint(len()) { // The uint conversions catch overflow from the previous line.return decodeErrCodeCorrupt}= uint32([-4]) | uint32([-3])<<8 | uint32([-2])<<16 | uint32([-1])<<24}= int() + 1if <= 0 {return decodeErrCodeUnsupportedLiteralLength}if > len()- || > len()- {return decodeErrCodeCorrupt}copy([:], [:+])+=+=continuecase tagCopy1:+= 2if uint() > uint(len()) { // The uint conversions catch overflow from the previous line.return decodeErrCodeCorrupt}= 4 + int([-2])>>2&0x7= int(uint32([-2])&0xe0<<3 | uint32([-1]))case tagCopy2:+= 3if uint() > uint(len()) { // The uint conversions catch overflow from the previous line.return decodeErrCodeCorrupt}= 1 + int([-3])>>2= int(uint32([-2]) | uint32([-1])<<8)case tagCopy4:+= 5if uint() > uint(len()) { // The uint conversions catch overflow from the previous line.return decodeErrCodeCorrupt}= 1 + int([-5])>>2= int(uint32([-4]) | uint32([-3])<<8 | uint32([-2])<<16 | uint32([-1])<<24)}if <= 0 || < || > len()- {return decodeErrCodeCorrupt}// Copy from an earlier sub-slice of dst to a later sub-slice.// If no overlap, use the built-in copy:if >= {copy([:+], [-:])+=continue}// Unlike the built-in copy function, this byte-by-byte copy always runs// forwards, even if the slices overlap. Conceptually, this is://// d += forwardCopy(dst[d:d+length], dst[d-offset:])//// We align the slices into a and b and show the compiler they are the same size.// This allows the loop to run without bounds checks.:= [ : +]:= [-:]= [:len()]for := range {[] = []}+=}if != len() {return decodeErrCodeCorrupt}return 0}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |