// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2016 The Go Authors.  All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package proto

import (
	
	
	
	
	
	
	
	
	
	
)

// Unmarshal is the entry point from the generated .pb.go files.
// This function is not intended to be used by non-generated code.
// This function is not subject to any compatibility guarantee.
// msg contains a pointer to a protocol buffer struct.
// b is the data to be unmarshaled into the protocol buffer.
// a is a pointer to a place to store cached unmarshal information.
func ( *InternalMessageInfo) ( Message,  []byte) error {
	// Load the unmarshal information for this message type.
	// The atomic load ensures memory consistency.
	 := atomicLoadUnmarshalInfo(&.unmarshal)
	if  == nil {
		// Slow path: find unmarshal info for msg, update a with it.
		 = getUnmarshalInfo(reflect.TypeOf().Elem())
		atomicStoreUnmarshalInfo(&.unmarshal, )
	}
	// Then do the unmarshaling.
	 := .unmarshal(toPointer(&), )
	return 
}

type unmarshalInfo struct {
	typ reflect.Type // type of the protobuf struct

	// 0 = only typ field is initialized
	// 1 = completely initialized
	initialized     int32
	lock            sync.Mutex                    // prevents double initialization
	dense           []unmarshalFieldInfo          // fields indexed by tag #
	sparse          map[uint64]unmarshalFieldInfo // fields indexed by tag #
	reqFields       []string                      // names of required fields
	reqMask         uint64                        // 1<<len(reqFields)-1
	unrecognized    field                         // offset of []byte to put unrecognized data (or invalidField if we should throw it away)
	extensions      field                         // offset of extensions field (of type proto.XXX_InternalExtensions), or invalidField if it does not exist
	oldExtensions   field                         // offset of old-form extensions field (of type map[int]Extension)
	extensionRanges []ExtensionRange              // if non-nil, implies extensions field is valid
	isMessageSet    bool                          // if true, implies extensions field is valid

	bytesExtensions field // offset of XXX_extensions with type []byte
}

// An unmarshaler takes a stream of bytes and a pointer to a field of a message.
// It decodes the field, stores it at f, and returns the unused bytes.
// w is the wire encoding.
// b is the data after the tag and wire encoding have been read.
type unmarshaler func(b []byte, f pointer, w int) ([]byte, error)

type unmarshalFieldInfo struct {
	// location of the field in the proto message structure.
	field field

	// function to unmarshal the data for the field.
	unmarshal unmarshaler

	// if a required field, contains a single set bit at this field's index in the required field list.
	reqMask uint64

	name string // name of the field, for error reporting
}

var (
	unmarshalInfoMap  = map[reflect.Type]*unmarshalInfo{}
	unmarshalInfoLock sync.Mutex
)

// getUnmarshalInfo returns the data structure which can be
// subsequently used to unmarshal a message of the given type.
// t is the type of the message (note: not pointer to message).
func getUnmarshalInfo( reflect.Type) *unmarshalInfo {
	// It would be correct to return a new unmarshalInfo
	// unconditionally. We would end up allocating one
	// per occurrence of that type as a message or submessage.
	// We use a cache here just to reduce memory usage.
	unmarshalInfoLock.Lock()
	defer unmarshalInfoLock.Unlock()
	 := unmarshalInfoMap[]
	if  == nil {
		 = &unmarshalInfo{typ: }
		// Note: we just set the type here. The rest of the fields
		// will be initialized on first use.
		unmarshalInfoMap[] = 
	}
	return 
}

// unmarshal does the main work of unmarshaling a message.
// u provides type information used to unmarshal the message.
// m is a pointer to a protocol buffer message.
// b is a byte stream to unmarshal into m.
// This is top routine used when recursively unmarshaling submessages.
func ( *unmarshalInfo) ( pointer,  []byte) error {
	if atomic.LoadInt32(&.initialized) == 0 {
		.computeUnmarshalInfo()
	}
	if .isMessageSet {
		return unmarshalMessageSet(, .offset(.extensions).toExtensions())
	}
	var  uint64 // bitmask of required fields we've seen.
	var  error
	for len() > 0 {
		// Read tag and wire type.
		// Special case 1 and 2 byte varints.
		var  uint64
		if [0] < 128 {
			 = uint64([0])
			 = [1:]
		} else if len() >= 2 && [1] < 128 {
			 = uint64([0]&0x7f) + uint64([1])<<7
			 = [2:]
		} else {
			var  int
			,  = decodeVarint()
			if  == 0 {
				return io.ErrUnexpectedEOF
			}
			 = [:]
		}
		 :=  >> 3
		 := int() & 7

		// Dispatch on the tag to one of the unmarshal* functions below.
		var  unmarshalFieldInfo
		if  < uint64(len(.dense)) {
			 = .dense[]
		} else {
			 = .sparse[]
		}
		if  := .unmarshal;  != nil {
			var  error
			,  = (, .offset(.field), )
			if  == nil {
				 |= .reqMask
				continue
			}
			if ,  := .(*RequiredNotSetError);  {
				// Remember this error, but keep parsing. We need to produce
				// a full parse even if a required field is missing.
				if  == nil {
					 = 
				}
				 |= .reqMask
				continue
			}
			if  != errInternalBadWireType {
				if  == errInvalidUTF8 {
					if  == nil {
						 := revProtoTypes[reflect.PtrTo(.typ)] + "." + .name
						 = &invalidUTF8Error{}
					}
					continue
				}
				return 
			}
			// Fragments with bad wire type are treated as unknown fields.
		}

		// Unknown tag.
		if !.unrecognized.IsValid() {
			// Don't keep unrecognized data; just skip it.
			var  error
			,  = skipField(, )
			if  != nil {
				return 
			}
			continue
		}
		// Keep unrecognized data around.
		// maybe in extensions, maybe in the unrecognized field.
		 := .offset(.unrecognized).toBytes()
		var  map[int32]Extension
		var  Extension
		for ,  := range .extensionRanges {
			if uint64(.Start) <=  &&  <= uint64(.End) {
				if .extensions.IsValid() {
					 := .offset(.extensions).toExtensions()
					 = .extensionsWrite()
					 = [int32()]
					 = &.enc
					break
				}
				if .oldExtensions.IsValid() {
					 := .offset(.oldExtensions).toOldExtensions()
					 = *
					if  == nil {
						 = map[int32]Extension{}
						* = 
					}
					 = [int32()]
					 = &.enc
					break
				}
				if .bytesExtensions.IsValid() {
					 = .offset(.bytesExtensions).toBytes()
					break
				}
				panic("no extensions field available")
			}
		}
		// Use wire type to skip data.
		var  error
		 := 
		,  = skipField(, )
		if  != nil {
			return 
		}
		* = encodeVarint(*, <<3|uint64())
		* = append(*, [:len()-len()]...)

		if  != nil {
			[int32()] = 
		}
	}
	if  != .reqMask &&  == nil {
		// A required field of this message is missing.
		for ,  := range .reqFields {
			if &1 == 0 {
				 = &RequiredNotSetError{}
			}
			 >>= 1
		}
	}
	return 
}

// computeUnmarshalInfo fills in u with information for use
// in unmarshaling protocol buffers of type u.typ.
func ( *unmarshalInfo) () {
	.lock.Lock()
	defer .lock.Unlock()
	if .initialized != 0 {
		return
	}
	 := .typ
	 := .NumField()

	// Set up the "not found" value for the unrecognized byte buffer.
	// This is the default for proto3.
	.unrecognized = invalidField
	.extensions = invalidField
	.oldExtensions = invalidField
	.bytesExtensions = invalidField

	// List of the generated type and offset for each oneof field.
	type  struct {
		  reflect.Type // interface type of oneof field
		 field        // offset in containing message
	}
	var  []

	for  := 0;  < ; ++ {
		 := .Field()
		if .Name == "XXX_unrecognized" {
			// The byte slice used to hold unrecognized input is special.
			if .Type != reflect.TypeOf(([]byte)(nil)) {
				panic("bad type for XXX_unrecognized field: " + .Type.Name())
			}
			.unrecognized = toField(&)
			continue
		}
		if .Name == "XXX_InternalExtensions" {
			// Ditto here.
			if .Type != reflect.TypeOf(XXX_InternalExtensions{}) {
				panic("bad type for XXX_InternalExtensions field: " + .Type.Name())
			}
			.extensions = toField(&)
			if .Tag.Get("protobuf_messageset") == "1" {
				.isMessageSet = true
			}
			continue
		}
		if .Name == "XXX_extensions" {
			// An older form of the extensions field.
			if .Type == reflect.TypeOf((map[int32]Extension)(nil)) {
				.oldExtensions = toField(&)
				continue
			} else if .Type == reflect.TypeOf(([]byte)(nil)) {
				.bytesExtensions = toField(&)
				continue
			}
			panic("bad type for XXX_extensions field: " + .Type.Name())
		}
		if .Name == "XXX_NoUnkeyedLiteral" || .Name == "XXX_sizecache" {
			continue
		}

		 := .Tag.Get("protobuf_oneof")
		if  != "" {
			 = append(, {.Type, toField(&)})
			// The rest of oneof processing happens below.
			continue
		}

		 := .Tag.Get("protobuf")
		 := strings.Split(, ",")
		if len() < 2 {
			panic("protobuf tag not enough fields in " + .Name() + "." + .Name + ": " + )
		}
		,  := strconv.Atoi([1])
		if  != nil {
			panic("protobuf tag field not an integer: " + [1])
		}

		 := ""
		for ,  := range [3:] {
			if strings.HasPrefix(, "name=") {
				 = [5:]
			}
		}

		// Extract unmarshaling function from the field (its type and tags).
		 := fieldUnmarshaler(&)

		// Required field?
		var  uint64
		if [2] == "req" {
			 := len(.reqFields)
			.reqFields = append(.reqFields, )
			 = uint64(1) << uint()
			// TODO: if we have more than 64 required fields, we end up
			// not verifying that all required fields are present.
			// Fix this, perhaps using a count of required fields?
		}

		// Store the info in the correct slot in the message.
		.setTag(, toField(&), , , )
	}

	// Find any types associated with oneof fields.
	// gogo: len(oneofFields) > 0 is needed for embedded oneof messages, without a marshaler and unmarshaler
	if len() > 0 {
		var  []interface{}
		switch m := reflect.Zero(reflect.PtrTo()).Interface().(type) {
		case oneofFuncsIface:
			_, _, _,  = .XXX_OneofFuncs()
		case oneofWrappersIface:
			 = .XXX_OneofWrappers()
		}
		for ,  := range  {
			 := reflect.TypeOf() // *Msg_X
			 := .Elem()        // Msg_X

			 := .Field(0) // oneof implementers have one field
			 := fieldUnmarshaler(&)
			 := strings.Split(.Tag.Get("protobuf"), ",")
			,  := strconv.Atoi([1])
			if  != nil {
				panic("protobuf tag field not an integer: " + [1])
			}
			var  string
			for ,  := range  {
				if strings.HasPrefix(, "name=") {
					 = strings.TrimPrefix(, "name=")
					break
				}
			}

			// Find the oneof field that this struct implements.
			// Might take O(n^2) to process all of the oneofs, but who cares.
			for ,  := range  {
				if .Implements(.) {
					// We have found the corresponding interface for this struct.
					// That lets us know where this struct should be stored
					// when we encounter it during unmarshaling.
					 := makeUnmarshalOneof(, ., )
					.setTag(, ., , 0, )
				}
			}

		}
	}

	// Get extension ranges, if any.
	 := reflect.Zero(reflect.PtrTo()).MethodByName("ExtensionRangeArray")
	if .IsValid() {
		if !.extensions.IsValid() && !.oldExtensions.IsValid() && !.bytesExtensions.IsValid() {
			panic("a message with extensions, but no extensions field in " + .Name())
		}
		.extensionRanges = .Call(nil)[0].Interface().([]ExtensionRange)
	}

	// Explicitly disallow tag 0. This will ensure we flag an error
	// when decoding a buffer of all zeros. Without this code, we
	// would decode and skip an all-zero buffer of even length.
	// [0 0] is [tag=0/wiretype=varint varint-encoded-0].
	.setTag(0, zeroField, func( []byte,  pointer,  int) ([]byte, error) {
		return nil, fmt.Errorf("proto: %s: illegal tag 0 (wire type %d)", , )
	}, 0, "")

	// Set mask for required field check.
	.reqMask = uint64(1)<<uint(len(.reqFields)) - 1

	atomic.StoreInt32(&.initialized, 1)
}

// setTag stores the unmarshal information for the given tag.
// tag = tag # for field
// field/unmarshal = unmarshal info for that field.
// reqMask = if required, bitmask for field position in required field list. 0 otherwise.
// name = short name of the field.
func ( *unmarshalInfo) ( int,  field,  unmarshaler,  uint64,  string) {
	 := unmarshalFieldInfo{field: , unmarshal: , reqMask: , name: }
	 := .typ.NumField()
	if  >= 0 && ( < 16 ||  < 2*) { // TODO: what are the right numbers here?
		for len(.dense) <=  {
			.dense = append(.dense, unmarshalFieldInfo{})
		}
		.dense[] = 
		return
	}
	if .sparse == nil {
		.sparse = map[uint64]unmarshalFieldInfo{}
	}
	.sparse[uint64()] = 
}

// fieldUnmarshaler returns an unmarshaler for the given field.
func fieldUnmarshaler( *reflect.StructField) unmarshaler {
	if .Type.Kind() == reflect.Map {
		return makeUnmarshalMap()
	}
	return typeUnmarshaler(.Type, .Tag.Get("protobuf"))
}

// typeUnmarshaler returns an unmarshaler for the given field type / field tag pair.
func typeUnmarshaler( reflect.Type,  string) unmarshaler {
	 := strings.Split(, ",")
	 := [0]
	 := "unknown"
	 := false
	 := false
	 := false
	 := false
	 := false
	 := true
	for ,  := range [3:] {
		if strings.HasPrefix(, "name=") {
			 = [5:]
		}
		if  == "proto3" {
			 = true
		}
		if strings.HasPrefix(, "customtype=") {
			 = true
		}
		if  == "stdtime" {
			 = true
		}
		if  == "stdduration" {
			 = true
		}
		if  == "wktptr" {
			 = true
		}
	}
	 =  && 

	// Figure out packaging (pointer, slice, or both)
	 := false
	 := false
	if .Kind() == reflect.Slice && .Elem().Kind() != reflect.Uint8 {
		 = true
		 = .Elem()
	}
	if .Kind() == reflect.Ptr {
		 = true
		 = .Elem()
	}

	if  {
		if reflect.PtrTo().Implements(customType) {
			if  {
				return makeUnmarshalCustomSlice(getUnmarshalInfo(), )
			}
			if  {
				return makeUnmarshalCustomPtr(getUnmarshalInfo(), )
			}
			return makeUnmarshalCustom(getUnmarshalInfo(), )
		} else {
			panic(fmt.Sprintf("custom type: type: %v, does not implement the proto.custom interface", ))
		}
	}

	if  {
		if  {
			if  {
				return makeUnmarshalTimePtrSlice(getUnmarshalInfo(), )
			}
			return makeUnmarshalTimePtr(getUnmarshalInfo(), )
		}
		if  {
			return makeUnmarshalTimeSlice(getUnmarshalInfo(), )
		}
		return makeUnmarshalTime(getUnmarshalInfo(), )
	}

	if  {
		if  {
			if  {
				return makeUnmarshalDurationPtrSlice(getUnmarshalInfo(), )
			}
			return makeUnmarshalDurationPtr(getUnmarshalInfo(), )
		}
		if  {
			return makeUnmarshalDurationSlice(getUnmarshalInfo(), )
		}
		return makeUnmarshalDuration(getUnmarshalInfo(), )
	}

	if  {
		switch .Kind() {
		case reflect.Float64:
			if  {
				if  {
					return makeStdDoubleValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdDoubleValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdDoubleValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdDoubleValueUnmarshaler(getUnmarshalInfo(), )
		case reflect.Float32:
			if  {
				if  {
					return makeStdFloatValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdFloatValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdFloatValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdFloatValueUnmarshaler(getUnmarshalInfo(), )
		case reflect.Int64:
			if  {
				if  {
					return makeStdInt64ValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdInt64ValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdInt64ValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdInt64ValueUnmarshaler(getUnmarshalInfo(), )
		case reflect.Uint64:
			if  {
				if  {
					return makeStdUInt64ValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdUInt64ValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdUInt64ValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdUInt64ValueUnmarshaler(getUnmarshalInfo(), )
		case reflect.Int32:
			if  {
				if  {
					return makeStdInt32ValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdInt32ValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdInt32ValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdInt32ValueUnmarshaler(getUnmarshalInfo(), )
		case reflect.Uint32:
			if  {
				if  {
					return makeStdUInt32ValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdUInt32ValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdUInt32ValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdUInt32ValueUnmarshaler(getUnmarshalInfo(), )
		case reflect.Bool:
			if  {
				if  {
					return makeStdBoolValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdBoolValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdBoolValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdBoolValueUnmarshaler(getUnmarshalInfo(), )
		case reflect.String:
			if  {
				if  {
					return makeStdStringValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdStringValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdStringValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdStringValueUnmarshaler(getUnmarshalInfo(), )
		case uint8SliceType:
			if  {
				if  {
					return makeStdBytesValuePtrSliceUnmarshaler(getUnmarshalInfo(), )
				}
				return makeStdBytesValuePtrUnmarshaler(getUnmarshalInfo(), )
			}
			if  {
				return makeStdBytesValueSliceUnmarshaler(getUnmarshalInfo(), )
			}
			return makeStdBytesValueUnmarshaler(getUnmarshalInfo(), )
		default:
			panic(fmt.Sprintf("unknown wktpointer type %#v", ))
		}
	}

	// We'll never have both pointer and slice for basic types.
	if  &&  && .Kind() != reflect.Struct {
		panic("both pointer and slice for basic type in " + .Name())
	}

	switch .Kind() {
	case reflect.Bool:
		if  {
			return unmarshalBoolPtr
		}
		if  {
			return unmarshalBoolSlice
		}
		return unmarshalBoolValue
	case reflect.Int32:
		switch  {
		case "fixed32":
			if  {
				return unmarshalFixedS32Ptr
			}
			if  {
				return unmarshalFixedS32Slice
			}
			return unmarshalFixedS32Value
		case "varint":
			// this could be int32 or enum
			if  {
				return unmarshalInt32Ptr
			}
			if  {
				return unmarshalInt32Slice
			}
			return unmarshalInt32Value
		case "zigzag32":
			if  {
				return unmarshalSint32Ptr
			}
			if  {
				return unmarshalSint32Slice
			}
			return unmarshalSint32Value
		}
	case reflect.Int64:
		switch  {
		case "fixed64":
			if  {
				return unmarshalFixedS64Ptr
			}
			if  {
				return unmarshalFixedS64Slice
			}
			return unmarshalFixedS64Value
		case "varint":
			if  {
				return unmarshalInt64Ptr
			}
			if  {
				return unmarshalInt64Slice
			}
			return unmarshalInt64Value
		case "zigzag64":
			if  {
				return unmarshalSint64Ptr
			}
			if  {
				return unmarshalSint64Slice
			}
			return unmarshalSint64Value
		}
	case reflect.Uint32:
		switch  {
		case "fixed32":
			if  {
				return unmarshalFixed32Ptr
			}
			if  {
				return unmarshalFixed32Slice
			}
			return unmarshalFixed32Value
		case "varint":
			if  {
				return unmarshalUint32Ptr
			}
			if  {
				return unmarshalUint32Slice
			}
			return unmarshalUint32Value
		}
	case reflect.Uint64:
		switch  {
		case "fixed64":
			if  {
				return unmarshalFixed64Ptr
			}
			if  {
				return unmarshalFixed64Slice
			}
			return unmarshalFixed64Value
		case "varint":
			if  {
				return unmarshalUint64Ptr
			}
			if  {
				return unmarshalUint64Slice
			}
			return unmarshalUint64Value
		}
	case reflect.Float32:
		if  {
			return unmarshalFloat32Ptr
		}
		if  {
			return unmarshalFloat32Slice
		}
		return unmarshalFloat32Value
	case reflect.Float64:
		if  {
			return unmarshalFloat64Ptr
		}
		if  {
			return unmarshalFloat64Slice
		}
		return unmarshalFloat64Value
	case reflect.Map:
		panic("map type in typeUnmarshaler in " + .Name())
	case reflect.Slice:
		if  {
			panic("bad pointer in slice case in " + .Name())
		}
		if  {
			return unmarshalBytesSlice
		}
		return unmarshalBytesValue
	case reflect.String:
		if  {
			if  {
				return unmarshalUTF8StringPtr
			}
			if  {
				return unmarshalUTF8StringSlice
			}
			return unmarshalUTF8StringValue
		}
		if  {
			return unmarshalStringPtr
		}
		if  {
			return unmarshalStringSlice
		}
		return unmarshalStringValue
	case reflect.Struct:
		// message or group field
		if ! {
			switch  {
			case "bytes":
				if  {
					return makeUnmarshalMessageSlice(getUnmarshalInfo(), )
				}
				return makeUnmarshalMessage(getUnmarshalInfo(), )
			}
		}
		switch  {
		case "bytes":
			if  {
				return makeUnmarshalMessageSlicePtr(getUnmarshalInfo(), )
			}
			return makeUnmarshalMessagePtr(getUnmarshalInfo(), )
		case "group":
			if  {
				return makeUnmarshalGroupSlicePtr(getUnmarshalInfo(), )
			}
			return makeUnmarshalGroupPtr(getUnmarshalInfo(), )
		}
	}
	panic(fmt.Sprintf("unmarshaler not found type:%s encoding:%s", , ))
}

// Below are all the unmarshalers for individual fields of various types.

func unmarshalInt64Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int64()
	*.toInt64() = 
	return , nil
}

func unmarshalInt64Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int64()
	*.toInt64Ptr() = &
	return , nil
}

func unmarshalInt64Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			,  = decodeVarint()
			if  == 0 {
				return nil, io.ErrUnexpectedEOF
			}
			 = [:]
			 := int64()
			 := .toInt64Slice()
			* = append(*, )
		}
		return , nil
	}
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int64()
	 := .toInt64Slice()
	* = append(*, )
	return , nil
}

func unmarshalSint64Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int64(>>1) ^ int64()<<63>>63
	*.toInt64() = 
	return , nil
}

func unmarshalSint64Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int64(>>1) ^ int64()<<63>>63
	*.toInt64Ptr() = &
	return , nil
}

func unmarshalSint64Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			,  = decodeVarint()
			if  == 0 {
				return nil, io.ErrUnexpectedEOF
			}
			 = [:]
			 := int64(>>1) ^ int64()<<63>>63
			 := .toInt64Slice()
			* = append(*, )
		}
		return , nil
	}
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int64(>>1) ^ int64()<<63>>63
	 := .toInt64Slice()
	* = append(*, )
	return , nil
}

func unmarshalUint64Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := uint64()
	*.toUint64() = 
	return , nil
}

func unmarshalUint64Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := uint64()
	*.toUint64Ptr() = &
	return , nil
}

func unmarshalUint64Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			,  = decodeVarint()
			if  == 0 {
				return nil, io.ErrUnexpectedEOF
			}
			 = [:]
			 := uint64()
			 := .toUint64Slice()
			* = append(*, )
		}
		return , nil
	}
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := uint64()
	 := .toUint64Slice()
	* = append(*, )
	return , nil
}

func unmarshalInt32Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int32()
	*.toInt32() = 
	return , nil
}

func unmarshalInt32Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int32()
	.setInt32Ptr()
	return , nil
}

func unmarshalInt32Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			,  = decodeVarint()
			if  == 0 {
				return nil, io.ErrUnexpectedEOF
			}
			 = [:]
			 := int32()
			.appendInt32Slice()
		}
		return , nil
	}
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int32()
	.appendInt32Slice()
	return , nil
}

func unmarshalSint32Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int32(>>1) ^ int32()<<31>>31
	*.toInt32() = 
	return , nil
}

func unmarshalSint32Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int32(>>1) ^ int32()<<31>>31
	.setInt32Ptr()
	return , nil
}

func unmarshalSint32Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			,  = decodeVarint()
			if  == 0 {
				return nil, io.ErrUnexpectedEOF
			}
			 = [:]
			 := int32(>>1) ^ int32()<<31>>31
			.appendInt32Slice()
		}
		return , nil
	}
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := int32(>>1) ^ int32()<<31>>31
	.appendInt32Slice()
	return , nil
}

func unmarshalUint32Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := uint32()
	*.toUint32() = 
	return , nil
}

func unmarshalUint32Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := uint32()
	*.toUint32Ptr() = &
	return , nil
}

func unmarshalUint32Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			,  = decodeVarint()
			if  == 0 {
				return nil, io.ErrUnexpectedEOF
			}
			 = [:]
			 := uint32()
			 := .toUint32Slice()
			* = append(*, )
		}
		return , nil
	}
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	 := uint32()
	 := .toUint32Slice()
	* = append(*, )
	return , nil
}

func unmarshalFixed64Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56
	*.toUint64() = 
	return [8:], nil
}

func unmarshalFixed64Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56
	*.toUint64Ptr() = &
	return [8:], nil
}

func unmarshalFixed64Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			if len() < 8 {
				return nil, io.ErrUnexpectedEOF
			}
			 := uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56
			 := .toUint64Slice()
			* = append(*, )
			 = [8:]
		}
		return , nil
	}
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56
	 := .toUint64Slice()
	* = append(*, )
	return [8:], nil
}

func unmarshalFixedS64Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := int64([0]) | int64([1])<<8 | int64([2])<<16 | int64([3])<<24 | int64([4])<<32 | int64([5])<<40 | int64([6])<<48 | int64([7])<<56
	*.toInt64() = 
	return [8:], nil
}

func unmarshalFixedS64Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := int64([0]) | int64([1])<<8 | int64([2])<<16 | int64([3])<<24 | int64([4])<<32 | int64([5])<<40 | int64([6])<<48 | int64([7])<<56
	*.toInt64Ptr() = &
	return [8:], nil
}

func unmarshalFixedS64Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			if len() < 8 {
				return nil, io.ErrUnexpectedEOF
			}
			 := int64([0]) | int64([1])<<8 | int64([2])<<16 | int64([3])<<24 | int64([4])<<32 | int64([5])<<40 | int64([6])<<48 | int64([7])<<56
			 := .toInt64Slice()
			* = append(*, )
			 = [8:]
		}
		return , nil
	}
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := int64([0]) | int64([1])<<8 | int64([2])<<16 | int64([3])<<24 | int64([4])<<32 | int64([5])<<40 | int64([6])<<48 | int64([7])<<56
	 := .toInt64Slice()
	* = append(*, )
	return [8:], nil
}

func unmarshalFixed32Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24
	*.toUint32() = 
	return [4:], nil
}

func unmarshalFixed32Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24
	*.toUint32Ptr() = &
	return [4:], nil
}

func unmarshalFixed32Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			if len() < 4 {
				return nil, io.ErrUnexpectedEOF
			}
			 := uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24
			 := .toUint32Slice()
			* = append(*, )
			 = [4:]
		}
		return , nil
	}
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24
	 := .toUint32Slice()
	* = append(*, )
	return [4:], nil
}

func unmarshalFixedS32Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := int32([0]) | int32([1])<<8 | int32([2])<<16 | int32([3])<<24
	*.toInt32() = 
	return [4:], nil
}

func unmarshalFixedS32Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := int32([0]) | int32([1])<<8 | int32([2])<<16 | int32([3])<<24
	.setInt32Ptr()
	return [4:], nil
}

func unmarshalFixedS32Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			if len() < 4 {
				return nil, io.ErrUnexpectedEOF
			}
			 := int32([0]) | int32([1])<<8 | int32([2])<<16 | int32([3])<<24
			.appendInt32Slice()
			 = [4:]
		}
		return , nil
	}
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := int32([0]) | int32([1])<<8 | int32([2])<<16 | int32([3])<<24
	.appendInt32Slice()
	return [4:], nil
}

func unmarshalBoolValue( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	// Note: any length varint is allowed, even though any sane
	// encoder will use one byte.
	// See https://github.com/golang/protobuf/issues/76
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	// TODO: check if x>1? Tests seem to indicate no.
	 :=  != 0
	*.toBool() = 
	return [:], nil
}

func unmarshalBoolPtr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 :=  != 0
	*.toBoolPtr() = &
	return [:], nil
}

func unmarshalBoolSlice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			,  = decodeVarint()
			if  == 0 {
				return nil, io.ErrUnexpectedEOF
			}
			 :=  != 0
			 := .toBoolSlice()
			* = append(*, )
			 = [:]
		}
		return , nil
	}
	if  != WireVarint {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 :=  != 0
	 := .toBoolSlice()
	* = append(*, )
	return [:], nil
}

func unmarshalFloat64Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := math.Float64frombits(uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56)
	*.toFloat64() = 
	return [8:], nil
}

func unmarshalFloat64Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := math.Float64frombits(uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56)
	*.toFloat64Ptr() = &
	return [8:], nil
}

func unmarshalFloat64Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			if len() < 8 {
				return nil, io.ErrUnexpectedEOF
			}
			 := math.Float64frombits(uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56)
			 := .toFloat64Slice()
			* = append(*, )
			 = [8:]
		}
		return , nil
	}
	if  != WireFixed64 {
		return , errInternalBadWireType
	}
	if len() < 8 {
		return nil, io.ErrUnexpectedEOF
	}
	 := math.Float64frombits(uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56)
	 := .toFloat64Slice()
	* = append(*, )
	return [8:], nil
}

func unmarshalFloat32Value( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := math.Float32frombits(uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24)
	*.toFloat32() = 
	return [4:], nil
}

func unmarshalFloat32Ptr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := math.Float32frombits(uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24)
	*.toFloat32Ptr() = &
	return [4:], nil
}

func unmarshalFloat32Slice( []byte,  pointer,  int) ([]byte, error) {
	if  == WireBytes { // packed
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:]
		 = [:]
		for len() > 0 {
			if len() < 4 {
				return nil, io.ErrUnexpectedEOF
			}
			 := math.Float32frombits(uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24)
			 := .toFloat32Slice()
			* = append(*, )
			 = [4:]
		}
		return , nil
	}
	if  != WireFixed32 {
		return , errInternalBadWireType
	}
	if len() < 4 {
		return nil, io.ErrUnexpectedEOF
	}
	 := math.Float32frombits(uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24)
	 := .toFloat32Slice()
	* = append(*, )
	return [4:], nil
}

func unmarshalStringValue( []byte,  pointer,  int) ([]byte, error) {
	if  != WireBytes {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	if  > uint64(len()) {
		return nil, io.ErrUnexpectedEOF
	}
	 := string([:])
	*.toString() = 
	return [:], nil
}

func unmarshalStringPtr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireBytes {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	if  > uint64(len()) {
		return nil, io.ErrUnexpectedEOF
	}
	 := string([:])
	*.toStringPtr() = &
	return [:], nil
}

func unmarshalStringSlice( []byte,  pointer,  int) ([]byte, error) {
	if  != WireBytes {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	if  > uint64(len()) {
		return nil, io.ErrUnexpectedEOF
	}
	 := string([:])
	 := .toStringSlice()
	* = append(*, )
	return [:], nil
}

func unmarshalUTF8StringValue( []byte,  pointer,  int) ([]byte, error) {
	if  != WireBytes {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	if  > uint64(len()) {
		return nil, io.ErrUnexpectedEOF
	}
	 := string([:])
	*.toString() = 
	if !utf8.ValidString() {
		return [:], errInvalidUTF8
	}
	return [:], nil
}

func unmarshalUTF8StringPtr( []byte,  pointer,  int) ([]byte, error) {
	if  != WireBytes {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	if  > uint64(len()) {
		return nil, io.ErrUnexpectedEOF
	}
	 := string([:])
	*.toStringPtr() = &
	if !utf8.ValidString() {
		return [:], errInvalidUTF8
	}
	return [:], nil
}

func unmarshalUTF8StringSlice( []byte,  pointer,  int) ([]byte, error) {
	if  != WireBytes {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	if  > uint64(len()) {
		return nil, io.ErrUnexpectedEOF
	}
	 := string([:])
	 := .toStringSlice()
	* = append(*, )
	if !utf8.ValidString() {
		return [:], errInvalidUTF8
	}
	return [:], nil
}

var emptyBuf [0]byte

func unmarshalBytesValue( []byte,  pointer,  int) ([]byte, error) {
	if  != WireBytes {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	if  > uint64(len()) {
		return nil, io.ErrUnexpectedEOF
	}
	// The use of append here is a trick which avoids the zeroing
	// that would be required if we used a make/copy pair.
	// We append to emptyBuf instead of nil because we want
	// a non-nil result even when the length is 0.
	 := append(emptyBuf[:], [:]...)
	*.toBytes() = 
	return [:], nil
}

func unmarshalBytesSlice( []byte,  pointer,  int) ([]byte, error) {
	if  != WireBytes {
		return , errInternalBadWireType
	}
	,  := decodeVarint()
	if  == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	 = [:]
	if  > uint64(len()) {
		return nil, io.ErrUnexpectedEOF
	}
	 := append(emptyBuf[:], [:]...)
	 := .toBytesSlice()
	* = append(*, )
	return [:], nil
}

func makeUnmarshalMessagePtr( *unmarshalInfo,  string) unmarshaler {
	return func( []byte,  pointer,  int) ([]byte, error) {
		if  != WireBytes {
			return , errInternalBadWireType
		}
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		// First read the message field to see if something is there.
		// The semantics of multiple submessages are weird.  Instead of
		// the last one winning (as it is for all other fields), multiple
		// submessages are merged.
		 := .getPointer()
		if .isNil() {
			 = valToPointer(reflect.New(.typ))
			.setPointer()
		}
		 := .unmarshal(, [:])
		if  != nil {
			if ,  := .(*RequiredNotSetError);  {
				.field =  + "." + .field
			} else {
				return nil, 
			}
		}
		return [:], 
	}
}

func makeUnmarshalMessageSlicePtr( *unmarshalInfo,  string) unmarshaler {
	return func( []byte,  pointer,  int) ([]byte, error) {
		if  != WireBytes {
			return , errInternalBadWireType
		}
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := valToPointer(reflect.New(.typ))
		 := .unmarshal(, [:])
		if  != nil {
			if ,  := .(*RequiredNotSetError);  {
				.field =  + "." + .field
			} else {
				return nil, 
			}
		}
		.appendPointer()
		return [:], 
	}
}

func makeUnmarshalGroupPtr( *unmarshalInfo,  string) unmarshaler {
	return func( []byte,  pointer,  int) ([]byte, error) {
		if  != WireStartGroup {
			return , errInternalBadWireType
		}
		,  := findEndGroup()
		if  < 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 := .getPointer()
		if .isNil() {
			 = valToPointer(reflect.New(.typ))
			.setPointer()
		}
		 := .unmarshal(, [:])
		if  != nil {
			if ,  := .(*RequiredNotSetError);  {
				.field =  + "." + .field
			} else {
				return nil, 
			}
		}
		return [:], 
	}
}

func makeUnmarshalGroupSlicePtr( *unmarshalInfo,  string) unmarshaler {
	return func( []byte,  pointer,  int) ([]byte, error) {
		if  != WireStartGroup {
			return , errInternalBadWireType
		}
		,  := findEndGroup()
		if  < 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 := valToPointer(reflect.New(.typ))
		 := .unmarshal(, [:])
		if  != nil {
			if ,  := .(*RequiredNotSetError);  {
				.field =  + "." + .field
			} else {
				return nil, 
			}
		}
		.appendPointer()
		return [:], 
	}
}

func makeUnmarshalMap( *reflect.StructField) unmarshaler {
	 := .Type
	 := .Key()
	 := .Elem()
	 := strings.Split(.Tag.Get("protobuf"), ",")
	 := strings.Split(.Tag.Get("protobuf_val"), ",")
	for ,  := range  {
		if strings.HasPrefix(, "customtype=") {
			 = append(, )
		}
		if  == "stdtime" {
			 = append(, )
		}
		if  == "stdduration" {
			 = append(, )
		}
		if  == "wktptr" {
			 = append(, )
		}
	}
	 := typeUnmarshaler(, .Tag.Get("protobuf_key"))
	 := typeUnmarshaler(, strings.Join(, ","))
	return func( []byte,  pointer,  int) ([]byte, error) {
		// The map entry is a submessage. Figure out how big it is.
		if  != WireBytes {
			return nil, fmt.Errorf("proto: bad wiretype for map field: got %d want %d", , WireBytes)
		}
		,  := decodeVarint()
		if  == 0 {
			return nil, io.ErrUnexpectedEOF
		}
		 = [:]
		if  > uint64(len()) {
			return nil, io.ErrUnexpectedEOF
		}
		 := [:] // unused data to return
		 = [:]  // data for map entry

		// Note: we could use #keys * #values ~= 200 functions
		// to do map decoding without reflection. Probably not worth it.
		// Maps will be somewhat slow. Oh well.

		// Read key and value from data.
		var  nonFatal
		 := reflect.New()
		 := reflect.New()
		for len() > 0 {
			,  := decodeVarint()
			if  == 0 {
				return nil, io.ErrUnexpectedEOF
			}
			 := int() & 7
			 = [:]

			var  error
			switch  >> 3 {
			case 1:
				,  = (, valToPointer(), )
			case 2:
				,  = (, valToPointer(), )
			default:
				 = errInternalBadWireType // skip unknown tag
			}

			if .Merge() {
				continue
			}
			if  != errInternalBadWireType {
				return nil, 
			}

			// Skip past unknown fields.
			,  = skipField(, )
			if  != nil {
				return nil, 
			}
		}

		// Get map, allocate if needed.
		 := .asPointerTo().Elem() // an addressable map[K]T
		if .IsNil() {
			.Set(reflect.MakeMap())
		}

		// Insert into map.
		.SetMapIndex(.Elem(), .Elem())

		return , .E
	}
}

// makeUnmarshalOneof makes an unmarshaler for oneof fields.
// for:
// message Msg {
//   oneof F {
//     int64 X = 1;
//     float64 Y = 2;
//   }
// }
// typ is the type of the concrete entry for a oneof case (e.g. Msg_X).
// ityp is the interface type of the oneof field (e.g. isMsg_F).
// unmarshal is the unmarshaler for the base type of the oneof case (e.g. int64).
// Note that this function will be called once for each case in the oneof.
func makeUnmarshalOneof(,  reflect.Type,  unmarshaler) unmarshaler {
	 := .Field(0)
	 := toField(&)
	return func( []byte,  pointer,  int) ([]byte, error) {
		// Allocate holder for value.
		 := reflect.New()

		// Unmarshal data into holder.
		// We unmarshal into the first field of the holder object.
		var  error
		var  nonFatal
		,  = (, valToPointer().offset(), )
		if !.Merge() {
			return nil, 
		}

		// Write pointer to holder into target field.
		.asPointerTo().Elem().Set()

		return , .E
	}
}

// Error used by decode internally.
var errInternalBadWireType = errors.New("proto: internal error: bad wiretype")

// skipField skips past a field of type wire and returns the remaining bytes.
func skipField( []byte,  int) ([]byte, error) {
	switch  {
	case WireVarint:
		,  := decodeVarint()
		if  == 0 {
			return , io.ErrUnexpectedEOF
		}
		 = [:]
	case WireFixed32:
		if len() < 4 {
			return , io.ErrUnexpectedEOF
		}
		 = [4:]
	case WireFixed64:
		if len() < 8 {
			return , io.ErrUnexpectedEOF
		}
		 = [8:]
	case WireBytes:
		,  := decodeVarint()
		if  == 0 || uint64(len()-) <  {
			return , io.ErrUnexpectedEOF
		}
		 = [uint64()+:]
	case WireStartGroup:
		,  := findEndGroup()
		if  == -1 {
			return , io.ErrUnexpectedEOF
		}
		 = [:]
	default:
		return , fmt.Errorf("proto: can't skip unknown wire type %d", )
	}
	return , nil
}

// findEndGroup finds the index of the next EndGroup tag.
// Groups may be nested, so the "next" EndGroup tag is the first
// unpaired EndGroup.
// findEndGroup returns the indexes of the start and end of the EndGroup tag.
// Returns (-1,-1) if it can't find one.
func findEndGroup( []byte) (int, int) {
	 := 1
	 := 0
	for {
		,  := decodeVarint([:])
		if  == 0 {
			return -1, -1
		}
		 := 
		 += 
		switch  & 7 {
		case WireVarint:
			,  := decodeVarint([:])
			if  == 0 {
				return -1, -1
			}
			 += 
		case WireFixed32:
			if len()-4 <  {
				return -1, -1
			}
			 += 4
		case WireFixed64:
			if len()-8 <  {
				return -1, -1
			}
			 += 8
		case WireBytes:
			,  := decodeVarint([:])
			if  == 0 {
				return -1, -1
			}
			 += 
			if uint64(len()-) <  {
				return -1, -1
			}
			 += int()
		case WireStartGroup:
			++
		case WireEndGroup:
			--
			if  == 0 {
				return , 
			}
		default:
			return -1, -1
		}
	}
}

// encodeVarint appends a varint-encoded integer to b and returns the result.
func encodeVarint( []byte,  uint64) []byte {
	for  >= 1<<7 {
		 = append(, byte(&0x7f|0x80))
		 >>= 7
	}
	return append(, byte())
}

// decodeVarint reads a varint-encoded integer from b.
// Returns the decoded integer and the number of bytes read.
// If there is an error, it returns 0,0.
func decodeVarint( []byte) (uint64, int) {
	var ,  uint64
	if len() == 0 {
		goto 
	}
	 = uint64([0])
	if  < 0x80 {
		return , 1
	}
	 -= 0x80

	if len() <= 1 {
		goto 
	}
	 = uint64([1])
	 +=  << 7
	if  < 0x80 {
		return , 2
	}
	 -= 0x80 << 7

	if len() <= 2 {
		goto 
	}
	 = uint64([2])
	 +=  << 14
	if  < 0x80 {
		return , 3
	}
	 -= 0x80 << 14

	if len() <= 3 {
		goto 
	}
	 = uint64([3])
	 +=  << 21
	if  < 0x80 {
		return , 4
	}
	 -= 0x80 << 21

	if len() <= 4 {
		goto 
	}
	 = uint64([4])
	 +=  << 28
	if  < 0x80 {
		return , 5
	}
	 -= 0x80 << 28

	if len() <= 5 {
		goto 
	}
	 = uint64([5])
	 +=  << 35
	if  < 0x80 {
		return , 6
	}
	 -= 0x80 << 35

	if len() <= 6 {
		goto 
	}
	 = uint64([6])
	 +=  << 42
	if  < 0x80 {
		return , 7
	}
	 -= 0x80 << 42

	if len() <= 7 {
		goto 
	}
	 = uint64([7])
	 +=  << 49
	if  < 0x80 {
		return , 8
	}
	 -= 0x80 << 49

	if len() <= 8 {
		goto 
	}
	 = uint64([8])
	 +=  << 56
	if  < 0x80 {
		return , 9
	}
	 -= 0x80 << 56

	if len() <= 9 {
		goto 
	}
	 = uint64([9])
	 +=  << 63
	if  < 2 {
		return , 10
	}

:
	return 0, 0
}