Skip to content

Commit c4fee1d

Browse files
committed
refactoring. Moved the data processing packages to the lib directory, the interface and json compression package remained in the root directory.
1 parent 892fb3b commit c4fee1d

9 files changed

Lines changed: 22 additions & 19 deletions

File tree

base64.go renamed to lib/base64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compressjson
1+
package lib
22

33
import "encoding/base64"
44

base64_test.go renamed to lib/base64_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compressjson
1+
package lib
22

33
import (
44
"encoding/base64"

help_test.go renamed to lib/help_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compressjson
1+
package lib
22

33
import "time"
44

json.go renamed to lib/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compressjson
1+
package lib
22

33
import "github.com/goccy/go-json"
44

json_test.go renamed to lib/json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compressjson
1+
package lib
22

33
import (
44
"testing"

zstd.go renamed to lib/zstd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compressjson
1+
package lib
22

33
import (
44
"github.com/klauspost/compress/zstd"
@@ -18,13 +18,13 @@ var (
1818

1919
// ZSTDTranscoder provides zero-allocation, high-throughput Zstandard compression and decompression
2020
// by reusing globally pre-configured encoder and decoder instances.
21-
// It has no internal state all heavy lifting is done by the shared, thread-safe global objects.
21+
// It has no internal state - all heavy lifting is done by the shared, thread-safe global objects.
2222
// This design eliminates per-instance initialization overhead and maximizes performance
2323
// in hot paths (caching, messaging, logging, etc.) while remaining safe for concurrent use.
2424
type ZSTDTranscoder struct{}
2525

2626
// NewZSTDTranscoder returns a lightweight transcoder instance that operates on the global
27-
// pre-initialized encoder and decoder. No allocation or setup is performed the instance
27+
// pre-initialized encoder and decoder. No allocation or setup is performed - the instance
2828
// is immediately ready for use and can be safely shared across the entire application.
2929
func NewZSTDTranscoder() *ZSTDTranscoder {
3030
return &ZSTDTranscoder{}
@@ -33,7 +33,7 @@ func NewZSTDTranscoder() *ZSTDTranscoder {
3333
// Compress compresses the input data in a single fast operation using the shared global encoder.
3434
// It uses EncodeAll which is optimized for complete in-memory buffers and produces
3535
// a fully framed, independently decompression output.
36-
// The result is allocated once and returned no internal buffers are reused.
36+
// The result is allocated once and returned - no internal buffers are reused.
3737
func (t *ZSTDTranscoder) Compress(src []byte) ([]byte, error) {
3838
// EncodeAll appends to the provided dest buffer; we pass a zero-length slice with capacity
3939
// to avoid extra allocations while still getting a fresh result slice.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compressjson
1+
package lib
22

33
import (
44
"testing"

zstd_test.go renamed to lib/zstd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package compressjson
1+
package lib
22

33
import (
44
"strings"

transcoder.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
package compressjson
22

3-
import "errors"
3+
import (
4+
"errors"
5+
6+
"github.com/spacemagneto/compressjson/lib"
7+
)
48

59
// transcoder is a concrete, high-performance implementation of transcoder[T]
610
// designed for low-latency, high-throughput scenarios. It is safe for concurrent use
711
// by multiple goroutines and reuses internal buffers and native resources across calls.
8-
//
912
// Call Close when the transcoder is no longer needed to free memory.
1013
type transcoder[T any] struct {
11-
jsonTranscoder *JSONTranscoder[T]
12-
standardTranscoder *ZSTDTranscoder
13-
binaryTranscoder *Base64Transcoder
14+
jsonTranscoder *lib.JSONTranscoder[T]
15+
standardTranscoder *lib.ZSTDTranscoder
16+
binaryTranscoder *lib.Base64Transcoder
1417
}
1518

1619
// NewTranscoder creates a ready-to-use transcoder for type T.
1720
// All internal components are initialized once and reused forever.
1821
// The returned value satisfies Transcoder[T] and can be shared globally.
1922
func NewTranscoder[T any]() Transcoder[T] {
2023
return &transcoder[T]{
21-
jsonTranscoder: NewJSONTranscoder[T](),
22-
standardTranscoder: NewZSTDTranscoder(),
23-
binaryTranscoder: NewBase64Transcoder(),
24+
jsonTranscoder: lib.NewJSONTranscoder[T](),
25+
standardTranscoder: lib.NewZSTDTranscoder(),
26+
binaryTranscoder: lib.NewBase64Transcoder(),
2427
}
2528
}
2629

0 commit comments

Comments
 (0)