jsonbuilder

package
v0.0.0-...-8e4d058 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReturnStream

func ReturnStream(stream *Stream)

Types

type JsonConfig

type JsonConfig struct {
	// contains filtered or unexported fields
}

func NewJsonConfig

func NewJsonConfig(indentionStep int) *JsonConfig

type Stream

type Stream struct {
	Error error

	Attachment interface{} // open for customized encoder
	// contains filtered or unexported fields
}

stream is a io.Writer like object, with JSON specific write functions. Error is not returned as return value, but stored as Error member on this stream instance.

func BorrowStream

func BorrowStream(writer io.Writer) *Stream

func NewStream

func NewStream(cfg *JsonConfig, out io.Writer, bufSize int) *Stream

NewStream create new stream instance. out can be nil if write to internal buffer. bufSize is the initial size for the internal buffer in bytes.

func (*Stream) Available

func (stream *Stream) Available() int

Available returns how many bytes are unused in the buffer.

func (*Stream) Buffer

func (stream *Stream) Buffer() []byte

Buffer if writer is nil, use this method to take the result

func (*Stream) Buffered

func (stream *Stream) Buffered() int

Buffered returns the number of bytes that have been written into the current buffer.

func (*Stream) Flush

func (stream *Stream) Flush() error

Flush writes any buffered data to the underlying io.Writer.

func (*Stream) Reset

func (stream *Stream) Reset(out io.Writer)

Reset reuse this stream instance by assign a new writer

func (*Stream) SetBuffer

func (stream *Stream) SetBuffer(buf []byte)

SetBuffer allows to append to the internal buffer directly

func (*Stream) Write

func (stream *Stream) Write(p []byte) (nn int, err error)

Write writes the contents of p into the buffer. It returns the number of bytes written. If nn < len(p), it also returns an error explaining why the write is short.

func (*Stream) WriteArrayEnd

func (stream *Stream) WriteArrayEnd()

WriteArrayEnd write ] with possible indention

func (*Stream) WriteArrayStart

func (stream *Stream) WriteArrayStart()

WriteArrayStart write [ with possible indention

func (*Stream) WriteBool

func (stream *Stream) WriteBool(val bool)

WriteBool write true or false into stream

func (*Stream) WriteByte

func (stream *Stream) WriteByte(c byte)

func (*Stream) WriteEmptyArray

func (stream *Stream) WriteEmptyArray()

WriteEmptyArray write []

func (*Stream) WriteEmptyObject

func (stream *Stream) WriteEmptyObject()

WriteEmptyObject write {}

func (*Stream) WriteFalse

func (stream *Stream) WriteFalse()

WriteFalse write false to stream

func (*Stream) WriteFloat32

func (stream *Stream) WriteFloat32(val float32)

WriteFloat32 write float32 to stream

func (*Stream) WriteFloat32Lossy

func (stream *Stream) WriteFloat32Lossy(val float32)

WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster

func (*Stream) WriteFloat64

func (stream *Stream) WriteFloat64(val float64)

WriteFloat64 write float64 to stream

func (*Stream) WriteFloat64Lossy

func (stream *Stream) WriteFloat64Lossy(val float64)

WriteFloat64Lossy write float64 to stream with ONLY 17 digits precision although much much faster

func (*Stream) WriteInt

func (stream *Stream) WriteInt(val int)

WriteInt write int to stream

func (*Stream) WriteInt16

func (stream *Stream) WriteInt16(nval int16)

WriteInt16 write int16 to stream

func (*Stream) WriteInt32

func (stream *Stream) WriteInt32(nval int32)

WriteInt32 write int32 to stream

func (*Stream) WriteInt64

func (stream *Stream) WriteInt64(nval int64)

WriteInt64 write int64 to stream

func (*Stream) WriteInt8

func (stream *Stream) WriteInt8(nval int8)

WriteInt8 write int8 to stream

func (*Stream) WriteMore

func (stream *Stream) WriteMore()

WriteMore write , with possible indention

func (*Stream) WriteNil

func (stream *Stream) WriteNil()

WriteNil write null to stream

func (*Stream) WriteObjectEnd

func (stream *Stream) WriteObjectEnd()

WriteObjectEnd write } with possible indention

func (*Stream) WriteObjectField

func (stream *Stream) WriteObjectField(field string)

WriteObjectField write "field": with possible indention

func (*Stream) WriteObjectStart

func (stream *Stream) WriteObjectStart()

WriteObjectStart write { with possible indention

func (*Stream) WriteRaw

func (stream *Stream) WriteRaw(s string)

WriteRaw write string out without quotes, just like []byte

func (*Stream) WriteString

func (stream *Stream) WriteString(s string)

WriteString write string to stream without html escape

func (*Stream) WriteStringByte

func (stream *Stream) WriteStringByte(c byte)

func (*Stream) WriteTrue

func (stream *Stream) WriteTrue()

WriteTrue write true to stream

func (*Stream) WriteUint

func (stream *Stream) WriteUint(val uint)

WriteUint write uint to stream

func (*Stream) WriteUint16

func (stream *Stream) WriteUint16(val uint16)

WriteUint16 write uint16 to stream

func (*Stream) WriteUint32

func (stream *Stream) WriteUint32(val uint32)

WriteUint32 write uint32 to stream

func (*Stream) WriteUint64

func (stream *Stream) WriteUint64(val uint64)

WriteUint64 write uint64 to stream

func (*Stream) WriteUint8

func (stream *Stream) WriteUint8(val uint8)

WriteUint8 write uint8 to stream

Jump to

Keyboard shortcuts

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