From d769cfe466e2a5f96d396f91f6000c4fc604d836 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 16 Aug 2022 23:21:43 +0700 Subject: all: use fixed []byte for consuming UDP packet Instead of using struct UDPPacket to read UDP packet from HAproxy log, simplify it by using fixed, reusable size of []byte directly. --- udppacket.go | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 udppacket.go (limited to 'udppacket.go') diff --git a/udppacket.go b/udppacket.go deleted file mode 100644 index fd52a61..0000000 --- a/udppacket.go +++ /dev/null @@ -1,35 +0,0 @@ -// 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 -// against 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]) - } -} -- cgit v1.3