From c73a6066c4067d81cefbe94fe07772757d2eccb1 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave <> Date: Tue, 23 Jul 2024 09:31:26 +0200 Subject: [PATCH] Fix pool to uint from int --- pdu/bufpool_test.go | 28 ++++++++++++++-------------- pdu/global.go | 2 +- pdu/pdu.go | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pdu/bufpool_test.go b/pdu/bufpool_test.go index 22d5e3a..9ed5f82 100644 --- a/pdu/bufpool_test.go +++ b/pdu/bufpool_test.go @@ -7,12 +7,12 @@ import ( func TestRetrieveBufferOfRequestedSize(t *testing.T) { bpm := &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), mu: sync.Mutex{}, } size := 1024 - buffer := bpm.GetBuffer(size) + buffer := bpm.GetBuffer(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -25,12 +25,12 @@ func TestRetrieveBufferOfRequestedSize(t *testing.T) { func TestRequestBufferSizeZero(t *testing.T) { bpm := &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), mu: sync.Mutex{}, } size := 0 - buffer := bpm.GetBuffer(size) + buffer := bpm.GetBuffer(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -43,7 +43,7 @@ func TestRequestBufferSizeZero(t *testing.T) { func TestConcurrentAccessToBufferPool(t *testing.T) { bpm := &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), mu: sync.Mutex{}, } @@ -55,7 +55,7 @@ func TestConcurrentAccessToBufferPool(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - buffer := bpm.GetBuffer(size) + buffer := bpm.GetBuffer(uint(size)) if buffer == nil { t.Errorf("Expected buffer, got nil") } @@ -70,12 +70,12 @@ func TestConcurrentAccessToBufferPool(t *testing.T) { func TestGetBufferLockUnlock(t *testing.T) { bpm := &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), mu: sync.Mutex{}, } size := 1024 - buffer := bpm.GetBuffer(size) + buffer := bpm.GetBuffer(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -88,12 +88,12 @@ func TestGetBufferLockUnlock(t *testing.T) { func TestVerifyPoolCreationForNewSizes(t *testing.T) { bpm := &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), mu: sync.Mutex{}, } size := 512 - buffer := bpm.GetBuffer(size) + buffer := bpm.GetBuffer(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -106,12 +106,12 @@ func TestVerifyPoolCreationForNewSizes(t *testing.T) { func TestBufferPoolManagerGetBuffer(t *testing.T) { bpm := &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), mu: sync.Mutex{}, } size := 1024 - buffer := bpm.GetBuffer(size) + buffer := bpm.GetBuffer(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -124,13 +124,13 @@ func TestBufferPoolManagerGetBuffer(t *testing.T) { func TestGetBufferWithMultipleSizes(t *testing.T) { bpm := &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), mu: sync.Mutex{}, } sizes := []int{512, 1024, 2048} for _, size := range sizes { - buffer := bpm.GetBuffer(size) + buffer := bpm.GetBuffer(uint(size)) if buffer == nil { t.Fatalf("Expected buffer for size %d, got nil", size) diff --git a/pdu/global.go b/pdu/global.go index 65c7b8e..6203035 100644 --- a/pdu/global.go +++ b/pdu/global.go @@ -3,6 +3,6 @@ package pdu import "sync" var ByteBufferPool = &BufferPoolManager{ - pools: make(map[int]*sync.Pool), + pools: make(map[uint]*sync.Pool), mu: sync.Mutex{}, } diff --git a/pdu/pdu.go b/pdu/pdu.go index 3928bec..47fd6a5 100644 --- a/pdu/pdu.go +++ b/pdu/pdu.go @@ -27,7 +27,7 @@ type ( ) func (p *PDU_HEADER) Encode() (*[]uint8, error) { - buf := ByteBufferPool.GetBuffer(int(p.Size())) + buf := ByteBufferPool.GetBuffer(uint(p.Size())) err := p.EncodeInto(buf) return buf, err }