// NewBytesMessage provides a Composer interface around a byte slice,
// which are always logable unless the string is empty.
775485
func NewBytesMessage(p level.Priority, b []byte) Composer {
	m := &bytesMessage{
		data: b,
	}

	_ = m.SetPriority(p)

	return m
}
221954
func Bytes(m *rfc5424.Message) []byte {
	msg := m.Bytes()
	return bytes.Join([][]byte{[]byte(strconv.Itoa(len(msg))), msg}, []byte{' '})
}
386434
func (m *InMessage) ConsumeBytes(n uintptr) (b []byte) {
	if n > m.Len() {
		return
	}

	b = m.remaining[:n]
	m.remaining = m.remaining[n:]

	return
}
1145951
func NewMessage(data interface{}) (*Message, error) {
	m := &Message{}
	if err := m.unmarshalInterface(data); err != nil {
		return nil, err
	}
	return m, nil
}
146899
func NewErrorMessage(errorCode, errorMessage string) []byte {
	return newErrorMessage([]byte(errorCode), []byte(errorMessage))
}
393057
func (s *server) OnNewMessage(callback func(c *Client, message string)) {
	s.onNewMessage = callback
}
1096713
func NewBytesResponder(status int, body []byte) Responder {
	return ResponderFromResponse(NewBytesResponse(status, body))
}
603812
func NewMessage(chatID int64, text string) MessageConfig {
	return MessageConfig{
		BaseChat: BaseChat{
			ChatID:           chatID,
			ReplyToMessageID: 0,
		},
		Text:                  text,
		DisableWebPagePreview: false,
	}
}
822372
func (l *Logger) NewMessage() *Message {
	msg := newMessage()
	msg.logger = l
	msg.Hostname = l.client.hostname
	return msg
}
585599
func NewSentMessage(params *MessageParams) (*sentMessage, error) {
	const payloadSizeFieldMaxSize = 4
	msg := sentMessage{}
	msg.Raw = make([]byte, 1,
		flagsLength+payloadSizeFieldMaxSize+len(params.Payload)+len(params.Padding)+signatureLength+padSizeLimit)
	msg.Raw[0] = 0 // set all the flags to zero
	msg.addPayloadSizeField(params.Payload)
	msg.Raw = append(msg.Raw, params.Payload...)
	err := msg.appendPadding(params)
	return &msg, err
}
1108848
func NewMessage(id uint64, phstr string) *Message {
	return &Message{id, Parts(phstr)}
}
159113
func NewErrorMessage(p level.Priority, err error) Composer {
	m := &errorMessage{
		err: err,
	}

	_ = m.SetPriority(p)
	return m
}
47750
func (c *Conn) WriteMessage(messageType int, data []byte) error {

	if c.isServer && (c.newCompressionWriter == nil || !c.enableWriteCompression) {
		// Fast path with no allocations and single frame.

		var mw messageWriter
		if err := c.beginMessage(&mw, messageType); err != nil {
			return err
		}
		n := copy(c.writeBuf[mw.pos:], data)
		mw.pos += n
		data = data[n:]
		return mw.flushFrame(true, data)
	}

	w, err := c.NextWriter(messageType)
	if err != nil {
		return err
	}
	if _, err = w.Write(data); err != nil {
		return err
	}
	return w.Close()
}
128469
func NewLineMessage(p level.Priority, args ...interface{}) Composer {
	m := NewLine(args...)
	_ = m.SetPriority(p)
	return m
}
643346
func (m EncryptedMessage) ToBytes() ([]byte, error) {
	if m.length > math.MaxUint64 {
		return nil, errors.New("The message exceeds the maximum allowed sized: uint64 MAX")
	}

	var buffer bytes.Buffer

	// length
	lengthBytes := smallendian.ToUint64(m.length)
	buffer.Write(lengthBytes[:])

	// nonce
	buffer.Write(m.nonce[:])

	// message
	buffer.Write(m.data)

	return buffer.Bytes(), nil

}
1154581
func (pl *Payload) BuildMessage() ([]byte, error) {
	plBuf, err := pl.Encode()
	if err != nil {
		return nil, fmt.Errorf("unable to encode payload: %s", err)
	}

	meta := &Meta{Size: uint32(len(plBuf))}
	metaBuf, err := meta.MarshalBinary()
	if err != nil {
		return nil, fmt.Errorf("unable to encode metadata: %s", err)
	}

	return append(metaBuf, plBuf...), nil
}
1208121
func NewBytesBytesPair(first []byte, second []byte) *BytesBytesPair {
	return &BytesBytesPair{
		First:  first,
		Second: second,
	}
}