serialize

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const MinIndent = "  "

Variables

This section is empty.

Functions

func MarshalJSON

func MarshalJSON(s Serializable) ([]byte, error)

Types

type BufferedSerializer

type BufferedSerializer struct {
	JsonSerializer
	// We buffer the writer to prepend locals later
	Original Writer
	Buffer   bytes.Buffer
	Buffered *bufio.Writer
}

Serializer that collects output into a buffer

func (*BufferedSerializer) End

func (j *BufferedSerializer) End()

End implements Serializer

func (*BufferedSerializer) Setup

func (j *BufferedSerializer) Setup(w Writer, params map[string]string)

Setup implements Serializer

type JsonSerializer

type JsonSerializer struct {
	Writer        Writer            // Where to write
	ReverseParams map[string]string // match strings and turn into parameters
	Matched       map[string]string // Which params were matched
	Depth         int               // indentation depth, if -1 then do not indent
	Err           error
	// contains filtered or unexported fields
}

Serializes a JSON object to a string.

func (*JsonSerializer) Begin

func (j *JsonSerializer) Begin()

Begin serializing a new object

func (*JsonSerializer) BeginBlock

func (j *JsonSerializer) BeginBlock(optionalTitle string)

BeginBlock opens a block with an optional key

func (*JsonSerializer) BeginList

func (j *JsonSerializer) BeginList(optionalTitle string)

BeginList opens a list with an optional key

func (*JsonSerializer) End

func (j *JsonSerializer) End()

End object serialization

func (*JsonSerializer) EndBlock

func (j *JsonSerializer) EndBlock()

Endblock closes a block

func (*JsonSerializer) EndList

func (j *JsonSerializer) EndList()

EndList closes a list

func (*JsonSerializer) Error

func (j *JsonSerializer) Error() error

Error accumulates errors while encoding to check at the end

func (*JsonSerializer) KeyBool

func (j *JsonSerializer) KeyBool(k string, v bool)

KeyBool dumps a key and value pair, value is bool

func (*JsonSerializer) KeyFloat

func (j *JsonSerializer) KeyFloat(k string, v float64)

KeyFloat dumps a key and value pair, value is float

func (*JsonSerializer) KeyInt

func (j *JsonSerializer) KeyInt(k string, v int)

KeyInt dumps a key and value pair, value is int

func (*JsonSerializer) KeyRaw

func (j *JsonSerializer) KeyRaw(k string, v json.RawMessage, compact bool)

KeyRaw dumps a key and value pair, value is json.RawMessage

func (*JsonSerializer) KeyString

func (j *JsonSerializer) KeyString(k, v string)

KeyString dumps a key and value pair, value is string

func (*JsonSerializer) Param

func (j *JsonSerializer) Param(s string)

Param called on every string, to check if it must be replaced

func (*JsonSerializer) Serialize

func (j *JsonSerializer) Serialize(s Serializable)

Serialize recursos into a Serializable object

func (*JsonSerializer) Setup

func (j *JsonSerializer) Setup(w Writer, params map[string]string)

Setup must be called before starting serializing

func (*JsonSerializer) String

func (j *JsonSerializer) String(v string)

KeyString dumps a string

type Serializable

type Serializable interface {
	Serialize(Serializer)
}

type Serializer

type Serializer interface {
	KeyString(k, v string)                            // , "key": "val"
	String(v string)                                  // , "val"
	KeyInt(k string, v int)                           // , "key": val
	KeyFloat(k string, v float64)                     // , "key": val
	KeyBool(k string, v bool)                         // , "key": val
	KeyRaw(k string, v json.RawMessage, compact bool) // , "key": val
	Serialize(Serializable)
	BeginBlock(string) // { + omit first ","
	EndBlock()         // }
	BeginList(string)  // [ + omit first ","
	EndList()          // ]
	Error() error      // If it failed at any step
}

type Writer

type Writer interface {
	io.Writer
	io.StringWriter
}

Jump to

Keyboard shortcuts

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