Skip to content

feat: generic codec interface#5

Merged
franklinkim merged 29 commits intomainfrom
feature/generic-codec-interface
Apr 21, 2026
Merged

feat: generic codec interface#5
franklinkim merged 29 commits intomainfrom
feature/generic-codec-interface

Conversation

@franklinkim
Copy link
Copy Markdown
Member

@franklinkim franklinkim commented Apr 21, 2026

Description

Replace the Codec[T] interface with generic function-type structs (Codec[S,T], StreamCodec[S]) and add type-safe PipeCodec composition. Export standalone Encoder, Decoder, StreamEncoder, and StreamDecoder constructors across all codec packages.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactoring
  • ⚡ Performance
  • ✅ Tests
  • 🔧 Build/CI

Changes

  • Replace Codec[T] interface and EncoderFunc/DecoderFunc with Encoder[S,T], Decoder[S,T], Codec[S,T] function-type structs
  • Replace StreamEncoder[S]/StreamDecoder[S] interfaces with function types bundled in StreamCodec[S]
  • Add PipeEncoder, PipeDecoder, PipeCodec for type-safe codec chaining
  • Export standalone NewEncoder/NewDecoder/NewStreamEncoder/NewStreamDecoder in all codec packages
  • Add StreamCodec support to yaml/v2, yaml/v3, yaml/v4, json/v2
  • Update file codec to accept Codec[T, []byte]

Checklist

  • My code adheres to the coding and style guidelines of the project.
  • I have performed a self-review of my own code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.

franklinkim and others added 29 commits April 21, 2026 00:28
…ruct

Replace single-param interfaces with two-param function types:
- Encoder[S,T] func type, Decoder[S,T] func type
- Codec[S,T] struct bundling Encode/Decode
- StreamEncoder[S], StreamDecoder[S] func types
- StreamCodec[S] struct bundling stream Encode/Decode
- Remove old Encoder[T], Decoder[T] interfaces and Func wrappers
Remove decorator pattern. Each compression codec now operates on raw
bytes. Use goencode.PipeCodec() to compose with serialization codecs.
Also migrate toml codec to Codec[S,T] function type.
- Convert Pipe tests to Examples for godoc visibility
- Migrate toml streamcodec to Codec[S,T] function type
- Add json/v2 ExampleNewStreamCodec
- Fix toml ExampleStreamCodec → ExampleNewStreamCodec
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…scii85, pem

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Moved to .claude/data/superpowers/ which is gitignored.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ml, gob, asn1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…se32, hex, ascii85, pem

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…td, brotli

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…/v2, msgpack/*

Move json/v2 NewStreamCodec from codec.go to streamcodec.go.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… yaml/v2, v3, v4

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@franklinkim franklinkim merged commit 7f54123 into main Apr 21, 2026
1 check passed
@franklinkim franklinkim deleted the feature/generic-codec-interface branch April 21, 2026 15:36
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.

1 participant