snappy: delete the varint package in favor of the standard
encoding/binary package.

R=bradfitz
CC=golang-dev
http://codereview.appspot.com/5308080
diff --git a/Makefile b/Makefile
index dae304b..4d71de0 100644
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,6 @@
 
 # The order matters: earlier packages may not depend on later ones.
 DIRS=\
-	varint/zigzag\
-	varint\
 	snappy\
 
 install clean nuke:
diff --git a/snappy/decode.go b/snappy/decode.go
index da21040..d169bea 100644
--- a/snappy/decode.go
+++ b/snappy/decode.go
@@ -5,9 +5,8 @@
 package snappy
 
 import (
+	"encoding/binary"
 	"errors"
-
-	"snappy-go.googlecode.com/hg/varint"
 )
 
 // ErrCorrupt reports that the input is invalid.
@@ -22,7 +21,7 @@
 // decodedLen returns the length of the decoded block and the number of bytes
 // that the length header occupied.
 func decodedLen(src []byte) (blockLen, headerLen int, err error) {
-	v, n := varint.Decode(src)
+	v, n := binary.Uvarint(src)
 	if n == 0 {
 		return 0, 0, ErrCorrupt
 	}
diff --git a/snappy/encode.go b/snappy/encode.go
index 78ffc0b..a403ab9 100644
--- a/snappy/encode.go
+++ b/snappy/encode.go
@@ -5,7 +5,7 @@
 package snappy
 
 import (
-	"snappy-go.googlecode.com/hg/varint"
+	"encoding/binary"
 )
 
 // We limit how far copy back-references can go, the same as the C++ code.
@@ -92,7 +92,7 @@
 	}
 
 	// The block starts with the varint-encoded length of the decompressed bytes.
-	d := varint.Encode(dst, uint64(len(src)))
+	d := binary.PutUvarint(dst, uint64(len(src)))
 
 	// Return early if src is short.
 	if len(src) <= 4 {
diff --git a/varint/Makefile b/varint/Makefile
deleted file mode 100644
index 01a9ca1..0000000
--- a/varint/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright 2011 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.
-
-include $(GOROOT)/src/Make.inc
-
-TARG=snappy-go.googlecode.com/hg/varint
-GOFILES=\
-	varint.go\
-
-include $(GOROOT)/src/Make.pkg
-
diff --git a/varint/varint.go b/varint/varint.go
deleted file mode 100644
index 8add448..0000000
--- a/varint/varint.go
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2011 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 varint implements a variable-width encoding of unsigned integers.
-//
-// It is the same format used by protocol buffers. The format is described at
-// http://code.google.com/apis/protocolbuffers/docs/encoding.html
-package varint
-
-// MaxLen is the maximum encoded length of a uint64.
-const MaxLen = 10
-
-// Len returns the number of bytes used to represent v.
-func Len(v uint64) (n int) {
-	for v > 0x7f {
-		v >>= 7
-		n++
-	}
-	return n + 1
-}
-
-// Decode returns the value encoded at the start of src, as well as the number
-// of bytes it occupies. It returns n == 0 if given invalid input.
-func Decode(src []byte) (v uint64, n int) {
-	for shift := uint(0); ; shift += 7 {
-		if n >= len(src) {
-			return 0, 0
-		}
-		b := src[n]
-		n++
-		v |= uint64(b&0x7f) << shift
-		if b&0x80 == 0 {
-			break
-		}
-	}
-	return v, n
-}
-
-// Encode writes the value to the start of dst, and returns the number of bytes
-// written. It panics if len(dst) < Len(v).
-func Encode(dst []byte, v uint64) (n int) {
-	for v > 0x7f {
-		dst[n] = 0x80 | uint8(v&0x7f)
-		v >>= 7
-		n++
-	}
-	dst[n] = uint8(v)
-	return n + 1
-}
diff --git a/varint/varint_test.go b/varint/varint_test.go
deleted file mode 100644
index 2587c68..0000000
--- a/varint/varint_test.go
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2011 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 varint
-
-import (
-	"testing"
-)
-
-var testCases = []struct {
-	valid bool
-	s     string
-	v     uint64
-}{
-	// Valid encodings.
-	{true, "\x00", 0},
-	{true, "\x01", 1},
-	{true, "\x7f", 127},
-	{true, "\x80\x01", 128},
-	{true, "\xff\x02", 383},
-	{true, "\x9e\xa7\x05", 86942}, // 86942 = 0x1e + 0x27<<7 + 0x05<<14
-	{true, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01", 0xffffffffffffffff},
-	{
-		true,
-		"\x8a\x89\x88\x87\x86\x85\x84\x83\x82\x01",
-		10 + 9<<7 + 8<<14 + 7<<21 + 6<<28 + 5<<35 + 4<<42 + 3<<49 + 2<<56 + 1<<63,
-	},
-	// Invalid encodings.
-	{false, "", 0},
-	{false, "\x80", 0},
-	{false, "\xff", 0},
-	{false, "\x9e\xa7", 0},
-}
-
-func TestDecode(t *testing.T) {
-	for _, tc := range testCases {
-		v, n := Decode([]byte(tc.s))
-		if v != tc.v {
-			t.Errorf("decode %q: want value %d got %d", tc.s, tc.v, v)
-			continue
-		}
-		m := 0
-		if tc.valid {
-			m = len(tc.s)
-		}
-		if n != m {
-			t.Errorf("decode %q: want length %d got %d", tc.s, m, n)
-			continue
-		}
-	}
-}
-
-func TestEncode(t *testing.T) {
-	for _, tc := range testCases {
-		if !tc.valid {
-			continue
-		}
-		var b [MaxLen]byte
-		n := Encode(b[:], tc.v)
-		if s := string(b[:n]); s != tc.s {
-			t.Errorf("encode %d: want bytes %q got %q", tc.v, tc.s, s)
-			continue
-		}
-		if n != Len(tc.v) {
-			t.Errorf("encode %d: Encode length %d != Len length %d", tc.v, n, Len(tc.v))
-			continue
-		}
-	}
-}
diff --git a/varint/zigzag/Makefile b/varint/zigzag/Makefile
deleted file mode 100644
index 730eef3..0000000
--- a/varint/zigzag/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright 2011 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.
-
-include $(GOROOT)/src/Make.inc
-
-TARG=snappy-go.googlecode.com/hg/varint/zigzag
-GOFILES=\
-	zigzag.go\
-
-include $(GOROOT)/src/Make.pkg
-
diff --git a/varint/zigzag/zigzag.go b/varint/zigzag/zigzag.go
deleted file mode 100644
index 20a84dc..0000000
--- a/varint/zigzag/zigzag.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2011 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 zigzag implements the zigzag mapping between signed and unsigned
-// integers:
-//	+0 <-> 0
-//	-1 <-> 1
-//	+1 <-> 2
-//	-2 <-> 3
-//	+2 <-> 4
-//	etcetera
-//
-// It is the same format used by protocol buffers. The format is described at
-// http://code.google.com/apis/protocolbuffers/docs/encoding.html
-package zigzag
-
-// Itou64 maps a signed integer to an unsigned integer.
-// If i >= 0, the result is 2*i.
-// If i < 0, the result is -2*i - 1.
-// The formulae above are in terms of ideal integers, with no overflow.
-func Itou64(i int64) uint64 {
-	return uint64(i<<1 ^ i>>63)
-}
-
-// Utoi64 maps an unsigned integer to a signed integer.
-// If u%2 == 0, the result is u/2.
-// If u%2 == 1, the result is -(u+1)/2.
-// The formulae above are in terms of ideal integers, with no overflow.
-func Utoi64(u uint64) int64 {
-	return int64(u>>1) ^ -int64(u&1)
-}
diff --git a/varint/zigzag/zigzag_test.go b/varint/zigzag/zigzag_test.go
deleted file mode 100644
index 397fe4a..0000000
--- a/varint/zigzag/zigzag_test.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2011 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 zigzag
-
-import (
-	"testing"
-)
-
-var testCases = []struct {
-	u uint64
-	i int64
-}{
-	{0, +0},
-	{1, -1},
-	{2, +1},
-	{3, -2},
-	{4, +2},
-	{5, -3},
-	{6, +3},
-	{199, -100},
-	{200, +100},
-	{1<<32 - 2, +1<<31 - 1},
-	{1<<32 - 1, -1<<31 - 0},
-	{1<<32 + 0, +1<<31 + 0},
-	{1<<32 + 1, -1<<31 - 1},
-	{1<<32 + 2, +1<<31 + 1},
-	{1<<64 - 2, +1<<63 - 1},
-	{1<<64 - 1, -1<<63 + 0},
-}
-
-func TestZigzag(t *testing.T) {
-	for _, tc := range testCases {
-		if i := Utoi64(tc.u); i != tc.i {
-			t.Errorf("uint64 %d to int64: want %d got %d", tc.u, tc.i, i)
-		}
-		if u := Itou64(tc.i); u != tc.u {
-			t.Errorf("int64 %d to uint64: want %d got %d", tc.i, tc.u, u)
-		}
-	}
-}