// parseJSONTag parses the given JSON struct field tag, to get its name.
// omitting fields via tags is not supported.
427436
func parseJSONTag(tag string) string {
	if len(tag) == 0 {
		return ""
	}

	if tag[:7] != "`json:\"" {
		return ""
	}

	parts := strings.Split(tag[7:len(tag)-2], ",")

	return parts[0]
}
1069525
func NewTag(version byte) *Tag {
	header := &Header{version: version}

	t := &Tag{
		Header: header,
		frames: make(map[string][]Framer),
		dirty:  false,
	}

	switch t.version {
	case 2:
		t.commonMap = V22CommonFrame
		t.frameConstructor = ParseV22Frame
		t.frameHeaderSize = V22FrameHeaderSize
		t.frameBytesConstructor = V22Bytes
	case 3:
		t.commonMap = V23CommonFrame
		t.frameConstructor = ParseV23Frame
		t.frameHeaderSize = FrameHeaderSize
		t.frameBytesConstructor = V23Bytes
	default:
		t.commonMap = V23CommonFrame
		t.frameConstructor = ParseV23Frame
		t.frameHeaderSize = FrameHeaderSize
		t.frameBytesConstructor = V23Bytes
	}

	return t
}
43307
func parseEntityTag(structName, dosaAnnotation string) (string, time.Duration, ETLState, *PrimaryKey, error) {
	tag := dosaAnnotation

	// find the primaryKey
	matchs := primaryKeyPattern0.FindStringSubmatch(tag)
	if len(matchs) != primaryKeyPattern0.NumSubexp()+1 {
		return "", NoTTL(), EtlOff, nil, fmt.Errorf("dosa.Entity on object %s with an invalid dosa struct tag %q", structName, tag)
	}
	pkString := matchs[1]

	key, err := parsePrimaryKey(structName, pkString)
	if err != nil {
		return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "struct %s has an invalid primary key %q", structName, pkString)
	}
	toRemove := strings.TrimSuffix(matchs[0], matchs[2])
	toRemove = strings.TrimSuffix(matchs[0], matchs[3])
	tag = strings.Replace(tag, toRemove, "", 1)

	// find the name
	fullNameTag, name, err := parseNameTag(tag, structName)
	if err != nil {
		return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid name tag: %s", tag)
	}
	tag = strings.Replace(tag, fullNameTag, "", 1)

	// find the ETL flag
	fullETLTag, etlState, err := parseETLTag(tag)
	if err != nil {
		return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid etl tag: %s", tag)
	}
	tag = strings.Replace(tag, fullETLTag, "", 1)

	// find the ttl flag
	fullTTLTag, ttl, err := parseTTLTag(tag)
	if err != nil {
		return "", NoTTL(), EtlOff, nil, errors.Wrapf(err, "invalid ttl tag: %s", tag)
	}
	tag = strings.Replace(tag, fullTTLTag, "", 1)

	tag = strings.TrimSpace(tag)
	if tag != "" {
		return "", NoTTL(), EtlOff, nil, fmt.Errorf("struct %s with an invalid dosa struct tag: %s", structName, tag)
	}

	return name, ttl, etlState, key, nil
}
548592
func (t *tree) parseMsg(token item) ast.Node {
	const ctx = "msg"
	var attrs = t.parseAttrs("desc", "meaning", "hidden")
	if _, ok := attrs["desc"]; !ok {
		t.errorf("Tag 'msg' must have a 'desc' attribute")
	}
	t.expect(itemRightDelim, ctx)

	// Parse the message body.
	t.inmsg = true
	var contents = t.itemList(itemMsgEnd)
	t.inmsg = false

	// Replace children nodes with placeholders.
	var node = &ast.MsgNode{token.pos, 0, attrs["meaning"], attrs["desc"], t.placeholderize(contents)}

	// Validate: if there's a plural tag, it should be the only child
	var hasPlural = false
	for _, child := range node.Body.Children() {
		if _, ok := child.(*ast.MsgPluralNode); ok {
			hasPlural = true
		}
	}
	if hasPlural && len(node.Body.Children()) != 1 {
		t.errorf("content not allowed outside plural tag")
	}

	t.expect(itemRightDelim, ctx)
	return node
}
175047
func (tag *BuildTag) TagString() string {
	result := tag.Name
	if tag.isNoomitempty() {
		if tag.OmitEmpty {
			result += ",omitempty"
		}
	} else {
		if tag.OmitEmpty || !tag.ShouldEmit {
			result += ",omitempty"
		}
	}
	if tag.String { // TODO add special support for int64
		result += ",string"
	}
	return "json:\"" + result + "\""
}
978968
func ParseImageStreamTagName(istag string) (name string, tag string, err error) {
	if strings.Contains(istag, "@") {
		err = fmt.Errorf("%q is an image stream image, not an image stream tag", istag)
		return
	}
	segments := strings.SplitN(istag, ":", 3)
	switch len(segments) {
	case 2:
		name = segments[0]
		tag = segments[1]
		if len(name) == 0 || len(tag) == 0 {
			err = fmt.Errorf("image stream tag name %q must have a name and a tag", istag)
		}
	default:
		err = fmt.Errorf("expected exactly one : delimiter in the istag %q", istag)
	}
	return
}
713713
func parseMessage(ctx *context, msgNode *jsongo.JSONNode) (*Message, error) {
	if msgNode.Len() == 0 || msgNode.At(0).GetType() != jsongo.TypeValue {
		return nil, errors.New("invalid JSON for message specified")
	}

	msgName, ok := msgNode.At(0).Get().(string)
	if !ok {
		return nil, fmt.Errorf("message name is %T, not a string", msgNode.At(0).Get())
	}
	msgCRC, ok := msgNode.At(msgNode.Len() - 1).At(crcField).Get().(string)
	if !ok {

		return nil, fmt.Errorf("message crc invalid or missing")
	}

	msg := Message{
		Name: msgName,
		CRC:  msgCRC,
	}

	// loop through message fields, skip first (name) and last (crc)
	for j := 1; j < msgNode.Len()-1; j++ {
		if msgNode.At(j).GetType() == jsongo.TypeArray {
			fieldNode := msgNode.At(j)

			field, err := parseField(ctx, fieldNode)
			if err != nil {
				return nil, err
			}

			msg.Fields = append(msg.Fields, *field)
		}
	}

	return &msg, nil
}
967850
func parseJSONTagName(tag string) string {
	if idx := strings.Index(tag, ","); idx != -1 {
		return tag[:idx]
	}
	return tag
}
136191
func NewTag(tag string) Tag {
	var t Tag
	if copy(t[:], tag) != 2 {
		panic("sam: illegal tag length")
	}
	return t
}
323427
func parseJSON(input []byte) (*logEntry, error) {
	var raw map[string]interface{}
	entry := &logEntry{}

	err := json.Unmarshal(input, &raw)
	if err != nil {
		return nil, err
	}

	// Parse hclog-specific objects
	if v, ok := raw["@message"]; ok {
		entry.Message = v.(string)
		delete(raw, "@message")
	}

	if v, ok := raw["@level"]; ok {
		entry.Level = v.(string)
		delete(raw, "@level")
	}

	if v, ok := raw["@timestamp"]; ok {
		t, err := time.Parse("2006-01-02T15:04:05.000000Z07:00", v.(string))
		if err != nil {
			return nil, err
		}
		entry.Timestamp = t
		delete(raw, "@timestamp")
	}

	// Parse dynamic KV args from the hclog payload.
	for k, v := range raw {
		entry.KVPairs = append(entry.KVPairs, &logEntryKV{
			Key:   k,
			Value: v,
		})
	}

	return entry, nil
}
643506
func (p *parser) parseRawTag() (node, error) {
	t := p.read()
	if t.typ != tokenIdentifier {
		return nil, p.errorf(t, "unexpected token %s", t)
	}
	if next := p.read(); next.typ != tokenRawEnd {
		return nil, p.errorf(t, "unexpected token %s", t)
	}
	if next := p.read(); next.typ != tokenRightDelim {
		return nil, p.errorf(t, "unexpected token %s", t)
	}
	return &varNode{name: t.val, escape: false}, nil
}
734948
func (e *Encoder) UseJSONTag(flag bool) *Encoder {
	e.useJSONTag = flag
	return e
}
191563
func parseIndexTag(indexName, dosaAnnotation string) (string, *PrimaryKey, error) {
	// index name struct must be exported in the entity,
	// otherwise it will be ignored when upserting the schema.
	if len(indexName) != 0 && unicode.IsLower([]rune(indexName)[0]) {
		expected := []rune(indexName)
		expected[0] = unicode.ToUpper(expected[0])
		return "", nil, fmt.Errorf("index name (%s) must be exported, "+
			"try (%s) instead", indexName, string(expected))
	}
	tag := dosaAnnotation
	// find the primaryKey
	matchs := indexKeyPattern0.FindStringSubmatch(tag)
	if len(matchs) != 4 {
		return "", nil, fmt.Errorf("dosa.Index %s with an invalid dosa index tag %q", indexName, tag)
	}
	pkString := matchs[1]
	key, err := parsePrimaryKey(indexName, pkString)
	if err != nil {
		return "", nil, errors.Wrapf(err, "struct %s has an invalid index key %q", indexName, pkString)
	}
	toRemove := strings.TrimSuffix(matchs[0], matchs[2])
	toRemove = strings.TrimSuffix(matchs[0], matchs[3])
	tag = strings.Replace(tag, toRemove, "", 1)

	//find the name
	fullNameTag, name, err := parseNameTag(tag, indexName)
	if err != nil {
		return "", nil, errors.Wrapf(err, "invalid name tag: %s", tag)
	}

	tag = strings.Replace(tag, fullNameTag, "", 1)
	tag = strings.TrimSpace(tag)
	if tag != "" {
		return "", nil, fmt.Errorf("index field %s with an invalid dosa index tag: %s", indexName, tag)
	}

	return name, key, nil
}
1192732
func ParseJSON(js []byte) *Graph {
	// Parse JSON into Go struct
	var descr graphDescription
	err := json.Unmarshal(js, &descr)
	if err != nil {
		return nil
	}
	// fmt.Printf("%+v\n", descr)

	constructor := func() interface{} {
		// Create a new Graph
		net := new(Graph)
		net.InitGraphState()

		// Add processes to the network
		for procName, procValue := range descr.Processes {
			net.AddNew(procValue.Component, procName)
			// Process mode detection
			if procValue.Metadata.PoolSize > 0 {
				proc := net.Get(procName).(*Component)
				proc.Mode = ComponentModePool
				proc.PoolSize = uint8(procValue.Metadata.PoolSize)
			} else if procValue.Metadata.Sync {
				proc := net.Get(procName).(*Component)
				proc.Mode = ComponentModeSync
			}
		}

		// Add connections
		for _, conn := range descr.Connections {
			// Check if it is an IIP or actual connection
			if conn.Data == nil {
				// Add a connection
				net.ConnectBuf(conn.Src.Process, conn.Src.Port, conn.Tgt.Process, conn.Tgt.Port, conn.Metadata.Buffer)
			} else {
				// Add an IIP
				net.AddIIP(conn.Data, conn.Tgt.Process, conn.Tgt.Port)
			}
		}

		// Add port exports
		for _, export := range descr.Exports {
			// Split private into proc.port
			procName := export.Private[:strings.Index(export.Private, ".")]
			procPort := export.Private[strings.Index(export.Private, ".")+1:]
			// Try to detect port direction using reflection
			procType := reflect.TypeOf(net.Get(procName)).Elem()
			field, fieldFound := procType.FieldByName(procPort)
			if !fieldFound {
				panic("Private port '" + export.Private + "' not found")
			}
			if field.Type.Kind() == reflect.Chan && (field.Type.ChanDir()&reflect.RecvDir) != 0 {
				// It's an inport
				net.MapInPort(export.Public, procName, procPort)
			} else if field.Type.Kind() == reflect.Chan && (field.Type.ChanDir()&reflect.SendDir) != 0 {
				// It's an outport
				net.MapOutPort(export.Public, procName, procPort)
			} else {
				// It's not a proper port
				panic("Private port '" + export.Private + "' is not a valid channel")
			}
			// TODO add support for subgraphs
		}

		return net
	}

	// Register a component to be reused
	if descr.Properties.Name != "" {
		Register(descr.Properties.Name, constructor)
	}

	return constructor().(*Graph)
}
192289
func processJaegerTags(s *jThrift.Span) (*string, *trace.Endpoint, map[string]string) {
	var kind *string
	var remote *trace.Endpoint
	tags := make(map[string]string, len(s.Tags))

	ensureRemote := func() {
		if remote == nil {
			remote = &trace.Endpoint{}
		}
	}

	for i := range s.Tags {
		switch s.Tags[i].Key {
		case string(ext.PeerHostIPv4):
			ip := convertPeerIPv4(s.Tags[i])
			if ip == "" {
				continue
			}
			ensureRemote()
			remote.Ipv4 = pointer.String(ip)
		// ipv6 host is always string
		case string(ext.PeerHostIPv6):
			if s.Tags[i].VStr != nil {
				ensureRemote()
				remote.Ipv6 = s.Tags[i].VStr
			}
		case string(ext.PeerPort):
			port := convertPeerPort(s.Tags[i])
			if port == 0 {
				continue
			}
			ensureRemote()
			remote.Port = &port
		case string(ext.PeerService):
			ensureRemote()
			remote.ServiceName = s.Tags[i].VStr
		case string(ext.SpanKind):
			kind = convertKind(s.Tags[i])
		default:
			val := tagValueToString(s.Tags[i])
			if val != "" {
				tags[s.Tags[i].Key] = val
			}
		}
	}
	return kind, remote, tags
}
1075796
func parseNameTag(tag, defaultName string) (string, string, error) {
	fullNameTag := ""
	name := defaultName

	matches := namePattern0.FindStringSubmatch(tag)
	if len(matches) == 2 {
		fullNameTag = matches[0]
		name = matches[1]
	}

	// filter out "trailing comma"
	name = strings.TrimRight(name, " ,")

	var err error
	name, err = NormalizeName(name)
	if err != nil {
		return "", "", err
	}

	return fullNameTag, name, nil
}
511858
func NewTag(key, value []byte) Tag {
	return Tag{
		Key:   key,
		Value: value,
	}
}