// MessageType returns the message type (pointer to struct) for a named message.
// The type is not guaranteed to implement proto.Message if the name refers to a
// map entry.
6740
func MessageType(name string) reflect.Type {
	if t, ok := protoTypedNils[name]; ok {
		return reflect.TypeOf(t)
	}
	return protoMapTypes[name]
}
1072459
func Type(tname string) reflect.Type {
	if t, found := typemap[tname]; found {
		return t
	}
	panic("Type not found: " + tname)
}
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
}
613737
func (sbc *SandboxConn) MessageStream(ctx context.Context, target *querypb.Target, name string, callback func(*sqltypes.Result) error) (err error) {
	if err := sbc.getError(); err != nil {
		return err
	}
	r := sbc.getNextResult()
	if r == nil {
		return nil
	}
	callback(r)
	return nil
}
487768
func (p *Parameter) DataType(typeName string) *Parameter {
	p.data.DataType = typeName
	return p
}
787778
func NewMessage(typ *MessageType) *Message {
	return &Message{
		typ:    typ,
		fields: starlark.StringDict{},
	}
}
1256044
func (s *GetService) Type(typ string) *GetService {
	s.typ = typ
	return s
}
126158
func (c *Certificate) Type() string {
	algo, ok := certAlgoNames[c.Key.Type()]
	if !ok {
		panic("unknown cert key type")
	}
	return algo
}
663144
func (p *Processor) Marshal(msg interface{}) ([][]byte, error) {
	msgType := reflect.TypeOf(msg)
	if msgType == nil || msgType.Kind() != reflect.Ptr {
		return nil, errors.New("json message pointer required")
	}
	msgID := msgType.Elem().Name()
	if _, ok := p.msgInfo[msgID]; !ok {
		return nil, fmt.Errorf("message %v not registered", msgID)
	}

	// data
	m := map[string]interface{}{msgID: msg}
	data, err := json.Marshal(m)
	return [][]byte{data}, err
}
1133087
func (s *serverReflectionServer) fileDescForType(st reflect.Type) (*dpb.FileDescriptorProto, error) {
	m, ok := reflect.Zero(reflect.PtrTo(st)).Interface().(protoMessage)
	if !ok {
		return nil, fmt.Errorf("failed to create message from type: %v", st)
	}
	enc, _ := m.Descriptor()

	return decodeFileDesc(enc)
}
1297761
func (m *Messenger) SendGeneralMessage(to Recipient, elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error {
	r := &Response{
		token: m.token,
		to:    to,
	}
	return r.GenericTemplate(elements, messagingType, tags...)
}
426172
func encodeRelayMessage(t messageType, addr net.UDPAddr, msg interface{}) ([]byte, error) {
	buf := bytes.NewBuffer(nil)
	handle := codec.MsgpackHandle{}
	encoder := codec.NewEncoder(buf, &handle)

	buf.WriteByte(uint8(messageRelayType))
	if err := encoder.Encode(relayHeader{DestAddr: addr}); err != nil {
		return nil, err
	}

	buf.WriteByte(uint8(t))
	err := encoder.Encode(msg)
	return buf.Bytes(), err
}
1300402
func Message(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "message", Listener: listener}
}
111266
func (s *SearchService) SearchType(searchType string) *SearchService {
	s.searchType = searchType
	return s
}
237653
func (m MessageType) String() string {
	switch m {
	case MsgInit:
		return "Init"
	case MsgCreateSession:
		return "MsgCreateSession"
	case MsgCreateSessionReply:
		return "MsgCreateSessionReply"
	case MsgStateUpdate:
		return "MsgStateUpdate"
	case MsgStateUpdateReply:
		return "MsgStateUpdateReply"
	case MsgDeleteSession:
		return "MsgDeleteSession"
	case MsgDeleteSessionReply:
		return "MsgDeleteSessionReply"
	case MsgError:
		return "Error"
	default:
		return "<unknown>"
	}
}
224054
func generateMessageTypeGetter(w io.Writer, structName string, msgType MessageType) {
	fmt.Fprintln(w, "func (*"+structName+") GetMessageType() api.MessageType {")
	if msgType == requestMessage {
		fmt.Fprintln(w, "\treturn api.RequestMessage")
	} else if msgType == replyMessage {
		fmt.Fprintln(w, "\treturn api.ReplyMessage")
	} else if msgType == eventMessage {
		fmt.Fprintln(w, "\treturn api.EventMessage")
	} else {
		fmt.Fprintln(w, "\treturn api.OtherMessage")
	}
	fmt.Fprintln(w, "}")
}
820547
func (m *Message) Bytes() ([]byte, error) {
	if b, ok := m.val.([]byte); ok {
		return b, nil
	}
	return nil, badType
}