// UpsertMessageType is a convenience upserts the message type
// of a pb.Message into the KeyMessageType.
343500
func UpsertMessageType(m *pb.Message) tag.Mutator {
	return tag.Upsert(KeyMessageType, m.Type.String())
}
212431
func NewMessage(typ Message_MessageType, key []byte, level int) *Message {
	m := &Message{
		Type: typ,
		Key:  key,
	}
	m.SetClusterLevel(level)
	return m
}
273912
func encode(msgType messageType, in interface{}) (*bytes.Buffer, error) {
	buf := bytes.NewBuffer(nil)
	buf.WriteByte(uint8(msgType))
	hd := codec.MsgpackHandle{}
	enc := codec.NewEncoder(buf, &hd)
	err := enc.Encode(in)
	return buf, err
}
1239561
func (q *StreamHealthQueryService) UpdateType(tabletType topodatapb.TabletType) {
	q.target.TabletType = tabletType
}
1006672
func (h *HTTPBodyMarshaler) ContentTypeFromMessage(v interface{}) string {
	if httpBody, ok := v.(*httpbody.HttpBody); ok {
		return httpBody.GetContentType()
	}
	return h.Marshaler.ContentType()
}
981906
func (dct *DjangoContentType) Upsert(db XODB) error {
	var err error

	// if already exist, bail
	if dct._exists {
		return errors.New("insert failed: already exists")
	}

	// sql query
	const sqlstr = `INSERT INTO public.django_content_type (` +
		`id, app_label, model` +
		`) VALUES (` +
		`$1, $2, $3` +
		`) ON CONFLICT (id) DO UPDATE SET (` +
		`id, app_label, model` +
		`) = (` +
		`EXCLUDED.id, EXCLUDED.app_label, EXCLUDED.model` +
		`)`

	// run query
	XOLog(sqlstr, dct.ID, dct.AppLabel, dct.Model)
	_, err = db.Exec(sqlstr, dct.ID, dct.AppLabel, dct.Model)
	if err != nil {
		return err
	}

	// set existence
	dct._exists = true

	return nil
}
596541
func Type(msg proto.Message) uint16 {
	return uint16(MessageType_value["MessageType_"+reflect.TypeOf(msg).Elem().Name()])
}
1371772
func (c *Client) UpsertPassword(user string, password []byte) error {
	_, err := c.PostJSON(
		c.Endpoint("users", user, "web", "password"),
		upsertPasswordReq{
			Password: string(password),
		})
	if err != nil {
		return trace.Wrap(err)
	}

	return nil
}
169312
func (cm AsStandard) MUpdateType(resource, class, update string) *metadata.MUpdateType {
	mut := metadata.MUpdateType{}
	mi := metadata.MIUpdateType
	for _, cd := range cm.Elements[mi.Name] {
		if cd.Attr["Resource"] != resource {
			continue
		}
		if cd.Attr["Class"] != class {
			continue
		}
		if cd.Attr["Update"] != update {
			continue
		}
		metadata.FieldTransfer(cd.Attr).To(&mut)
		for _, entry := range cd.Entries() {
			tmp := metadata.UpdateType{}
			entry.SetFields(&tmp)
			mut.UpdateType = append(mut.UpdateType, tmp)
		}
	}
	return &mut
}
1046721
func findMessageByTypeName(s string) (*dotaMessage, bool) {
	for _, t := range messageTypes {
		if t.typeRe.MatchString(s) {
			return t, true
		}
	}
	return nil, false
}
40231
func PayloadType(i interface{}) string {
	v := reflect.Indirect(reflect.ValueOf(i))
	if !v.IsValid() {
		return ""
	}
	if field, ok := v.Type().FieldByName("_"); ok {
		if payloadName := field.Tag.Get("payload"); payloadName != "" {
			if member, ok := v.Type().FieldByName(payloadName); ok {
				return member.Tag.Get("type")
			}
		}
	}
	return ""
}
996026
func GetMessageType(typ reflect.Type) (*MessageType, error) {
	typeRegistry.m.RLock()
	cached := typeRegistry.types[typ]
	typeRegistry.m.RUnlock()
	if cached != nil {
		return cached, nil
	}

	zero := reflect.Zero(typ) // (*Struct)(nil)
	name := proto.MessageName(zero.Interface().(proto.Message))
	if name == "" {
		return nil, fmt.Errorf("%q is not a registered proto message type", typ.Name())
	}

	typeRegistry.m.Lock()
	defer typeRegistry.m.Unlock()
	if typeRegistry.types == nil {
		typeRegistry.types = map[reflect.Type]*MessageType{}
	}

	strct := typ.Elem() // Struct{}
	props := proto.GetProperties(strct)

	fields := map[string]fieldDesc{}
	names := []string{}

	// Handle non-oneof fields.
	for _, prop := range props.Prop {
		prop := prop
		// Oneof wrapper types generated by Go protoc have no tags and should not
		// appear in the list of message fields. Oneofs are handled below based on
		// props.OneofTypes map.
		if prop.Tag == 0 {
			continue
		}
		f, ok := strct.FieldByName(prop.Name)
		if !ok {
			panic("property from proto.GetProperties is not defined in the go struct")
		}
		fields[prop.OrigName] = fieldDesc{
			typ:         f.Type,
			defaultable: true,
			onProtoReflection: func(msg reflect.Value, _ reflectionDirection) reflect.Value {
				return msg.FieldByName(prop.Name)
			},
		}
		names = append(names, prop.OrigName)
	}

	// Oneof fields are very special.
	//
	// Imagine we have the following message:
	//
	// message Msg {
	//   ...
	//   oneof wrapper {
	//     A field_a = 1;
	//     B field_b = 2;
	//   }
	// }
	//
	// Protoc will generate the following types for it:
	//
	// type Msg struct {
	//    ...
	//    Wrapper isMsg_Wrapper // assume index of this field in Msg struct is 7
	// }
	//
	// type Msg_FieldA struct {
	//    FieldA *A
	// }
	//
	// type Msg_FieldB struct {
	//    FieldB *B
	// }
	//
	// (where *Msg_FieldA and *Msg_FieldB implement isMsg_Wrapper interface)
	//
	// When examining this via 'props' we'll see 'wrapper' listed among
	// props.Prop. We skip it completely since we want to expose only 'a' and 'b'.
	//
	// Next we'll see props.OneofTypes to be a map:
	//
	// 'field_a': {
	//   Type: *testprotos.Msg_FieldA
	//   Field: 7
	//   Prop: <useless>
	// },
	// 'field_b': {
	//   Type: *testprotos.Msg_FieldB
	//   Field: 7
	//   Prop: <useless>
	// }
	//
	// (where 7, as mentioned above, is an index of Wrapper field in Msg go
	// struct).
	//
	// Important details here:
	//   * Names of the Go fields inside Msg_* structs are not mentioned anywhere,
	//     e.g. 'FieldA' is not mentioned. We workaround this by asserting that
	//     Msg_* structs have only one field and then just referring to this field
	//     by index 0.
	//   * Wrapper field index (7), can be used to associate a bunch of oneof
	//     alternatives with each other (e.g. when setting one, clear another).
	//     So we'll build a reverse map {7 -> ['field_a', 'field_b']} for this.
	oneofGroups := map[int]*oneofGroup{} // keyed by the field index
	for name, desc := range props.OneofTypes {
		ofg := oneofGroups[desc.Field]
		if ofg == nil {
			ofg = &oneofGroup{
				fieldIdx: desc.Field,
			}
			oneofGroups[desc.Field] = ofg
		}
		ofg.registerAlternative(name, desc)
	}
	for _, ofg := range oneofGroups {
		for name, fd := range ofg.fieldDescs() {
			fields[name] = fd
			names = append(names, name)
		}
	}

	sort.Strings(names)

	newTyp := &MessageType{
		name:       name,
		ptr:        typ,
		fields:     fields,
		fieldNames: names,
	}
	typeRegistry.types[typ] = newTyp
	return newTyp, nil
}
394702
func (c *DefaultPublisher) PublishUplink(dataUp types.UplinkMessage) error {
	key := DeviceKey{dataUp.AppID, dataUp.DevID, DeviceUplink, ""}
	msg, err := json.Marshal(dataUp)
	if err != nil {
		return fmt.Errorf("Unable to marshal the message payload: %s", err)
	}
	return c.publish(key.String(), msg, time.Time(dataUp.Metadata.Time))
}
1173343
func ConvertProtoToMessageType(protoMsgType protos.MsgType) message.Type {
	var msgType message.Type
	switch protoMsgType {
	case protos.MsgType_MsgRequest:
		msgType = message.Request
	case protos.MsgType_MsgNotify:
		msgType = message.Notify
	}
	return msgType
}
281122
func (m *MessageType) NewProtoMessage() reflect.Value {
	return reflect.New(m.ptr.Elem())
}
381565
func (a *VppAdapter) ReplyTypeFor(requestMsgName string) (reflect.Type, uint16, bool) {
	replyName, foundName := binapi.ReplyNameFor(requestMsgName)
	if foundName {
		if reply, found := a.binAPITypes[replyName]; found {
			msgID, err := a.GetMsgID(replyName, "")
			if err == nil {
				return reply, msgID, found
			}
		}
	}

	return nil, 0, false
}
912872
func (r *BulkUpdateRequest) VersionType(versionType string) *BulkUpdateRequest {
	r.versionType = versionType
	return r
}