// messageToPromText converts a single metrics message to prometheus-formatted
// newline-separate strings
198585
func messageToPromText(message producers.MetricsMessage) string {
	var buffer bytes.Buffer

	for _, d := range message.Datapoints {
		name := sanitizeName(d.Name)
		labels := getLabelsForDatapoint(message.Dimensions, d.Tags)
		t, err := time.Parse(time.RFC3339, d.Timestamp)
		if err != nil {
			log.Warnf("Encountered bad timestamp, %q: %s", d.Timestamp, err)
			continue
		}
		timestampMs := int(t.UnixNano() / 1000000)
		buffer.WriteString(fmt.Sprintf("%s%s %v %d\n", name, labels, d.Value, timestampMs))
	}

	return buffer.String()
}
921610
func (formatter *outputFormatter) Text(s *goquery.Selection) string {
	var buf bytes.Buffer

	// Slightly optimized vs calling Each: no single selection object created
	var f func(*html.Node)
	f = func(n *html.Node) {
		if n.Type == html.TextNode && 0 == n.DataAtom { // NB: had to add the DataAtom check to avoid printing text twice when a textual node embeds another textual node
			// Keep newlines and spaces, like jQuery
			buf.WriteString(n.Data)
		}
		if n.FirstChild != nil {
			for c := n.FirstChild; c != nil; c = c.NextSibling {
				f(c)
			}
		}
	}
	for _, n := range s.Nodes {
		f(n)
	}

	return buf.String()
}
1170581
func NewFormattedMessage(p level.Priority, base string, args ...interface{}) Composer {
	m := &formatMessenger{
		base: base,
		args: args,
	}
	_ = m.SetPriority(p)

	return m
}
1048910
func stdoutConnector(metrics []producers.MetricsMessage, c *cli.Context) error {
	if len(metrics) == 0 {
		log.Info("No messages received from metrics service")
		return nil
	}
	for _, message := range metrics {
		dimensions := &message.Dimensions

		// we print a few potentially interesting dimensions
		log.Infof("Metrics from task %s, framework %s, host %s", dimensions.ExecutorID, dimensions.FrameworkName, dimensions.Hostname)
		if len(dimensions.Labels) > 0 {
			log.Infof("Labels: %v", dimensions.Labels)
		}

		log.Info("Datapoints:")
		for _, datapoint := range message.Datapoints {
			// For clarity, we don't print timestamp or tags here.
			log.Infof("  %s: %v", datapoint.Name, datapoint.Value)
		}
	}

	return nil
}
1362740
func (format *Sequence) ApplyFormatter(msg *core.Message) error {
	seq := atomic.AddInt64(format.seq, 1)
	sequenceStr := strconv.FormatInt(seq, 10)
	content := format.GetAppliedContent(msg)

	dataSize := len(sequenceStr) + len(format.separator) + len(content)
	payload := make([]byte, dataSize)

	offset := copy(payload, []byte(sequenceStr))
	offset += copy(payload[offset:], format.separator)
	copy(payload[offset:], content)

	format.SetAppliedContent(msg, payload)
	return nil
}
710402
func NewStatustext(SEVERITY uint8, TEXT [50]uint8) *Statustext {
	m := Statustext{}
	m.SEVERITY = SEVERITY
	m.TEXT = TEXT
	return &m
}
588909
func MessageSummary(msg Message) string {
	switch msg := msg.(type) {
	case *Init:
		return ""

	case *CreateSession:
		return fmt.Sprintf("blob_type=%s, max_updates=%d "+
			"reward_base=%d reward_rate=%d sweep_fee_rate=%d",
			msg.BlobType, msg.MaxUpdates, msg.RewardBase,
			msg.RewardRate, msg.SweepFeeRate)

	case *CreateSessionReply:
		return fmt.Sprintf("code=%d", msg.Code)

	case *StateUpdate:
		return fmt.Sprintf("seqnum=%d last_applied=%d is_complete=%d "+
			"hint=%x", msg.SeqNum, msg.LastApplied, msg.IsComplete,
			msg.Hint)

	case *StateUpdateReply:
		return fmt.Sprintf("code=%d last_applied=%d", msg.Code,
			msg.LastApplied)

	case *Error:
		return fmt.Sprintf("code=%d", msg.Code)

	default:
		return ""
	}
}
1157528
func (t *Table) ToText(sep string) (*bytes.Buffer, error) {
	t.mu.RLock()
	defer t.mu.RUnlock()
	res, row := &bytes.Buffer{}, &bytes.Buffer{}
	res.WriteString(strings.Join(t.AvailableBindings, sep))
	res.WriteString("\n")
	for _, r := range t.Data {
		err := r.ToTextLine(row, t.AvailableBindings, sep)
		if err != nil {
			return nil, err
		}
		if _, err := res.Write(row.Bytes()); err != nil {
			return nil, err
		}
		if _, err := res.WriteString("\n"); err != nil {
			return nil, err
		}
		row.Reset()
	}
	return res, nil
}
656034
func (tm *TextMarshaler) Text(pb Message) string {
	var buf bytes.Buffer
	tm.Marshal(&buf, pb)
	return buf.String()
}
1193070
func newMessageWriter(w http.ResponseWriter, getProgressFunc func() (bytesScanned, bytesProcessed int64)) *messageWriter {
	writer := &messageWriter{
		writer:          w,
		getProgressFunc: getProgressFunc,

		payloadBuffer: make([]byte, bufLength),
		payloadCh:     make(chan []byte),

		errCh:  make(chan []byte),
		doneCh: make(chan struct{}),
	}
	go writer.start()
	return writer
}
72251
func CompactTextString(pb Message) string {
	var buf bytes.Buffer
	marshalText(&buf, pb, true)
	return buf.String()
}
245878
func (p *TJSONProtocol) ReadMessageBegin() (name string, typeId TMessageType, seqId int32, err error) {
	p.resetContextStack() // THRIFT-3735
	if isNull, err := p.ParseListBegin(); isNull || err != nil {
		return name, typeId, seqId, err
	}
	version, err := p.ReadI32()
	if err != nil {
		return name, typeId, seqId, err
	}
	if version != THRIFT_JSON_PROTOCOL_VERSION {
		e := fmt.Errorf("Unknown Protocol version %d, expected version %d", version, THRIFT_JSON_PROTOCOL_VERSION)
		return name, typeId, seqId, NewTProtocolExceptionWithType(INVALID_DATA, e)

	}
	if name, err = p.ReadString(); err != nil {
		return name, typeId, seqId, err
	}
	bTypeId, err := p.ReadByte()
	typeId = TMessageType(bTypeId)
	if err != nil {
		return name, typeId, seqId, err
	}
	if seqId, err = p.ReadI32(); err != nil {
		return name, typeId, seqId, err
	}
	return name, typeId, seqId, nil
}
1121000
func messageSummary(msg wire.Message) string {
	switch msg := msg.(type) {
	case *wire.MsgVersion:
		return fmt.Sprintf("agent %s, pver %d, block %d",
			msg.UserAgent, msg.ProtocolVersion, msg.LastBlock)

	case *wire.MsgVerAck:
		// No summary.

	case *wire.MsgGetAddr:
		// No summary.

	case *wire.MsgAddr:
		return fmt.Sprintf("%d addr", len(msg.AddrList))

	case *wire.MsgPing:
		// No summary - perhaps add nonce.

	case *wire.MsgPong:
		// No summary - perhaps add nonce.

	case *wire.MsgAlert:
		// No summary.

	case *wire.MsgMemPool:
		// No summary.

	case *wire.MsgTx:
		return fmt.Sprintf("hash %s, %d inputs, %d outputs, lock %s",
			msg.TxHash(), len(msg.TxIn), len(msg.TxOut),
			formatLockTime(msg.LockTime))

	case *wire.MsgBlock:
		header := &msg.Header
		return fmt.Sprintf("hash %s, ver %d, %d tx, %s", msg.BlockHash(),
			header.Version, len(msg.Transactions), header.Timestamp)

	case *wire.MsgInv:
		return invSummary(msg.InvList)

	case *wire.MsgNotFound:
		return invSummary(msg.InvList)

	case *wire.MsgGetData:
		return invSummary(msg.InvList)

	case *wire.MsgGetBlocks:
		return locatorSummary(msg.BlockLocatorHashes, &msg.HashStop)

	case *wire.MsgGetHeaders:
		return locatorSummary(msg.BlockLocatorHashes, &msg.HashStop)

	case *wire.MsgHeaders:
		return fmt.Sprintf("num %d", len(msg.Headers))

	case *wire.MsgGetCFHeaders:
		return fmt.Sprintf("start_height=%d, stop_hash=%v",
			msg.StartHeight, msg.StopHash)

	case *wire.MsgCFHeaders:
		return fmt.Sprintf("stop_hash=%v, num_filter_hashes=%d",
			msg.StopHash, len(msg.FilterHashes))

	case *wire.MsgReject:
		// Ensure the variable length strings don't contain any
		// characters which are even remotely dangerous such as HTML
		// control characters, etc.  Also limit them to sane length for
		// logging.
		rejCommand := sanitizeString(msg.Cmd, wire.CommandSize)
		rejReason := sanitizeString(msg.Reason, maxRejectReasonLen)
		summary := fmt.Sprintf("cmd %v, code %v, reason %v", rejCommand,
			msg.Code, rejReason)
		if rejCommand == wire.CmdBlock || rejCommand == wire.CmdTx {
			summary += fmt.Sprintf(", hash %v", msg.Hash)
		}
		return summary
	}

	// No summary for other messages.
	return ""
}
698572
func (m TaskManager) ValidateProtoMessage(c *validation.Context, msg proto.Message) {
	cfg, ok := msg.(*messages.UrlFetchTask)
	if !ok {
		c.Errorf("wrong type %T, expecting *messages.UrlFetchTask", msg)
		return
	}
	if cfg == nil {
		c.Errorf("expecting a non-empty UrlFetchTask")
		return
	}

	// Validate 'method' field.
	// TODO(vadimsh): Add more methods (POST, PUT) when 'Body' is added.
	goodMethods := map[string]bool{"GET": true}
	if cfg.Method != "" && !goodMethods[cfg.Method] {
		c.Errorf("unsupported HTTP method: %q", cfg.Method)
	}

	// Validate 'url' field.
	if cfg.Url == "" {
		c.Errorf("field 'url' is required")
	} else {
		u, err := url.Parse(cfg.Url)
		if err != nil {
			c.Errorf("invalid URL %q: %s", cfg.Url, err)
		} else if !u.IsAbs() {
			c.Errorf("not an absolute url: %q", cfg.Url)
		}
	}

	// Validate 'timeout_sec' field. GAE task queue request deadline is 10 min, so
	// limit URL fetch call duration to 8 min (giving 2 min to spare).
	if cfg.TimeoutSec != 0 {
		if cfg.TimeoutSec < 1 {
			c.Errorf("minimum allowed 'timeout_sec' is 1 sec, got %d", cfg.TimeoutSec)
		}
		if cfg.TimeoutSec > 480 {
			c.Errorf("maximum allowed 'timeout_sec' is 480 sec, got %d", cfg.TimeoutSec)
		}
	}
}
1298808
func (a *Accelerator) MarshalText() ([]byte, error) {
	return []byte(strings.Join(*a, acceleratorSeparator)), nil
}
757410
func (cms *ConcurrentMergeScheduler) message(format string, args ...interface{}) {
	cms.writer.infoStream.Message("CMS", format, args...)
}
695871
func (this *Weixinmp) ReplyTextMsg(rw http.ResponseWriter, content string) error {
	var msg textMsg
	msg.MsgType = "text"
	msg.Content = content
	return this.replyMsg(rw, &msg)
}