Help us shape the future of Go! Take the 2026 Go Developer Survey

segmentio

package module
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 2 Imported by: 0

README

aarv segmentio codec

A drop-in JSON codec for aarv backed by github.com/segmentio/encoding/json, a faster, allocation-friendly replacement for encoding/json that keeps full behavioral compatibility with the standard library.

When to use it

  • You want a meaningful speedup over encoding/json without changing tags or struct shapes.
  • You need pure-Go portability (works on every architecture Go supports).
  • You don't want JIT warmup or any of sonic's platform constraints.

Install

go get github.com/nilshah80/aarv/codec/segmentio

This codec lives in its own Go module so the main aarv module stays dependency-free.

Usage

import (
    "github.com/nilshah80/aarv"
    "github.com/nilshah80/aarv/codec/segmentio"
)

app := aarv.New(aarv.WithCodec(segmentio.New()))

That's it — every c.JSON(...) and request-body bind on the app now goes through segmentio's encoder.

Notes

  • Behavior matches encoding/json, including struct tags, json.Marshaler, and omitempty.
  • Recorded head-to-head numbers against sonic and jsonv2 live in ../benchmarks/RESULTS.md. The suite is its own Go module — reproduce with cd codec/benchmarks && go test -bench=. -benchmem ./... (running from the repo root will not work).

Documentation

Overview

Package segmentio implements the aarv.Codec interface using the github.com/segmentio/encoding/json library, a high-performance drop-in replacement for encoding/json.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SegmentioCodec

type SegmentioCodec struct{}

SegmentioCodec implements aarv.Codec using segmentio/encoding/json.

func New

func New() *SegmentioCodec

New returns a new SegmentioCodec.

func (*SegmentioCodec) ContentType

func (c *SegmentioCodec) ContentType() string

ContentType returns the MIME type for JSON content.

func (*SegmentioCodec) Decode

func (c *SegmentioCodec) Decode(r io.Reader, v any) error

Decode reads JSON from r and unmarshals it into v.

func (*SegmentioCodec) Encode

func (c *SegmentioCodec) Encode(w io.Writer, v any) error

Encode marshals v as JSON and writes it to w.

func (*SegmentioCodec) MarshalBytes

func (c *SegmentioCodec) MarshalBytes(v any) ([]byte, error)

MarshalBytes marshals v into JSON bytes.

func (*SegmentioCodec) UnmarshalBytes

func (c *SegmentioCodec) UnmarshalBytes(data []byte, v any) error

UnmarshalBytes unmarshals JSON bytes into v.

Jump to

Keyboard shortcuts

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