codec

package
v4.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package codec is a unified place for configuring and allocating JSON encoders and decoders.

Example
enc := GetEncoder(os.Stdout)
defer PutEncoder(enc)
enc.MustEncode([]string{"a", "slice", "of", "strings"})
fmt.Fprintln(os.Stdout)
enc.MustEncode(nil)
fmt.Fprintln(os.Stdout)
enc.MustEncode(map[string]string{})
fmt.Fprintln(os.Stdout)
Output:

["a","slice","of","strings"]
null
{}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONReader

func JSONReader(v interface{}) io.ReadCloser

JSONReader returns an io.ReadCloser backed by a pipe being fed by a JSON encoder.

func PutDecoder

func PutDecoder(d *Decoder)

PutDecoder returns a decoder to the pool.

func PutEncoder

func PutEncoder(e *Encoder)

PutEncoder returns an encoder to the pool.

Types

type Decoder

type Decoder = codec.Decoder

Decoder decodes.

func GetDecoder

func GetDecoder(r io.Reader) *Decoder

GetDecoder returns a decoder configured to read from r.

type Encoder

type Encoder = codec.Encoder

Encoder encodes.

func GetEncoder

func GetEncoder(w io.Writer) *Encoder

GetEncoder returns an encoder configured to write to w.

Jump to

Keyboard shortcuts

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