bfr

package
v0.0.0-...-7e8a755 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: BSD-2-Clause Imports: 5 Imported by: 7

Documentation

Overview

Package bfr provides a common interface for buffered writers and a bytes.Buffer pool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() *bytes.Buffer

Get returns a bytes.Buffer from the pool.

func Grow

func Grow(b B, n int)

Grow grows the buffer by n if it implements a Grow(int) method. Both bytes.Buffer and strings.Builder implement that method.

func JSON

func JSON(w Writer) ([]byte, error)

JSON writes w in json format and returns the result as bytes or an error.

func Put

func Put(b *bytes.Buffer)

Put a Buffer back into the pool.

func String

func String(w Writer) string

String writes w in xelf format and returns the result as string ignoring any error.

Types

type B

type B interface {
	Write([]byte) (int, error)
	WriteByte(byte) error
	WriteRune(rune) (int, error)
	WriteString(string) (int, error)
}

B is the common interface of bytes.Buffer, strings.Builder and bufio.Writer.

type Ctx

type Ctx struct {
	B
	JSON  bool
	Depth int
	Tab   string
}

Ctx is serialization context with output configuration flags

func (*Ctx) Break

func (c *Ctx) Break() bool

func (*Ctx) Dedent

func (c *Ctx) Dedent() bool

func (*Ctx) Fmt

func (c *Ctx) Fmt(f string, args ...interface{}) (err error)

Fmt writes the formatted string to the buffer or returns an error

func (*Ctx) Indent

func (c *Ctx) Indent() bool

func (*Ctx) Quote

func (c *Ctx) Quote(v string) (err error)

Quote writes v as quoted string to the buffer or returns an error. The quote used depends on the json context flag.

func (*Ctx) RecordKey

func (c *Ctx) RecordKey(key string) (err error)

RecordKey writes key as quoted string followed by a colon to the buffer or returns an error. The quote used depends on the json context flag.

func (*Ctx) Sep

func (c *Ctx) Sep() error

Sep writes a record field or list element separator to the buffer or returns an error. The separator used depends on the json context flag.

type Writer

type Writer interface {
	WriteBfr(*Ctx) error
}

Writer is an interface for types that can write to a Ctx

Jump to

Keyboard shortcuts

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