func (u *unmarshalInfo) setTag(tag int, field field, unmarshal unmarshaler, reqMask uint64) {
	i := unmarshalFieldInfo{field: field, unmarshal: unmarshal, reqMask: reqMask}
	n := u.typ.NumField()
	if tag >= 0 && (tag < 16 || tag < 2*n) {  
		for len(u.dense) <= tag {
			u.dense = append(u.dense, unmarshalFieldInfo{})
		}
		u.dense[tag] = i
		return
	}
	if u.sparse == nil {
		u.sparse = map[uint64]unmarshalFieldInfo{}
	}
	u.sparse[uint64(tag)] = i
}
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.
package proto
import (
	"errors"
	"fmt"
	"io"
	"math"
	"reflect"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"
	"unicode/utf8"
)
func (a *InternalMessageInfo) Unmarshal(msg Message, b []byte) error {
	u := atomicLoadUnmarshalInfo(&a.unmarshal)
	if u == nil {
		u = getUnmarshalInfo(reflect.TypeOf(msg).Elem())
		atomicStoreUnmarshalInfo(&a.unmarshal, u)
	}
	err := u.unmarshal(toPointer(&msg), b)
	return err
}
type unmarshalInfo struct {
	typ reflect.Type  
	initialized     int32
	lock            sync.Mutex                     
	dense           []unmarshalFieldInfo           
	sparse          map[uint64]unmarshalFieldInfo  
	reqFields       []string                       
	reqMask         uint64                         
	unrecognized    field                          
	extensions      field                          
	oldExtensions   field                          
	extensionRanges []ExtensionRange               
	isMessageSet    bool                           
	bytesExtensions field  
}
type unmarshaler func(b []byte, f pointer, w int) ([]byte, error)
type unmarshalFieldInfo struct {
	field field
	unmarshal unmarshaler
	reqMask uint64
}
var (
	unmarshalInfoMap  = map[reflect.Type]*unmarshalInfo{}
	unmarshalInfoLock sync.Mutex
)
func getUnmarshalInfo(t reflect.Type) *unmarshalInfo {
	unmarshalInfoLock.Lock()
	defer unmarshalInfoLock.Unlock()
	u := unmarshalInfoMap[t]
	if u == nil {
		u = &unmarshalInfo{typ: t}
		unmarshalInfoMap[t] = u
	}
	return u
}
func (u *unmarshalInfo) unmarshal(m pointer, b []byte) error {
	if atomic.LoadInt32(&u.initialized) == 0 {
		u.computeUnmarshalInfo()
	}
	if u.isMessageSet {
		return UnmarshalMessageSet(b, m.offset(u.extensions).toExtensions())
	}
	var reqMask uint64             
	var rnse *RequiredNotSetError  
	for len(b) > 0 {
		var x uint64
		if b[0] < 128 {
			x = uint64(b[0])
			b = b[1:]
		} else if len(b) >= 2 && b[1] < 128 {
			x = uint64(b[0]&0x7f) + uint64(b[1])<<7
			b = b[2:]
		} else {
			var n int
			x, n = decodeVarint(b)
			if n == 0 {
				return io.ErrUnexpectedEOF
			}
			b = b[n:]
		}
		tag := x >> 3
		wire := int(x) & 7
		var f unmarshalFieldInfo
		if tag < uint64(len(u.dense)) {
			f = u.dense[tag]
		} else {
			f = u.sparse[tag]
		}
		if fn := f.unmarshal; fn != nil {
			var err error
			b, err = fn(b, m.offset(f.field), wire)
			if err == nil {
				reqMask |= f.reqMask
				continue
			}
			if r, ok := err.(*RequiredNotSetError); ok {
				rnse = r
				reqMask |= f.reqMask
				continue
			}
			if err != errInternalBadWireType {
				return err
			}
		}
		if !u.unrecognized.IsValid() {
			var err error
			b, err = skipField(b, wire)
			if err != nil {
				return err
			}
			continue
		}
		z := m.offset(u.unrecognized).toBytes()
		var emap map[int32]Extension
		var e Extension
		for _, r := range u.extensionRanges {
			if uint64(r.Start) <= tag && tag <= uint64(r.End) {
				if u.extensions.IsValid() {
					mp := m.offset(u.extensions).toExtensions()
					emap = mp.extensionsWrite()
					e = emap[int32(tag)]
					z = &e.enc
					break
				}
				if u.oldExtensions.IsValid() {
					p := m.offset(u.oldExtensions).toOldExtensions()
					emap = *p
					if emap == nil {
						emap = map[int32]Extension{}
						*p = emap
					}
					e = emap[int32(tag)]
					z = &e.enc
					break
				}
				if u.bytesExtensions.IsValid() {
					z = m.offset(u.bytesExtensions).toBytes()
					break
				}
				panic("no extensions field available")
			}
		}
		var err error
		b0 := b
		b, err = skipField(b, wire)
		if err != nil {
			return err
		}
		*z = encodeVarint(*z, tag<<3|uint64(wire))
		*z = append(*z, b0[:len(b0)-len(b)]...)
		if emap != nil {
			emap[int32(tag)] = e
		}
	}
	if rnse != nil {
		return rnse
	}
	if reqMask != u.reqMask {
		for _, n := range u.reqFields {
			if reqMask&1 == 0 {
				return &RequiredNotSetError{n}
			}
			reqMask >>= 1
		}
	}
	return nil
}
func (u *unmarshalInfo) computeUnmarshalInfo() {
	u.lock.Lock()
	defer u.lock.Unlock()
	if u.initialized != 0 {
		return
	}
	t := u.typ
	n := t.NumField()
	u.unrecognized = invalidField
	u.extensions = invalidField
	u.oldExtensions = invalidField
	u.bytesExtensions = invalidField
	type oneofField struct {
		ityp  reflect.Type  
		field field         
	}
	var oneofFields []oneofField
	for i := 0; i < n; i++ {
		f := t.Field(i)
		if f.Name == "XXX_unrecognized" {
			if f.Type != reflect.TypeOf(([]byte)(nil)) {
				panic("bad type for XXX_unrecognized field: " + f.Type.Name())
			}
			u.unrecognized = toField(&f)
			continue
		}
		if f.Name == "XXX_InternalExtensions" {
			if f.Type != reflect.TypeOf(XXX_InternalExtensions{}) {
				panic("bad type for XXX_InternalExtensions field: " + f.Type.Name())
			}
			u.extensions = toField(&f)
			if f.Tag.Get("protobuf_messageset") == "1" {
				u.isMessageSet = true
			}
			continue
		}
		if f.Name == "XXX_extensions" {
			if f.Type == reflect.TypeOf((map[int32]Extension)(nil)) {
				u.oldExtensions = toField(&f)
				continue
			} else if f.Type == reflect.TypeOf(([]byte)(nil)) {
				u.bytesExtensions = toField(&f)
				continue
			}
			panic("bad type for XXX_extensions field: " + f.Type.Name())
		}
		if f.Name == "XXX_NoUnkeyedLiteral" || f.Name == "XXX_sizecache" {
			continue
		}
		oneof := f.Tag.Get("protobuf_oneof")
		if oneof != "" {
			oneofFields = append(oneofFields, oneofField{f.Type, toField(&f)})
			continue
		}
		tags := f.Tag.Get("protobuf")
		tagArray := strings.Split(tags, ",")
		if len(tagArray) < 2 {
			panic("protobuf tag not enough fields in " + t.Name() + "." + f.Name + ": " + tags)
		}
		tag, err := strconv.Atoi(tagArray[1])
		if err != nil {
			panic("protobuf tag field not an integer: " + tagArray[1])
		}
		name := ""
		for _, tag := range tagArray[3:] {
			if strings.HasPrefix(tag, "name=") {
				name = tag[5:]
			}
		}
		unmarshal := fieldUnmarshaler(&f)
		var reqMask uint64
		if tagArray[2] == "req" {
			bit := len(u.reqFields)
			u.reqFields = append(u.reqFields, name)
			reqMask = uint64(1) << uint(bit)
		}
		u.setTag(tag, toField(&f), unmarshal, reqMask)
	}
	fn := reflect.Zero(reflect.PtrTo(t)).MethodByName("XXX_OneofFuncs")
	if fn.IsValid() && len(oneofFields) > 0 {
		res := fn.Call(nil)[3]  
		for i := res.Len() - 1; i >= 0; i-- {
			v := res.Index(i)                              
			tptr := reflect.ValueOf(v.Interface()).Type()  
			typ := tptr.Elem()                             
			f := typ.Field(0)  
			baseUnmarshal := fieldUnmarshaler(&f)
			tagstr := strings.Split(f.Tag.Get("protobuf"), ",")[1]
			tag, err := strconv.Atoi(tagstr)
			if err != nil {
				panic("protobuf tag field not an integer: " + tagstr)
			}
			for _, of := range oneofFields {
				if tptr.Implements(of.ityp) {
					unmarshal := makeUnmarshalOneof(typ, of.ityp, baseUnmarshal)
					u.setTag(tag, of.field, unmarshal, 0)
				}
			}
		}
	}
	fn = reflect.Zero(reflect.PtrTo(t)).MethodByName("ExtensionRangeArray")
	if fn.IsValid() {
		if !u.extensions.IsValid() && !u.oldExtensions.IsValid() && !u.bytesExtensions.IsValid() {
			panic("a message with extensions, but no extensions field in " + t.Name())
		}
		u.extensionRanges = fn.Call(nil)[0].Interface().([]ExtensionRange)
	}
	u.setTag(0, zeroField, func(b []byte, f pointer, w int) ([]byte, error) {
		return nil, fmt.Errorf("proto: %s: illegal tag 0 (wire type %d)", t, w)
	}, 0)
	u.reqMask = uint64(1)<<uint(len(u.reqFields)) - 1
	atomic.StoreInt32(&u.initialized, 1)
}