func isNil(v reflect.Value) bool {
	switch v.Kind() {
	case reflect.Map, reflect.Ptr, reflect.Slice:
		return v.IsNil()
	}
	return false
}
All protocol buffer fields are nillable, but be careful.
package proto
import (
	"errors"
	"reflect"
	"runtime"
	"unsafe"
)
type ErrRequiredNotSet struct {
	t reflect.Type
}
func (e *ErrRequiredNotSet) String() string {
	return "proto: required fields not set in " + e.t.String()
}
func (e *ErrRequiredNotSet) Error() string {
	return "proto: required fields not set in " + e.t.String()
}
var (
	ErrRepeatedHasNil = errors.New("proto: repeated field has nil")
	ErrNil = errors.New("proto: Marshal called with nil")
	ErrNotPtr = errors.New("proto: Marshal called with a non-pointer")
)
const maxVarintBytes = 10  
func EncodeVarint(x uint64) []byte {
	var buf [maxVarintBytes]byte
	var n int
	for n = 0; x > 127; n++ {
		buf[n] = 0x80 | uint8(x&0x7F)
		x >>= 7
	}
	buf[n] = uint8(x)
	n++
	return buf[0:n]
}
func (p *Buffer) EncodeVarint(x uint64) error {
	for x >= 1<<7 {
		p.buf = append(p.buf, uint8(x&0x7f|0x80))
		x >>= 7
	}
	p.buf = append(p.buf, uint8(x))
	return nil
}
func (p *Buffer) EncodeFixed64(x uint64) error {
	p.buf = append(p.buf,
		uint8(x),
		uint8(x>>8),
		uint8(x>>16),
		uint8(x>>24),
		uint8(x>>32),
		uint8(x>>40),
		uint8(x>>48),
		uint8(x>>56))
	return nil
}
func (p *Buffer) EncodeFixed32(x uint64) error {
	p.buf = append(p.buf,
		uint8(x),
		uint8(x>>8),
		uint8(x>>16),
		uint8(x>>24))
	return nil
}
func (p *Buffer) EncodeZigzag64(x uint64) error {
	return p.EncodeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (p *Buffer) EncodeZigzag32(x uint64) error {
	return p.EncodeVarint(uint64((uint32(x) << 1) ^ uint32((int32(x) >> 31))))
}
func (p *Buffer) EncodeRawBytes(b []byte) error {
	lb := len(b)
	p.EncodeVarint(uint64(lb))
	p.buf = append(p.buf, b...)
	return nil
}
func (p *Buffer) EncodeStringBytes(s string) error {
	y := *(*[]byte)(unsafe.Pointer(&s))
	p.EncodeRawBytes(y)
	return nil
}
type Marshaler interface {
	Marshal() ([]byte, error)
}
func Marshal(pb interface{}) ([]byte, error) {
	if m, ok := pb.(Marshaler); ok {
		return m.Marshal()
	}
	p := NewBuffer(nil)
	err := p.Marshal(pb)
	if err != nil {
		return nil, err
	}
	return p.buf, err
}
func (p *Buffer) Marshal(pb interface{}) error {
	if m, ok := pb.(Marshaler); ok {
		data, err := m.Marshal()
		if err != nil {
			return err
		}
		p.buf = append(p.buf, data...)
		return nil
	}
	mstat := runtime.MemStats.Mallocs
	t, b, err := getbase(pb)
	if t.Kind() != reflect.Ptr {
		return ErrNotPtr
	}
	if err == nil {
		err = p.enc_struct(t.Elem(), b)
	}
	mstat = runtime.MemStats.Mallocs - mstat
	stats.Emalloc += mstat
	stats.Encode++
	return err
}
func (o *Buffer) enc_bool(p *Properties, base uintptr) error {
	v := *(**uint8)(unsafe.Pointer(base + p.offset))
	if v == nil {
		return ErrNil
	}
	x := *v
	if x != 0 {
		x = 1
	}
	o.buf = append(o.buf, p.tagcode...)
	p.valEnc(o, uint64(x))
	return nil
}
func (o *Buffer) enc_int32(p *Properties, base uintptr) error {
	v := *(**uint32)(unsafe.Pointer(base + p.offset))
	if v == nil {
		return ErrNil
	}
	x := *v
	o.buf = append(o.buf, p.tagcode...)
	p.valEnc(o, uint64(x))
	return nil
}
func (o *Buffer) enc_int64(p *Properties, base uintptr) error {
	v := *(**uint64)(unsafe.Pointer(base + p.offset))
	if v == nil {
		return ErrNil
	}
	x := *v
	o.buf = append(o.buf, p.tagcode...)
	p.valEnc(o, uint64(x))
	return nil
}
func (o *Buffer) enc_string(p *Properties, base uintptr) error {
	v := *(**string)(unsafe.Pointer(base + p.offset))
	if v == nil {
		return ErrNil
	}
	x := *v
	o.buf = append(o.buf, p.tagcode...)
	o.EncodeStringBytes(x)
	return nil
}