Skip to content

More custom codecs#94

Merged
ksysoev merged 5 commits into
mainfrom
more_custom_codecs
Jul 1, 2026
Merged

More custom codecs#94
ksysoev merged 5 commits into
mainfrom
more_custom_codecs

Conversation

@ksysoev

@ksysoev ksysoev commented Jul 1, 2026

Copy link
Copy Markdown
Owner

This pull request refactors the codec implementation to support multiple serialization formats and organizes codecs into their own packages. It removes the built-in JSON codec from the main package, introduces a modular codec structure for JSON, BSON, Gob, and MessagePack, and adds comprehensive tests for each codec. The changes improve extensibility and maintainability, making it easier to add or swap codecs.

Codec modularization and new codec support:

  • Moved the JSON codec implementation from the main anycache package into a new codec/json package, updating all usages and tests accordingly. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Added new codec packages: codec/bson for BSON encoding/decoding (MongoDB), codec/gob for Go's native Gob encoding, and codec/msgpack for MessagePack serialization, each with their own implementation and test files. [1] [2] [3] [4] [5] [6]

Code cleanup and refactoring:

  • Removed the original JSONCodec implementation from the main codec.go file, leaving only the Codec interface definition.
  • Renamed the original codec test file to codec/json/json_test.go and updated it to use the new package structure.

Dependency updates:

  • Added dependencies for BSON and MessagePack codecs in go.mod, and updated the klauspost/compress dependency version. [1] [2]

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.20%. Comparing base (060a63c) to head (01e08d1).

Files with missing lines Patch % Lines
codec/gob/gob.go 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #94      +/-   ##
==========================================
- Coverage   89.23%   89.20%   -0.04%     
==========================================
  Files          10       13       +3     
  Lines         511      528      +17     
==========================================
+ Hits          456      471      +15     
- Misses         32       33       +1     
- Partials       23       24       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ksysoev ksysoev linked an issue Jul 1, 2026 that may be closed by this pull request
@ksysoev ksysoev requested a review from Copilot July 1, 2026 10:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modularizes anycache’s serialization layer by moving the JSON codec out of the root package and adding additional codec implementations (BSON, Gob, MessagePack) as dedicated subpackages under codec/, improving extensibility for swapping/adding codecs.

Changes:

  • Moved the JSON codec implementation into codec/json and updated the cache default + tests to use it.
  • Added new codec packages (codec/bson, codec/gob, codec/msgpack) with corresponding unit tests.
  • Updated module dependencies to support the new codec implementations and refreshed documentation text.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Updates option documentation to mention available codecs.
go.mod Adds/updates dependencies required for BSON and MessagePack support.
go.sum Records checksums for newly introduced/updated transitive dependencies.
codec.go Leaves only the Codec interface in the root package (removes old JSON implementation).
anycache.go Switches the default codec to codec/json.
cache_options_test.go Updates tests to use codec/json instead of the removed root JSON codec.
codec/json/json.go Introduces JSON codec implementation in its own package.
codec/json/json_test.go Moves/updates JSON codec tests for the new package.
codec/bson/bson.go Adds BSON codec implementation.
codec/bson/bson_test.go Adds BSON codec tests.
codec/gob/gob.go Adds Gob codec implementation.
codec/gob/gob_test.go Adds Gob codec tests.
codec/msgpack/msgpack.go Adds MessagePack codec implementation.
codec/msgpack/msgpack_test.go Adds MessagePack codec tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ksysoev ksysoev merged commit 76a485a into main Jul 1, 2026
2 checks passed
@ksysoev ksysoev deleted the more_custom_codecs branch July 1, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more codecs for encoding cache values.

2 participants