Skip to content
Myr

sonic.go

This file

Path

codec/json/sonic.go

44 lines · 953 bytes · Go

Last changed by

feat: support custom json codec at runtime (#3391)Timbefore adoption688a429

History of this file

Take it

1// Copyright 2025 Gin Core Team. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45//go:build sonic && (linux || windows || darwin)67package json89import (10	"io"1112	"github.com/bytedance/sonic"13)1415// Package indicates what library is being used for JSON encoding.16const Package = "github.com/bytedance/sonic"1718func init() {19	API = sonicApi{}20}2122var json = sonic.ConfigStd2324type sonicApi struct{}2526func (j sonicApi) Marshal(v any) ([]byte, error) {27	return json.Marshal(v)28}2930func (j sonicApi) Unmarshal(data []byte, v any) error {31	return json.Unmarshal(data, v)32}3334func (j sonicApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {35	return json.MarshalIndent(v, prefix, indent)36}3738func (j sonicApi) NewEncoder(writer io.Writer) Encoder {39	return json.NewEncoder(writer)40}4142func (j sonicApi) NewDecoder(reader io.Reader) Decoder {43	return json.NewDecoder(reader)44}