func (m *Message) UnmarshalMerge(b []byte) error {
	return m.unmarshal(newCodedBuffer(b), false)
}
UnmarshalMerge de-serializes the message that is present in the given bytes
into this message. Unlike Unmarshal, it does not first reset the message,
instead merging the data in the given bytes into the existing data in this
message.
package dynamic
import (
	"fmt"
	"io"
	"math"
	"reflect"
	"sort"
	"github.com/golang/protobuf/proto"
	"github.com/golang/protobuf/protoc-gen-go/descriptor"
	"github.com/jhump/protoreflect/desc"
)
var defaultDeterminism = false
func (m *Message) Marshal() ([]byte, error) {
	var b codedBuffer
	if err := m.marshal(&b, defaultDeterminism); err != nil {
		return nil, err
	}
	return b.buf, nil
}
func (m *Message) MarshalDeterministic() ([]byte, error) {
	var b codedBuffer
	if err := m.marshal(&b, true); err != nil {
		return nil, err
	}
	return b.buf, nil
}
func (m *Message) marshal(b *codedBuffer, deterministic bool) error {
	if err := m.marshalKnownFields(b, deterministic); err != nil {
		return err
	}
	return m.marshalUnknownFields(b)
}
func (m *Message) marshalKnownFields(b *codedBuffer, deterministic bool) error {
	for _, tag := range m.knownFieldTags() {
		itag := int32(tag)
		val := m.values[itag]
		fd := m.FindFieldDescriptor(itag)
		if fd == nil {
			panic(fmt.Sprintf("Couldn't find field for tag %d", itag))
		}
		if err := marshalField(itag, fd, val, b, deterministic); err != nil {
			return err
		}
	}
	return nil
}
func (m *Message) marshalUnknownFields(b *codedBuffer) error {
	for _, tag := range m.unknownFieldTags() {
		itag := int32(tag)
		sl := m.unknownFields[itag]
		for _, u := range sl {
			if err := b.encodeTagAndWireType(itag, u.Encoding); err != nil {
				return err
			}
			switch u.Encoding {
			case proto.WireBytes:
				if err := b.encodeRawBytes(u.Contents); err != nil {
					return err
				}
			case proto.WireStartGroup:
				b.buf = append(b.buf, u.Contents...)
				if err := b.encodeTagAndWireType(itag, proto.WireEndGroup); err != nil {
					return err
				}
			case proto.WireFixed32:
				if err := b.encodeFixed32(u.Value); err != nil {
					return err
				}
			case proto.WireFixed64:
				if err := b.encodeFixed64(u.Value); err != nil {
					return err
				}
			case proto.WireVarint:
				if err := b.encodeVarint(u.Value); err != nil {
					return err
				}
			default:
				return proto.ErrInternalBadWireType
			}
		}
	}
	return nil
}
func marshalField(tag int32, fd *desc.FieldDescriptor, val interface{}, b *codedBuffer, deterministic bool) error {
	if fd.IsMap() {
		mp := val.(map[interface{}]interface{})
		entryType := fd.GetMessageType()
		keyType := entryType.FindFieldByNumber(1)
		valType := entryType.FindFieldByNumber(2)
		var entryBuffer codedBuffer
		if deterministic {
			keys := make([]interface{}, 0, len(mp))
			for k := range mp {
				keys = append(keys, k)
			}
			sort.Sort(sortable(keys))
			for _, k := range keys {
				v := mp[k]
				entryBuffer.reset()
				if err := marshalFieldElement(1, keyType, k, &entryBuffer, deterministic); err != nil {
					return err
				}
				if err := marshalFieldElement(2, valType, v, &entryBuffer, deterministic); err != nil {
					return err
				}
				if err := b.encodeTagAndWireType(tag, proto.WireBytes); err != nil {
					return err
				}
				if err := b.encodeRawBytes(entryBuffer.buf); err != nil {
					return err
				}
			}
		} else {
			for k, v := range mp {
				entryBuffer.reset()
				if err := marshalFieldElement(1, keyType, k, &entryBuffer, deterministic); err != nil {
					return err
				}
				if err := marshalFieldElement(2, valType, v, &entryBuffer, deterministic); err != nil {
					return err
				}
				if err := b.encodeTagAndWireType(tag, proto.WireBytes); err != nil {
					return err
				}
				if err := b.encodeRawBytes(entryBuffer.buf); err != nil {
					return err
				}
			}
		}
		return nil
	} else if fd.IsRepeated() {
		sl := val.([]interface{})
		wt, err := getWireType(fd.GetType())
		if err != nil {
			return err
		}
		if isPacked(fd) && len(sl) > 1 &&
			(wt == proto.WireVarint || wt == proto.WireFixed32 || wt == proto.WireFixed64) {
			var packedBuffer codedBuffer
			for _, v := range sl {
				if err := marshalFieldValue(fd, v, &packedBuffer, deterministic); err != nil {
					return err
				}
			}
			if err := b.encodeTagAndWireType(tag, proto.WireBytes); err != nil {
				return err
			}
			return b.encodeRawBytes(packedBuffer.buf)
		} else {
			for _, v := range sl {
				if err := marshalFieldElement(tag, fd, v, b, deterministic); err != nil {
					return err
				}
			}
			return nil
		}
	} else {
		return marshalFieldElement(tag, fd, val, b, deterministic)
	}
}
func isPacked(fd *desc.FieldDescriptor) bool {
	opts := fd.AsFieldDescriptorProto().GetOptions()
	if opts != nil && opts.Packed != nil {
		return opts.GetPacked()
	}
	return fd.GetFile().IsProto3()
}
type sortable []interface{}
func (s sortable) Len() int {
	return len(s)
}
func (s sortable) Less(i, j int) bool {
	vi := s[i]
	vj := s[j]
	switch reflect.TypeOf(vi).Kind() {
	case reflect.Int32:
		return vi.(int32) < vj.(int32)
	case reflect.Int64:
		return vi.(int64) < vj.(int64)
	case reflect.Uint32:
		return vi.(uint32) < vj.(uint32)
	case reflect.Uint64:
		return vi.(uint64) < vj.(uint64)
	case reflect.String:
		return vi.(string) < vj.(string)
	case reflect.Bool:
		return vi.(bool) && !vj.(bool)
	default:
		panic(fmt.Sprintf("cannot compare keys of type %v", reflect.TypeOf(vi)))
	}
}
func (s sortable) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func marshalFieldElement(tag int32, fd *desc.FieldDescriptor, val interface{}, b *codedBuffer, deterministic bool) error {
	wt, err := getWireType(fd.GetType())
	if err != nil {
		return err
	}
	if err := b.encodeTagAndWireType(tag, wt); err != nil {
		return err
	}
	if err := marshalFieldValue(fd, val, b, deterministic); err != nil {
		return err
	}
	if wt == proto.WireStartGroup {
		return b.encodeTagAndWireType(tag, proto.WireEndGroup)
	}
	return nil
}
func marshalFieldValue(fd *desc.FieldDescriptor, val interface{}, b *codedBuffer, deterministic bool) error {
	switch fd.GetType() {
	case descriptor.FieldDescriptorProto_TYPE_BOOL:
		v := val.(bool)
		if v {
			return b.encodeVarint(1)
		} else {
			return b.encodeVarint(0)
		}
	case descriptor.FieldDescriptorProto_TYPE_ENUM,
		descriptor.FieldDescriptorProto_TYPE_INT32:
		v := val.(int32)
		return b.encodeVarint(uint64(v))
	case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
		v := val.(int32)
		return b.encodeFixed32(uint64(v))
	case descriptor.FieldDescriptorProto_TYPE_SINT32:
		v := val.(int32)
		return b.encodeVarint(encodeZigZag32(v))
	case descriptor.FieldDescriptorProto_TYPE_UINT32:
		v := val.(uint32)
		return b.encodeVarint(uint64(v))
	case descriptor.FieldDescriptorProto_TYPE_FIXED32:
		v := val.(uint32)
		return b.encodeFixed32(uint64(v))
	case descriptor.FieldDescriptorProto_TYPE_INT64:
		v := val.(int64)
		return b.encodeVarint(uint64(v))
	case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
		v := val.(int64)
		return b.encodeFixed64(uint64(v))
	case descriptor.FieldDescriptorProto_TYPE_SINT64:
		v := val.(int64)
		return b.encodeVarint(encodeZigZag64(v))
	case descriptor.FieldDescriptorProto_TYPE_UINT64:
		v := val.(uint64)
		return b.encodeVarint(v)
	case descriptor.FieldDescriptorProto_TYPE_FIXED64:
		v := val.(uint64)
		return b.encodeFixed64(v)
	case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
		v := val.(float64)
		return b.encodeFixed64(math.Float64bits(v))
	case descriptor.FieldDescriptorProto_TYPE_FLOAT:
		v := val.(float32)
		return b.encodeFixed32(uint64(math.Float32bits(v)))
	case descriptor.FieldDescriptorProto_TYPE_BYTES:
		v := val.([]byte)
		return b.encodeRawBytes(v)
	case descriptor.FieldDescriptorProto_TYPE_STRING:
		v := val.(string)
		return b.encodeRawBytes(([]byte)(v))
	case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
		m := val.(proto.Message)
		if bytes, err := proto.Marshal(m); err != nil {
			return err
		} else {
			return b.encodeRawBytes(bytes)
		}
	case descriptor.FieldDescriptorProto_TYPE_GROUP:
		dm, ok := val.(*Message)
		if ok {
			return dm.marshal(b, deterministic)
		} else {
			m := val.(proto.Message)
			return b.encodeMessage(m)
		}
	default:
		return fmt.Errorf("unrecognized field type: %v", fd.GetType())
	}
}
func getWireType(t descriptor.FieldDescriptorProto_Type) (int8, error) {
	switch t {
	case descriptor.FieldDescriptorProto_TYPE_ENUM,
		descriptor.FieldDescriptorProto_TYPE_BOOL,
		descriptor.FieldDescriptorProto_TYPE_INT32,
		descriptor.FieldDescriptorProto_TYPE_SINT32,
		descriptor.FieldDescriptorProto_TYPE_UINT32,
		descriptor.FieldDescriptorProto_TYPE_INT64,
		descriptor.FieldDescriptorProto_TYPE_SINT64,
		descriptor.FieldDescriptorProto_TYPE_UINT64:
		return proto.WireVarint, nil
	case descriptor.FieldDescriptorProto_TYPE_FIXED32,
		descriptor.FieldDescriptorProto_TYPE_SFIXED32,
		descriptor.FieldDescriptorProto_TYPE_FLOAT:
		return proto.WireFixed32, nil
	case descriptor.FieldDescriptorProto_TYPE_FIXED64,
		descriptor.FieldDescriptorProto_TYPE_SFIXED64,
		descriptor.FieldDescriptorProto_TYPE_DOUBLE:
		return proto.WireFixed64, nil
	case descriptor.FieldDescriptorProto_TYPE_BYTES,
		descriptor.FieldDescriptorProto_TYPE_STRING,
		descriptor.FieldDescriptorProto_TYPE_MESSAGE:
		return proto.WireBytes, nil
	case descriptor.FieldDescriptorProto_TYPE_GROUP:
		return proto.WireStartGroup, nil
	default:
		return 0, proto.ErrInternalBadWireType
	}
}
func (m *Message) Unmarshal(b []byte) error {
	m.Reset()
	if err := m.UnmarshalMerge(b); err != nil {
		return err
	}
	return m.Validate()
}