// NewJIRACommentMessage returns a self-contained composer for posting a comment
// to a single JIRA issue. This composer will override the issue set in the
// JIRA sender
196383
func NewJIRACommentMessage(p level.Priority, issueID, body string) Composer {
	s := MakeJIRACommentMessage(issueID, body)
	_ = s.SetPriority(p)

	return s
}
775485
func NewBytesMessage(p level.Priority, b []byte) Composer {
	m := &bytesMessage{
		data: b,
	}

	_ = m.SetPriority(p)

	return m
}
105167
func NewMessage(topic string, payload interface{}, opts ...MessageOption) Message {
	return DefaultClient.NewMessage(topic, payload, opts...)
}
1030907
func (fw *Framework) NewRequestFromMessage(version string, msg *Message) (req protocol.Request, err error) {
	if !(msg.Type() == "request" || msg.Type() == "direct_request") {
		err = fmt.Errorf("Cannot use `%s` message to construct a Request", msg.Type())
		return
	}

	req, err = fw.NewRequest(version, msg.Agent, msg.SenderID, msg.CallerID, msg.TTL, msg.RequestID, msg.Collective())
	if err != nil {
		return req, fmt.Errorf("Could not create a Request from a Message: %s", err)
	}

	req.SetMessage(msg.Payload)

	if msg.Filter == nil || msg.Filter.Empty() {
		req.NewFilter()
	} else {
		req.SetFilter(msg.Filter)
	}

	return
}
485928
func (sp *SendAudio) ReplyToMessage(rm int) *SendAudio {
	sp.ReplyToMessageID = &rm
	return sp
}
645833
func NewFieldsMessage(p level.Priority, message string, f Fields) Composer {
	m := MakeFieldsMessage(message, f)

	_ = m.SetPriority(p)

	return m
}
695273
func NewInitMessage(gf *RawFeatureVector, lf *RawFeatureVector) *Init {
	return &Init{
		GlobalFeatures: gf,
		LocalFeatures:  lf,
	}
}
460588
func NewMessagesReceivedTotalStatsHandler(sub Subsystem, vec *prometheus.CounterVec) *MessagesReceivedTotalStatsHandler {
	return &MessagesReceivedTotalStatsHandler{
		baseStatsHandler: baseStatsHandler{
			subsystem: sub,
			collector: vec,
		},
		vec: vec,
	}
}
246854
func NewRunMessage(statement string, parameters map[string]interface{}) RunMessage {
	return RunMessage{
		statement:  statement,
		parameters: parameters,
	}
}
307903
func NewMessage(data []byte) (*Message, error) {
	message := &Message{}
	message.startByte = data[0]
	if len(data) <= 1 {
		return message, nil
	}
	message.Length = data[1]
	message.MessageType = data[2]
	message.Function = ZWaveFunction(data[3])

	var err error
	switch message.Function {
	case ApplicationCommandHandler:
		message.NodeID = data[5]

		message.Data, err = NewApplicationCommandHandler(data[7 : 7+data[6]])
	case DiscoveryNodes:

		message.Data, err = NewDiscoverdNodes(data[7 : 7+data[6]])
	case GetNodeProtocolInfo:

		message.Data, err = NewGetNodeProtocolInfo(data[4:])
	default:
		err = fmt.Errorf("Dropping message function='%s' with data %x (not implemented)", message.Function, data[4:])
	}

	if err != nil {
		return nil, err
	}

	logrus.Debugf("Message: %+v Message data: %+v", message, message.Data)
	return message, err

	// 1 FrameHeader (type of message)
	// 1 Message length
	// 1 Request (00) or Response (01)
	// 1 Function
	//
	// 1 (Node ID)
	// 1 (Command - length)
	// - (Command)
	// - (Transmit options)
	// - (Callback id)
	// 1 Checksum

	// Type
	//Request = 0x00,
	//Response = 0x01,
	//GetVersion = 0x15,
	//MemoryGetId = 0x20,
	//ClockSet = 0x30

	// Transmit options
	//Ack = 0x01,
	//LowPower = 0x02,
	//AutoRoute = 0x04,
	//ForceRoute = 0x08

}
69803
func CreateMessage(c *messagebird.Client, conversationID string, req *MessageCreateRequest) (*Message, error) {
	uri := fmt.Sprintf("%s/%s/%s", path, conversationID, messagesPath)

	message := &Message{}
	if err := request(c, message, http.MethodPost, uri, req); err != nil {
		return nil, err
	}

	return message, nil
}
1074563
func NewMessageWriter(info *api.Info) (MessageWriter, error) {
	conn, err := api.Open(info, dialOpts)
	if err != nil {
		return nil, errors.Trace(err)
	}
	a := pubsubapi.NewAPI(conn)
	writer, err := a.OpenMessageWriter()
	if err != nil {
		conn.Close()
		return nil, errors.Trace(err)
	}
	return &remoteConnection{connection: conn, MessageWriter: writer}, nil
}
445778
func (sp *SendSticker) ReplyToMessage(rm int) *SendSticker {
	sp.ReplyToMessageID = &rm
	return sp
}
214271
func NewMessage(sz int) *Message {
	var m *Message
	for i := range messageCache {
		if sz < messageCache[i].maxbody {
			m = messageCache[i].pool.Get().(*Message)
			break
		}
	}
	if m == nil {
		m = newMsg(sz)
	}

	m.refcnt = 1
	m.Body = m.bbuf
	m.Header = m.hbuf
	return m
}
1239770
func NewLogMessage(bee string, message string, messageType uint) LogMessage {
	return LogMessage{
		ID:          UUID(),
		Bee:         bee,
		Message:     message,
		MessageType: messageType,
		Timestamp:   time.Now(),
	}
}
601232
func NewMessageItem(ch string, m *Message) Item {
	return Item{Type: TYPE_MESSAGE, Channel: ch, Message: m}
}
778313
func newMessageManager(tsv TabletService, table *schema.Table, conns *connpool.Pool, postponeSema *sync2.Semaphore) *messageManager {
	mm := &messageManager{
		tsv:  tsv,
		name: table.Name,
		fieldResult: &sqltypes.Result{
			Fields: table.MessageInfo.Fields,
		},
		ackWaitTime:  table.MessageInfo.AckWaitDuration,
		purgeAfter:   table.MessageInfo.PurgeAfterDuration,
		batchSize:    table.MessageInfo.BatchSize,
		cache:        newCache(table.MessageInfo.CacheSize),
		pollerTicks:  timer.NewTimer(table.MessageInfo.PollInterval),
		purgeTicks:   timer.NewTimer(table.MessageInfo.PollInterval),
		conns:        conns,
		postponeSema: postponeSema,
	}
	mm.cond.L = &mm.mu

	columnList := buildSelectColumnList(table)
	mm.readByTimeNext = sqlparser.BuildParsedQuery(
		"select time_next, epoch, time_created, %s from %v where time_next < %a order by time_next desc limit %a",
		columnList, mm.name, ":time_next", ":max")
	mm.loadMessagesQuery = sqlparser.BuildParsedQuery(
		"select time_next, epoch, time_created, %s from %v where %a",
		columnList, mm.name, ":#pk")
	mm.ackQuery = sqlparser.BuildParsedQuery(
		"update %v set time_acked = %a, time_next = null where id in %a and time_acked is null",
		mm.name, ":time_acked", "::ids")
	mm.postponeQuery = sqlparser.BuildParsedQuery(
		"update %v set time_next = %a+(%a<<epoch), epoch = epoch+1 where id in %a and time_acked is null",
		mm.name, ":time_now", ":wait_time", "::ids")
	mm.purgeQuery = sqlparser.BuildParsedQuery(
		"delete from %v where time_scheduled < %a and time_acked is not null limit 500",
		mm.name, ":time_scheduled")
	return mm
}