implement filter codec

This commit is contained in:
2025-08-26 18:26:34 +01:00
parent c958a7d9ed
commit 1ba2bb0a9b
47 changed files with 687 additions and 19133 deletions

View File

@@ -1,71 +0,0 @@
package bufpool
import (
"testing"
)
func TestBufferPoolGetPut(t *testing.T) {
// Get a buffer from the pool
buf1 := Get()
// Verify the buffer is the correct size
if len(*buf1) != BufferSize {
t.Errorf("Expected buffer size of %d, got %d", BufferSize, len(*buf1))
}
// Write some data to the buffer
(*buf1)[0] = 42
// Return the buffer to the pool
Put(buf1)
// Get another buffer, which should be the same one we just returned
buf2 := Get()
// Buffer may or may not be cleared, but we should be able to use it
// Let's check if we have the expected buffer size
if len(*buf2) != BufferSize {
t.Errorf("Expected buffer size of %d, got %d", BufferSize, len(*buf2))
}
}
func TestMultipleBuffers(t *testing.T) {
// Get multiple buffers at once to ensure the pool can handle it
const numBuffers = 10
buffers := make([]B, numBuffers)
// Get buffers from the pool
for i := 0; i < numBuffers; i++ {
buffers[i] = Get()
// Verify each buffer is the correct size
if len(*buffers[i]) != BufferSize {
t.Errorf(
"Buffer %d: Expected size of %d, got %d", i, BufferSize,
len(*buffers[i]),
)
}
}
// Return all buffers to the pool
for i := 0; i < numBuffers; i++ {
Put(buffers[i])
}
}
func BenchmarkGetPut(b *testing.B) {
for i := 0; i < b.N; i++ {
buf := Get()
Put(buf)
}
}
func BenchmarkGetPutParallel(b *testing.B) {
b.RunParallel(
func(pb *testing.PB) {
for pb.Next() {
buf := Get()
Put(buf)
}
},
)
}

View File

@@ -0,0 +1,23 @@
package pointers
import (
"time"
"next.orly.dev/pkg/encoders/timestamp"
)
// PointerToValue is a generic interface (type constraint) to refer to any
// pointer to almost any kind of common type of value.
//
// see the utils/values package for a set of methods to accept these values and
// return the correct type pointer to them.
type PointerToValue interface {
~*uint | ~*int | ~*uint8 | ~*uint16 | ~*uint32 | ~*uint64 | ~*int8 | ~*int16 | ~*int32 |
~*int64 | ~*float32 | ~*float64 | ~*string | ~*[]string | ~*time.Time | ~*time.Duration |
~*[]byte | ~*[][]byte | ~*timestamp.T
}
// Present determines whether there is a value for a PointerToValue type.
func Present[V PointerToValue](i V) bool {
return i != nil
}

View File

@@ -0,0 +1,95 @@
package values
import (
"time"
)
// ToUintPointer returns a pointer to the uint value passed in.
func ToUintPointer(v uint) *uint {
return &v
}
// ToIntPointer returns a pointer to the int value passed in.
func ToIntPointer(v int) *int {
return &v
}
// ToUint8Pointer returns a pointer to the uint8 value passed in.
func ToUint8Pointer(v uint8) *uint8 {
return &v
}
// ToUint16Pointer returns a pointer to the uint16 value passed in.
func ToUint16Pointer(v uint16) *uint16 {
return &v
}
// ToUint32Pointer returns a pointer to the uint32 value passed in.
func ToUint32Pointer(v uint32) *uint32 {
return &v
}
// ToUint64Pointer returns a pointer to the uint64 value passed in.
func ToUint64Pointer(v uint64) *uint64 {
return &v
}
// ToInt8Pointer returns a pointer to the int8 value passed in.
func ToInt8Pointer(v int8) *int8 {
return &v
}
// ToInt16Pointer returns a pointer to the int16 value passed in.
func ToInt16Pointer(v int16) *int16 {
return &v
}
// ToInt32Pointer returns a pointer to the int32 value passed in.
func ToInt32Pointer(v int32) *int32 {
return &v
}
// ToInt64Pointer returns a pointer to the int64 value passed in.
func ToInt64Pointer(v int64) *int64 {
return &v
}
// ToFloat32Pointer returns a pointer to the float32 value passed in.
func ToFloat32Pointer(v float32) *float32 {
return &v
}
// ToFloat64Pointer returns a pointer to the float64 value passed in.
func ToFloat64Pointer(v float64) *float64 {
return &v
}
// ToStringPointer returns a pointer to the string value passed in.
func ToStringPointer(v string) *string {
return &v
}
// ToStringSlicePointer returns a pointer to the []string value passed in.
func ToStringSlicePointer(v []string) *[]string {
return &v
}
// ToTimePointer returns a pointer to the time.Time value passed in.
func ToTimePointer(v time.Time) *time.Time {
return &v
}
// ToDurationPointer returns a pointer to the time.Duration value passed in.
func ToDurationPointer(v time.Duration) *time.Duration {
return &v
}
// ToBytesPointer returns a pointer to the []byte value passed in.
func ToBytesPointer(v []byte) *[]byte {
return &v
}
// ToByteSlicesPointer returns a pointer to the [][]byte value passed in.
func ToByteSlicesPointer(v [][]byte) *[][]byte {
return &v
}