//ToBytes creates a packet buffer and converts it into a complete packet with ethernet, IP and TCP (with options)
169696
func (p *Packet) ToBytes() ([]byte, error) {

	opts := gopacket.SerializeOptions{
		FixLengths:       true, //fix lengths based on the payload (data)
		ComputeChecksums: true, //compute checksum based on the payload during serialization
	}

	if err := p.tcpLayer.SetNetworkLayerForChecksum(p.ipLayer); err != nil {
		return nil, fmt.Errorf("unable to compute checksum: %s", err)
	}

	//Creating a packet buffer by serializing the ethernet, IP and TCP layers/packets
	packetBuf := gopacket.NewSerializeBuffer()
	tcpPayload := gopacket.Payload(p.tcpLayer.Payload)
	if err := gopacket.SerializeLayers(packetBuf, opts, p.ethernetLayer, p.ipLayer, p.tcpLayer, tcpPayload); err != nil {
		return nil, fmt.Errorf("unable to serialize layers: %s", err)
	}
	//Converting into bytes and removing the ethernet from the layers
	bytes := packetBuf.Bytes()
	bytesWithoutEthernet := bytes[14:]

	var finalBytes []byte
	finalBytes = append(finalBytes, bytesWithoutEthernet...)

	return finalBytes, nil
}
1317005
func ToBytesMsgChan(ch chan *client.ConsumerMessage, opts ...interface{}) func(*client.ConsumerMessage) {

	timeout, logger := messaging.ParseOpts(opts...)

	return func(msg *client.ConsumerMessage) {
		select {
		case ch <- msg:
		case <-time.After(timeout):
			logger.Warn("Unable to deliver message")
		}
	}
}
1124670
func (b *Bitset) AppendBytes(data []byte) {
	for _, d := range data {
		b.AppendByte(d, 8)
	}
}
662430
func (addr I2PAddr) ToBytes() ([]byte, error) {
	buf := make([]byte, i2pB64enc.DecodedLen(len(addr)))
	if _, err := i2pB64enc.Decode(buf, []byte(addr)); err != nil {
		return buf, errors.New("Address is not base64-encoded")
	}
	return buf, nil
}
872988
func (pool *ByteSlicePool) decodeBytes(b PacketReader) []byte {
	fieldLength := decodeUint16(b)
	field := pool.getByteSlice(int(fieldLength))
	b.Read(field)
	return field
}
1089667
func (p Ping) Bytes() []byte {
	data, _ := json2.Marshal(p)
	return data
}
998338
func ToBytes(val interface{}) ([]byte, error) {
	switch val.(type) {
	case string:
		return []byte(val.(string)), nil
	case []byte:
		b := make([]byte, len(val.([]byte)))
		copy(b, val.([]byte))
		return b, nil
	default:
		return json.Marshal(val)
	}
}
147104
func (c *Cache) GetBytes(key string) (value []byte, ok bool) {
	v, ok := c.Get(key)
	if !ok {
		return nil, false
	}
	return v.([]byte), true
}
345063
func (p Packet) ValueBytes() [][]byte {
	b := make([][]byte, len(p.DataTypes))
	for i := range b {
		b[i] = p.Bytes[i*8 : 8+(i*8)]
	}
	return b
}
1025221
func (h Headers) Bytes() []byte {
	b := make([]byte, 0, 1024)
	for i := 0; i < len(h); i += 2 {
		b = append(b, h[i]+":"+h[i+1]+"\n"...)
	}
	return b
}
181048
func ToBytes(s string) []byte {
	if len(s) == 0 {
		return []byte{}
	}
	return Pad(append([]byte(s), 0))
}
1132544
func (mmap MarshalMap) Bytes(key string) ([]byte, error) {
	val, exists := mmap.Value(key)
	if !exists {
		return []byte{}, fmt.Errorf(`"%s" is not set`, key)
	}

	bytesValue, isBytes := val.([]byte)
	if !isBytes {
		return []byte{}, fmt.Errorf(`"%s" is expected to be a []byte`, key)
	}
	return bytesValue, nil
}
414722
func ToBytes(keys string) ([]byte, error) {
	codes := []byte{}
next:
	for _, key := range strings.Split(keys, ",") {
		if len(key) != 1 {
			for code, ctrl := range ASCII {
				if ctrl == key {
					codes = append(codes, byte(code))
					continue next
				}
			}
			if key == "DEL" {
				codes = append(codes, 127)
			} else {
				return nil, fmt.Errorf("Unknown character: '%s'", key)
			}
		} else {
			codes = append(codes, key[0])
		}
	}
	return codes, nil
}
369032
func ToBytesProducerChan(ch chan *client.ProducerMessage, opts ...interface{}) func(*client.ProducerMessage) {

	timeout, logger := messaging.ParseOpts(opts...)

	return func(msg *client.ProducerMessage) {
		select {
		case ch <- msg:
		case <-time.After(timeout):
			logger.Warn("Unable to deliver message")
		}
	}
}
706981
func (soc *Socket) RecvMessageBytes(flags Flag) (msg [][]byte, err error) {
	msg = make([][]byte, 0)
	for {
		b, e := soc.RecvBytes(flags)
		if e == nil {
			msg = append(msg, b)
		} else {
			return msg[0:0], e
		}
		more, e := soc.GetRcvmore()
		if e == nil {
			if !more {
				break
			}
		} else {
			return msg[0:0], e
		}
	}
	return
}
1003453
func (c *Conn) ReadBytes(delim byte) ([]byte, error) {
	var line []byte
	for {
		b, err := c.ReadByte()
		if err != nil {
			return nil, err
		}
		line = append(line, b)
		if b == delim {
			break
		}
	}
	return line, nil
}
635769
func (cs *ConnStats) AvgRPCBytes() (send float64, recv float64) {
	return float64(cs.BytesWritten) / float64(cs.RPCCalls), float64(cs.BytesRead) / float64(cs.RPCCalls)
}