Skip to content

🔄 Refactor CBOR implementation to match MsgPack opt-in pattern #3577

@coderabbitai

Description

@coderabbitai

Description

Currently, CBOR support in Fiber is implemented with direct imports of the github.com/fxamacker/cbor/v2 library, while the new MsgPack implementation (PR #3565) uses an opt-in pattern with binder mock functions to avoid forcing dependencies on rarely used serialization libraries.

Current State

CBOR (current implementation):

  • Direct import of github.com/fxamacker/cbor/v2
  • Uses cbor.Marshal and cbor.Unmarshal as defaults
  • Forces dependency on all users

MsgPack (new pattern):

  • Uses binder.UnimplementedMsgpackMarshal and binder.UnimplementedMsgpackUnmarshal as defaults
  • Mock functions panic if called without explicit setup
  • Allows users to opt-in by configuring their preferred MsgPack library

Proposed Changes

Refactor CBOR implementation to follow the MsgPack pattern:

  1. Create binder.UnimplementedCborMarshal and binder.UnimplementedCborUnmarshal functions
  2. Set these as defaults in the Config struct instead of cbor.Marshal/cbor.Unmarshal
  3. Remove direct github.com/fxamacker/cbor/v2 import from core app
  4. Update documentation to show users how to explicitly configure CBOR support
  5. Maintain backward compatibility where possible

Benefits

  • Reduces binary size for users who don't use CBOR
  • Follows the opt-in philosophy for non-standard serialization formats
  • Consistent approach across MsgPack and CBOR implementations
  • Allows users to choose their preferred CBOR library

Context

This refactoring was discussed in PR #3565 (MsgPack implementation):

Related

  • Part of the broader serialization architecture improvements
  • Could be extended to other non-standard formats in the future
  • Aligns with the plugin-based registry pattern discussion for Fiber v3

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions