// UnmarshalMessage unmarshals the proto message from flags.
//
// The descriptor set should be obtained from the `cproto` compiled packages'
// FileDescriptorSet() method.
347286
func UnmarshalMessage(flags []string, resolver Resolver, msg proto.Message) error {
	// TODO(iannucci): avoid round-trip through parser and jsonpb and populate the
	// message directly. This would involve writing some additional reflection
	// code that may depend on implementation details of proto's generated Go
	// code, which is why this wasn't done initially.
	name := proto.MessageName(msg)
	dproto, ok := resolver.Resolve(name).(*descriptor.DescriptorProto)
	if !ok {
		return fmt.Errorf("could not resolve message %q", name)
	}

	jdata, err := UnmarshalUntyped(flags, dproto, resolver)
	if err != nil {
		return err
	}

	jtext, err := json.Marshal(jdata)
	if err != nil {
		return err
	}

	return jsonpb.Unmarshal(bytes.NewReader(jtext), msg)
}
1011790
func (m *Message) UnmarshalBinary(b []byte) error {
	if len(b) < nlmsgHeaderLen {
		return errShortMessage
	}
	if len(b) != nlmsgAlign(len(b)) {
		return errUnalignedMessage
	}

	// Don't allow misleading length
	m.Header.Length = nlenc.Uint32(b[0:4])
	if int(m.Header.Length) != len(b) {
		return errShortMessage
	}

	m.Header.Type = HeaderType(nlenc.Uint16(b[4:6]))
	m.Header.Flags = HeaderFlags(nlenc.Uint16(b[6:8]))
	m.Header.Sequence = nlenc.Uint32(b[8:12])
	m.Header.PID = nlenc.Uint32(b[12:16])
	m.Data = b[16:]

	return nil
}
571740
func (sp *SerializerProto) Unmarshal(data []byte, protoData proto.Message) error {
	return proto.Unmarshal(data, protoData)
}
664812
func DeserializeMessage(data []byte) (*Message, error) {
	serializable := new(SerializedMessage)
	if err := proto.Unmarshal(data, serializable); err != nil {
		return nil, err
	}

	msg := &Message{
		streamID:     MessageStreamID(serializable.GetStreamID()),
		prevStreamID: MessageStreamID(serializable.GetPrevStreamID()),
		origStreamID: MessageStreamID(serializable.GetOrigStreamID()),
		timestamp:    serializable.GetTimestamp(),
	}

	if msgData := serializable.GetData(); msgData != nil {
		msg.data.payload = msgData.GetData()
		msg.data.metadata = msgData.GetMetadata()
	}

	if msgOrigData := serializable.GetOriginal(); msgOrigData != nil {
		msg.orig = new(MessageData)
		msg.orig.payload = msgOrigData.GetData()
		msg.orig.metadata = msgOrigData.GetMetadata()
	}

	return msg, nil
}
598216
func (e MessagePathEnumNestedPathEnum) UnmarshalJSON(b []byte) error {
	return unmarshalJSONEnum(b, pbpathenum.MessagePathEnum_NestedPathEnum_value)
}
113035
func (l *ContainerChildList) UnmarshalJSON(text []byte) error {
	containers := struct {
		Children []*ContainerChild `json:"children,omitempty"`
	}{}
	if err := json.Unmarshal(text, &containers); err != nil {
		return err
	}
	*l = containers.Children
	return nil
}
941070
func (v *ListMemberUploaded) UnmarshalJSON(data []byte) error {
	r := jlexer.Lexer{Data: data}
	easyjson692db02bDecodeGithubComMailgunMailgunGoEvents9(&r, v)
	return r.Error()
}
886935
func (v *MessageHeaders) UnmarshalJSON(data []byte) error {
	r := jlexer.Lexer{Data: data}
	easyjsonCce3d1beDecodeGithubComMailgunMailgunGoEvents1(&r, v)
	return r.Error()
}
659747
func (k *KeyringMemberRevocationType) UnmarshalText(b []byte) error {
	switch string(b) {
	case "org_removal":
		*k = OrgRemovalRevocationType
	case "key_revocation":
		*k = KeyRevocationRevocationType
	case "machine_destroy":
		*k = MachineDestroyRevocationType
	case "machine_token_destroy":
		*k = MachineTokenDestroyRevocationType
	default:
		return errBadRevocationType
	}

	return nil
}
1039866
func (v *Attachment) UnmarshalJSON(data []byte) error {
	r := jlexer.Lexer{Data: data}
	easyjsonCce3d1beDecodeGithubComMailgunMailgunGoEvents10(&r, v)
	return r.Error()
}
646203
func UnmarshalMessageSet(buf []byte, m map[int32]Extension) error {
	ms := new(MessageSet)
	if err := Unmarshal(buf, ms); err != nil {
		return err
	}
	for _, item := range ms.Item {
		// restore wire type and field number varint, plus length varint.
		b := EncodeVarint(uint64(*item.TypeId)<<3 | WireBytes)
		b = append(b, EncodeVarint(uint64(len(item.Message)))...)
		b = append(b, item.Message...)

		m[*item.TypeId] = Extension{enc: b}
	}
	return nil
}
835621
func (request *RPCRequest) UnmarshalJSON(data []byte) error {
	unsafeReq := &struct {
		JSONRPC string          `json:"jsonrpc"`
		ID      interface{}     `json:"id"`
		Method  string          `json:"method"`
		Params  json.RawMessage `json:"params"` // must be map[string]interface{} or []interface{}
	}{}
	err := json.Unmarshal(data, &unsafeReq)
	if err != nil {
		return err
	}
	request.JSONRPC = unsafeReq.JSONRPC
	request.Method = unsafeReq.Method
	request.Params = unsafeReq.Params
	if unsafeReq.ID == nil {
		return nil
	}
	id, err := idFromInterface(unsafeReq.ID)
	if err != nil {
		return err
	}
	request.ID = id
	return nil
}
717729
func unmarshalMessageSet(buf []byte, exts interface{}) error {
	var m map[int32]Extension
	switch exts := exts.(type) {
	case *XXX_InternalExtensions:
		m = exts.extensionsWrite()
	case map[int32]Extension:
		m = exts
	default:
		return errors.New("proto: not an extension map")
	}

	ms := new(messageSet)
	if err := Unmarshal(buf, ms); err != nil {
		return err
	}
	for _, item := range ms.Item {
		id := *item.TypeId
		msg := item.Message

		// Restore wire type and field number varint, plus length varint.
		// Be careful to preserve duplicate items.
		b := EncodeVarint(uint64(id)<<3 | WireBytes)
		if ext, ok := m[id]; ok {
			// Existing data; rip off the tag and length varint
			// so we join the new data correctly.
			// We can assume that ext.enc is set because we are unmarshaling.
			o := ext.enc[len(b):]   // skip wire type and field number
			_, n := DecodeVarint(o) // calculate length of length varint
			o = o[n:]               // skip length varint
			msg = append(o, msg...) // join old data and new data
		}
		b = append(b, EncodeVarint(uint64(len(msg)))...)
		b = append(b, msg...)

		m[id] = Extension{enc: b}
	}
	return nil
}
366609
func (spaceQuota *SpaceQuota) UnmarshalJSON(data []byte) error {
	var ccSpaceQuota struct {
		Metadata internal.Metadata `json:"metadata"`
		Entity   struct {
			Name string `json:"name"`
		} `json:"entity"`
	}
	err := cloudcontroller.DecodeJSON(data, &ccSpaceQuota)
	if err != nil {
		return err
	}

	spaceQuota.GUID = ccSpaceQuota.Metadata.GUID
	spaceQuota.Name = ccSpaceQuota.Entity.Name
	return nil
}
516188
func (pt *PrimitiveTypes) UnmarshalJSON(data []byte) error {
	if data[0] != '[' {
		var t PrimitiveType
		if err := json.Unmarshal(data, &t); err != nil {
			return err
		}

		*pt = PrimitiveTypes{t}
		return nil
	}

	var list []PrimitiveType
	if err := json.Unmarshal(data, &list); err != nil {
		return err
	}

	*pt = PrimitiveTypes(list)
	return nil
}
986938
func (p *Processor) Unmarshal(data []byte) (interface{}, error) {
	var m map[string]json.RawMessage
	err := json.Unmarshal(data, &m)
	if err != nil {
		return nil, err
	}
	if len(m) != 1 {
		return nil, errors.New("invalid json data")
	}

	for msgID, data := range m {
		i, ok := p.msgInfo[msgID]
		if !ok {
			return nil, fmt.Errorf("message %v not registered", msgID)
		}

		// msg
		if i.msgRawHandler != nil {
			return MsgRaw{msgID, data}, nil
		} else {
			msg := reflect.New(i.msgType.Elem()).Interface()
			return msg, json.Unmarshal(data, msg)
		}
	}

	panic("bug")
}
783512
func (p ProtobufImpl) Unmarshal(marshaled []byte, msg proto.Message) error {
	return errors.WithStack(proto.Unmarshal(marshaled, msg))
}