bfr

package
v0.0.0-...-9cd5b15 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: BSD-2-Clause Imports: 5 Imported by: 15

Documentation

Overview

Package bfr provides a writer and printer interface and pool of bytes.Buffer.

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 Writer, 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(p Printer) (res []byte, err 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 *bytes.Buffer back into the pool.

func String

func String(p Printer) string

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

Types

type P

type P struct {
	Writer
	JSON  bool
	Plain bool
	Depth int
	Tab   string
	Err   error
}

P is serialization context with output configuration flags for printers

func (*P) Break

func (p *P) Break() bool

func (*P) Byte

func (p *P) Byte(b byte) (err error)

func (*P) Dedent

func (p *P) Dedent() bool

func (*P) Fmt

func (p *P) Fmt(f string, args ...interface{}) (err error)

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

func (*P) Indent

func (p *P) Indent() bool

func (*P) Quote

func (p *P) 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 (*P) RecordKey

func (p *P) RecordKey(key string) 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 (*P) RecordKeyTag

func (p *P) RecordKeyTag(key string, tag byte) (err error)

func (*P) Sep

func (p *P) 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 Printer

type Printer interface {
	Print(*P) error
}

Printer is an interface for types that can print

type Writer

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

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

Jump to

Keyboard shortcuts

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