func (w *UDPWriter) writeChunked(zBytes []byte) (err error) {
	b := make([]byte, 0, w.config.ChunkSize)
	buf := bytes.NewBuffer(b)
	nChunksI := numChunks(zBytes, w.config.ChunkSize)
	if nChunksI > 255 {
		return fmt.Errorf("msg too large, would need %d chunks", nChunksI)
	}
	nChunks := uint8(nChunksI)
	// use urandom to get a unique message id
	msgId := make([]byte, 8)
	n, err := io.ReadFull(rand.Reader, msgId)
	if err != nil || n != 8 {
		return fmt.Errorf("rand.Reader: %d/%s", n, err)
	}

	bytesLeft := len(zBytes)
	for i := uint8(0); i < nChunks; i++ {
		buf.Reset()
		// manually write header.  Don't care about
		// host/network byte order, because the spec only
		// deals in individual bytes.
		buf.Write(magicChunked) //magic
		buf.Write(msgId)
		buf.WriteByte(i)
		buf.WriteByte(nChunks)
		// slice out our chunk from zBytes
		chunkLen := (w.config.ChunkSize - chunkedHeaderLen)
		if chunkLen > bytesLeft {
			chunkLen = bytesLeft
		}
		off := int(i) * (w.config.ChunkSize - chunkedHeaderLen)
		chunk := zBytes[off : off+chunkLen]
		buf.Write(chunk)

		// write this chunk, and make sure the write was good
		n, err := w.conn.Write(buf.Bytes())
		if err != nil {
			return fmt.Errorf("Write (chunk %d/%d): %s", i,
				nChunks, err)
		}
		if n != len(buf.Bytes()) {
			return fmt.Errorf("Write len: (chunk %d/%d) (%d/%d)",
				i, nChunks, n, len(buf.Bytes()))
		}

		bytesLeft -= chunkLen
	}

	if bytesLeft != 0 {
		return fmt.Errorf("error: %d bytes left after sending", bytesLeft)
	}
	return nil
}
// writes the gzip compressed byte array to the connection as a series
// of GELF chunked messages.  The header format is documented at
// https://github.com/Graylog2/graylog2-docs/wiki/GELF as:
//
//     2-byte magic (0x1e 0x0f), 8 byte id, 1 byte sequence id, 1 byte
//     total, chunk-data
writes the gzip compressed byte array to the connection as a series
of GELF chunked messages.

2-byte magic (0x1e 0x0f), 8 byte id, 1 byte sequence id, 1 byte
total, chunk-data
// writes the gzip compressed byte array to the connection as a series // of GELF chunked messages . The header format is documented at // https : // github . com / Graylog2 / graylog2 - docs / wiki / GELF as : // // 2 - byte magic ( 0x1e 0x0f ) 8 byte id 1 byte sequence id 1 byte // total chunk - data
func (w *UDPWriter) writeChunked(zBytes []byte) (err error) {
	b := make([]byte, 0, w.config.ChunkSize)
	buf := bytes.NewBuffer(b)
	nChunksI := numChunks(zBytes, w.config.ChunkSize)
	if nChunksI > 255 {
		return fmt.Errorf("msg too large, would need %d chunks", nChunksI)
	}
	nChunks := uint8(nChunksI)
	msgId := make([]byte, 8)
	n, err := io.ReadFull(rand.Reader, msgId)
	if err != nil || n != 8 {
		return fmt.Errorf("rand.Reader: %d/%s", n, err)
	}
	bytesLeft := len(zBytes)
	for i := uint8(0); i < nChunks; i++ {
		buf.Reset()
		buf.Write(magicChunked) 
		buf.Write(msgId)
		buf.WriteByte(i)
		buf.WriteByte(nChunks)
		chunkLen := (w.config.ChunkSize - chunkedHeaderLen)
		if chunkLen > bytesLeft {
			chunkLen = bytesLeft
		}
		off := int(i) * (w.config.ChunkSize - chunkedHeaderLen)
		chunk := zBytes[off : off+chunkLen]
		buf.Write(chunk)
		n, err := w.conn.Write(buf.Bytes())
		if err != nil {
			return fmt.Errorf("Write (chunk %d/%d): %s", i,
				nChunks, err)
		}
		if n != len(buf.Bytes()) {
			return fmt.Errorf("Write len: (chunk %d/%d) (%d/%d)",
				i, nChunks, n, len(buf.Bytes()))
		}
		bytesLeft -= chunkLen
	}
	if bytesLeft != 0 {
		return fmt.Errorf("error: %d bytes left after sending", bytesLeft)
	}
	return nil
}
func ( w * UDPWriter ) writeChunked ( zBytes [ ] byte ) ( err error ) { b := make ( [ ] byte , 0 , w . config . ChunkSize ) buf := bytes . NewBuffer ( b ) nChunksI := numChunks ( zBytes , w . config . ChunkSize ) if nChunksI > 255 { return fmt . Errorf ( " " , nChunksI ) } nChunks := uint8 ( nChunksI ) msgId := make ( [ ] byte , 8 ) n , err := io . ReadFull ( rand . Reader , msgId ) if err != nil || n != 8 { return fmt . Errorf ( " " , n , err ) } bytesLeft := len ( zBytes ) for i := uint8 ( 0 ) ; i < nChunks ; i ++ { buf . Reset ( ) buf . Write ( magicChunked ) buf . Write ( msgId ) buf . WriteByte ( i ) buf . WriteByte ( nChunks ) chunkLen := ( w . config . ChunkSize - chunkedHeaderLen ) if chunkLen > bytesLeft { chunkLen = bytesLeft } off := int ( i ) * ( w . config . ChunkSize - chunkedHeaderLen ) chunk := zBytes [ off : off + chunkLen ] buf . Write ( chunk ) n , err := w . conn . Write ( buf . Bytes ( ) ) if err != nil { return fmt . Errorf ( " " , i , nChunks , err ) } if n != len ( buf . Bytes ( ) ) { return fmt . Errorf ( " " , i , nChunks , n , len ( buf . Bytes ( ) ) ) } bytesLeft -= chunkLen } if bytesLeft != 0 { return fmt . Errorf ( " " , bytesLeft ) } return nil }
writes the gzip compressed byte array to the connection as a series
of GELF chunked messages.
writes the gzip compressed byte array to the connection as a series of GELF chunked messages .
// use urandom to get a unique message id // manually write header.  Don't care about // host/network byte order, because the spec only // deals in individual bytes. //magic // slice out our chunk from zBytes // write this chunk, and make sure the write was good