internal/encoding/wire: initial commit

This adds package wire, which provides low-level functionality for
marshaling and unmarshaling the protobuf wire format.

High-level API:
	type Number int32
	    const MinValidNumber Number = 1 ...
	type Type int8
	    const VarintType Type = 0 ...
	func ParseError(n int) error

	func ConsumeField(b []byte) (Number, Type, int)
	func ConsumeFieldValue(num Number, typ Type, b []byte) (n int)
	func ConsumeTag(b []byte) (Number, Type, int)
	func ConsumeVarint(b []byte) (v uint64, n int)
	func ConsumeFixed32(b []byte) (v uint32, n int)
	func ConsumeFixed64(b []byte) (v uint64, n int)
	func ConsumeBytes(b []byte) (v []byte, n int)
	func ConsumeGroup(num Number, b []byte) (v []byte, n int)
	func AppendTag(b []byte, num Number, typ Type) []byte
	func AppendVarint(b []byte, v uint64) []byte
	func AppendFixed32(b []byte, v uint32) []byte
	func AppendFixed64(b []byte, v uint64) []byte
	func AppendBytes(b []byte, v []byte) []byte
	func AppendGroup(b []byte, num Number, v []byte) []byte
	func SizeTag(num Number) int
	func SizeVarint(v uint64) int
	func SizeFixed32() int
	func SizeFixed64() int
	func SizeBytes(n int) int
	func SizeGroup(num Number, n int) int

	func DecodeBool(x uint64) bool
	func DecodeTag(x uint64) (Number, Type)
	func DecodeZigZag(x uint64) int64
	func EncodeBool(x bool) uint64
	func EncodeTag(num Number, typ Type) uint64
	func EncodeZigZag(x int64) uint64

Change-Id: I052d8975414aeb182f6e9595c4736e716f1b7e9d
Reviewed-on: https://go-review.googlesource.com/127337
Reviewed-by: Chris Manghane <cmang@golang.org>
Run-TryBot: Chris Manghane <cmang@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2 files changed
tree: 670770357b71a7efede911b62a4266113f1a9881
  1. internal/
  2. CONTRIBUTING.md
  3. go.mod
  4. README.md
README.md

Next Generation Go Protocol Buffers

WARNING: This repository is in active development. There are no guarantees about API stability. Breaking changes will occur until a stable release is made and announced.

This repository is for the development of the next major Go implementation of protocol buffers. This library makes breaking API changes relative to the existing Go protobuf library. Of particular note, this API aims to make protobuf reflection a first-class feature of the API and implements the protobuf ecosystem in terms of reflection.

Design Documents

List of relevant design documents:

Contributing

We appreciate community contributions. See CONTRIBUTING.md.

Reporting Issues

Issues regarding the new API can be filed at github.com/golang/protobuf. Please use a APIv2: prefix in the title to make it clear that the issue is regarding the new API work.