codec

command
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Example: Pluggable Codec — demonstrates the pluggable Codec interface.

Aarv supports pluggable JSON codecs for different performance/feature tradeoffs:

  1. Default (encoding/json) - Zero dependencies, standard library
  2. PrettyJSONCodec - Custom codec with indented output (shown in this example)
  3. segmentio/encoding/json - ~2-3x faster, drop-in replacement
  4. bytedance/sonic - ~5-10x faster, JIT-compiled (amd64/arm64)
  5. go-json-experiment/json - Future encoding/json/v2

To use alternative codecs, import and configure:

import "github.com/nilshah80/aarv/codec/segmentio"
app := aarv.New(aarv.WithCodec(segmentio.New()))

import "github.com/nilshah80/aarv/codec/sonic"
app := aarv.New(aarv.WithCodec(sonic.New()))         // Standard
app := aarv.New(aarv.WithCodec(sonic.NewFastest()))  // Maximum speed

import "github.com/nilshah80/aarv/codec/jsonv2"
app := aarv.New(aarv.WithCodec(jsonv2.New()))

The codec is used for all JSON operations: c.JSON(), c.BindJSON(), Bind[Req,Res]()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL