diff options
| author | Shulhan <ms@kilabit.info> | 2018-04-01 05:01:02 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-04-01 05:01:02 +0700 |
| commit | 3987f51dda643f770729ac39729def7d64ebb9f9 (patch) | |
| tree | 0b20f329efc1972fe76dfda3de03de4af9ad9587 /udppacket.go | |
| download | haminer-3987f51dda643f770729ac39729def7d64ebb9f9.tar.xz | |
haminer: Library and program to parse and forward HAProxy logs
Diffstat (limited to 'udppacket.go')
| -rw-r--r-- | udppacket.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/udppacket.go b/udppacket.go new file mode 100644 index 0000000..c7b017b --- /dev/null +++ b/udppacket.go @@ -0,0 +1,41 @@ +// Copyright 2018, M. Shulhan (ms@kilabit.info). All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package haminer + +const ( + defSize = 1024 +) + +// +// UDPPacket wrap the slice of bytes for easy manipulation. +// +type UDPPacket struct { + Bytes []byte +} + +// +// NewUDPPacket will create and initialize UDP packet. +// +func NewUDPPacket(size uint32) (p *UDPPacket) { + if size <= 0 { + size = defSize + } + p = &UDPPacket{ + Bytes: make([]byte, size), + } + + return +} + +// +// Reset will set the content of packet data to zero, so it can be used agains +// on Read(). +// +func (p *UDPPacket) Reset() { + p.Bytes[0] = 0 + for x := 1; x < len(p.Bytes); x *= 2 { + copy(p.Bytes[x:], p.Bytes[:x]) + } +} |
