diff --git a/pdu/bufpool.go b/pdu/bufpool.go index c50d947..5a7435b 100644 --- a/pdu/bufpool.go +++ b/pdu/bufpool.go @@ -15,7 +15,7 @@ func NewBufferPoolManager() *BufferPoolManager { } } -func (bpm *BufferPoolManager) GetBuffer(size uint) *[]uint8 { +func (bpm *BufferPoolManager) Get(size uint) *[]uint8 { bpm.mu.RLock() pool, exists := bpm.pools[size] bpm.mu.RUnlock() @@ -39,7 +39,7 @@ func (bpm *BufferPoolManager) GetBuffer(size uint) *[]uint8 { return pool.Get().(*[]uint8) } -func (bpm *BufferPoolManager) PutBuffer(buf *[]uint8) { +func (bpm *BufferPoolManager) Put(buf *[]uint8) { size := uint(len(*buf)) bpm.mu.RLock() pool, exists := bpm.pools[size] diff --git a/pdu/bufpool_test.go b/pdu/bufpool_test.go index db5c229..fbe9ca0 100644 --- a/pdu/bufpool_test.go +++ b/pdu/bufpool_test.go @@ -9,7 +9,7 @@ func TestRetrieveBufferOfRequestedSize(t *testing.T) { bpm := NewBufferPoolManager() size := 1024 - buffer := bpm.GetBuffer(uint(size)) + buffer := bpm.Get(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -24,7 +24,7 @@ func TestRequestBufferSizeZero(t *testing.T) { bpm := NewBufferPoolManager() size := 0 - buffer := bpm.GetBuffer(uint(size)) + buffer := bpm.Get(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -46,7 +46,7 @@ func TestConcurrentAccessToBufferPool(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - buffer := bpm.GetBuffer(uint(size)) + buffer := bpm.Get(uint(size)) if buffer == nil { t.Errorf("Expected buffer, got nil") } @@ -63,7 +63,7 @@ func TestGetBufferLockUnlock(t *testing.T) { bpm := NewBufferPoolManager() size := 1024 - buffer := bpm.GetBuffer(uint(size)) + buffer := bpm.Get(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -78,7 +78,7 @@ func TestVerifyPoolCreationForNewSizes(t *testing.T) { bpm := NewBufferPoolManager() size := 512 - buffer := bpm.GetBuffer(uint(size)) + buffer := bpm.Get(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -93,7 +93,7 @@ func TestBufferPoolManagerGetBuffer(t *testing.T) { bpm := NewBufferPoolManager() size := 1024 - buffer := bpm.GetBuffer(uint(size)) + buffer := bpm.Get(uint(size)) if buffer == nil { t.Fatalf("Expected buffer, got nil") @@ -109,7 +109,7 @@ func TestGetBufferWithMultipleSizes(t *testing.T) { sizes := []int{512, 1024, 2048} for _, size := range sizes { - buffer := bpm.GetBuffer(uint(size)) + buffer := bpm.Get(uint(size)) if buffer == nil { t.Fatalf("Expected buffer for size %d, got nil", size) @@ -124,9 +124,9 @@ func TestGetBufferWithMultipleSizes(t *testing.T) { func TestGetBufferIsAlwaysZero(t *testing.T) { bpm := NewBufferPoolManager() - var size uint = 1024*64 + var size uint = 1024 * 64 for i := 0; i < 1000; i++ { - buffer := bpm.GetBuffer(size) + buffer := bpm.Get(size) if buffer == nil { t.Fatalf("Expected buffer for size %d, got nil", size) @@ -142,6 +142,6 @@ func TestGetBufferIsAlwaysZero(t *testing.T) { } } - bpm.PutBuffer(buffer) + bpm.Put(buffer) } } diff --git a/pdu/pdu.go b/pdu/pdu.go index 1cef575..e53eb57 100644 --- a/pdu/pdu.go +++ b/pdu/pdu.go @@ -25,6 +25,7 @@ type ( header PDU_HEADER } ) + // Hmm the header can be partially encoded // As in command_status can just be null // So not 0s, null, non existent, not encoded @@ -56,9 +57,8 @@ type ( // What are the other 0s? // Don't know - func (p *PDU_HEADER) Encode() (*[]uint8, error) { - buf := ByteBufferPool.GetBuffer(uint(p.Size())) + buf := ByteBufferPool.Get(uint(p.Size())) err := p.EncodeInto(buf) return buf, err } diff --git a/pdu/submit.go b/pdu/submit.go index 3f380ce..9d37663 100644 --- a/pdu/submit.go +++ b/pdu/submit.go @@ -61,7 +61,7 @@ type ( ) func (p *SUBMIT_SM) Encode() (*[]byte, error) { - buf := ByteBufferPool.GetBuffer(uint(p.Size())) + buf := ByteBufferPool.Get(uint(p.Size())) err := p.EncodeInto(buf) return buf, err }