// messageToHex serializes a message to the wire protocol encoding using the
// latest protocol version and returns a hex-encoded string of the result.
179840
func messageToHex(msg wire.Message) (string, error) {
	var buf bytes.Buffer
	if err := msg.BtcEncode(&buf, maxProtocolVersion, wire.WitnessEncoding); err != nil {
		context := fmt.Sprintf("Failed to encode msg of type %T", msg)
		return "", internalRPCError(err.Error(), context)
	}

	return hex.EncodeToString(buf.Bytes()), nil
}
395921
func (m *SMTPMessage) Bytes() io.Reader {
	var b = new(bytes.Buffer)

	b.WriteString("HELO:<" + m.Helo + ">\r\n")
	b.WriteString("FROM:<" + m.From + ">\r\n")
	for _, t := range m.To {
		b.WriteString("TO:<" + t + ">\r\n")
	}
	b.WriteString("\r\n")
	b.WriteString(m.Data)

	return b
}
20591
func ToHex(b []byte) string {
	hex := Bytes2Hex(b)
	if len(hex) == 0 {
		hex = "0"
	}
	return "0x" + hex
}
269910
func RgbToHex(r, g, b uint8) C.uint32_t {
	return C.color_rgb_to_hex(C.uint8_t(r), C.uint8_t(g), C.uint8_t(b))
}
1074629
func (t TraceID) ToHex() string {
	if t.High == 0 {
		return fmt.Sprintf("%016x", t.Low)
	}
	return fmt.Sprintf("%016x%016x", t.High, t.Low)
}
125271
func (m *Message) WriteTo(w io.Writer) (int64, error) {

	total, err := m.Header.WriteTo(w)
	if err != nil {
		return total, err
	}

	mediaType, mediaTypeParams, err := m.Header.ContentType()
	if err != nil && err != ErrHeadersMissingField {
		return total, err
	}
	hasParts := strings.HasPrefix(mediaType, "multipart")
	hasSubMessage := strings.HasPrefix(mediaType, "message")

	if !hasParts && !hasSubMessage {
		return m.writeBody(w, total)
	}

	written, err := io.WriteString(w, "\r\n")
	total += int64(written)
	if err != nil {
		return total, err
	}

	if hasSubMessage {
		written2, err := m.SubMessage.WriteTo(w)
		return total + written2, err

	}
	// hasParts
	return m.writeParts(w, mediaTypeParams["boundary"], total)
}
1039947
func Sign(message string, pm string) string {
	key := ExtractKeyFromPem(pm)
	byta := []byte(message)
	hash := sha256.New()
	hash.Write(byta)
	bytb := hash.Sum(nil)
	sig, _ := key.Sign(bytb)
	ser := sig.Serialize()
	hexa := hex.EncodeToString(ser)
	return hexa
}
454474
func (m *ChannelDeMultiplexer) DeMultiplex(msg interface{}) {
	m.lock.RLock()
	defer m.lock.RUnlock()
	if m.isClosed() {
		return
	}
	for _, ch := range m.channels {
		if ch.pred(msg) {
			ch.ch <- msg
		}
	}
}
832871
func (r *Response) Message(msg string) JResponseWriter {
	return r.Field(fieldMsg, msg)
}
875153
func txHexString(tx *wire.MsgTx) string {
	buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
	// Ignore Serialize's error, as writing to a bytes.buffer cannot fail.
	tx.Serialize(buf)
	return hex.EncodeToString(buf.Bytes())
}
896243
func ParseHex(s string) (Hex, error) {
	var err error
	s, err = uniformHexStrLit(s)
	if err != nil {
		return Hex{}, errors.Trace(err)
	}
	n, err := strconv.ParseInt(s, 0, 64)
	if err != nil {
		return Hex{}, errors.Trace(err)
	}

	return Hex{Value: n}, nil
}
443432
func (m *Message) Bytes() ([]byte, error) {
	buffer := &bytes.Buffer{}
	_, err := m.WriteTo(buffer)
	return buffer.Bytes(), err
}
743057
func (event *Event) MessageType() (msgtype string, ok bool) {
	value, exists := event.Content["msgtype"]
	if !exists {
		return
	}
	msgtype, ok = value.(string)
	return
}
953128
func (msg Message) WriteTo(w io.Writer) (int64, error) {
	var bytesWritten int

	nw, err := fmt.Fprintf(w, "%s%s", msg.Address, msg.Typetags())
	if err != nil {
		return 0, err
	}
	bytesWritten += nw

	for _, a := range msg.Arguments {
		nw, err := a.WriteTo(w)
		if err != nil {
			return 0, err
		}
		bytesWritten += int(nw)
	}

	return int64(bytesWritten), nil
}
406578
func (m *Message) Bytes() ([]byte, error) {
	if m.nlm == nil {
		return nil, errors.New("no netlink message")
	}
	nlh := C.nlmsg_hdr(m.nlm)
	nlb := make([]byte, nlh.nlmsg_len)
	copy(nlb, (*[1 << 20]byte)(unsafe.Pointer(nlh))[:nlh.nlmsg_len])
	return nlb, nil
}
94465
func MessageName(x Message) string {
	type xname interface {
		XXX_MessageName() string
	}
	if m, ok := x.(xname); ok {
		return m.XXX_MessageName()
	}
	return revProtoTypes[reflect.TypeOf(x)]
}
80085
func Encode(t MessageType, msg interface{}) ([]byte, error) {
	var buf bytes.Buffer
	buf.WriteByte(uint8(t))
	err := codec.NewEncoder(&buf, msgpackHandle).Encode(msg)
	return buf.Bytes(), err
}