1
0
mirror of https://github.com/json-iterator/go.git synced 2025-05-13 21:36:29 +02:00

fix golint: document exported symbols

This commit is contained in:
Tao Wen 2017-07-09 14:57:49 +08:00
parent bede1d7f40
commit ce479f3476
3 changed files with 26 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import (
"io" "io"
) )
// Stream is a writer like object, with JSON specific write functions.
// Error is not returned as return value, but stored as Error member on this stream instance.
type Stream struct { type Stream struct {
cfg *frozenConfig cfg *frozenConfig
out io.Writer out io.Writer
@ -13,6 +15,10 @@ type Stream struct {
indention int indention int
} }
// NewStream create new stream instance.
// cfg can be jsoniter.ConfigDefault
// out can be nil if write to internal buffer
// bufSize is the initial size for the internal buffer in bytes
func NewStream(cfg *frozenConfig, out io.Writer, bufSize int) *Stream { func NewStream(cfg *frozenConfig, out io.Writer, bufSize int) *Stream {
return &Stream{ return &Stream{
cfg: cfg, cfg: cfg,
@ -24,6 +30,7 @@ func NewStream(cfg *frozenConfig, out io.Writer, bufSize int) *Stream {
} }
} }
// Reset reuse this stream instance by assign a new writer
func (stream *Stream) Reset(out io.Writer) { func (stream *Stream) Reset(out io.Writer) {
stream.out = out stream.out = out
stream.n = 0 stream.n = 0
@ -39,6 +46,7 @@ func (stream *Stream) Buffered() int {
return stream.n return stream.n
} }
// Buffer if writer is nil, use this method to take the result
func (stream *Stream) Buffer() []byte { func (stream *Stream) Buffer() []byte {
return stream.buf[:stream.n] return stream.buf[:stream.n]
} }
@ -188,6 +196,8 @@ func (stream *Stream) growAtLeast(minimal int) {
stream.buf = newBuf stream.buf = newBuf
} }
// WriteRaw write string out without quotes, just like []byte
func (stream *Stream) WriteRaw(s string) { func (stream *Stream) WriteRaw(s string) {
stream.ensure(len(s)) stream.ensure(len(s))
if stream.Error != nil { if stream.Error != nil {
@ -197,18 +207,22 @@ func (stream *Stream) WriteRaw(s string) {
stream.n += n stream.n += n
} }
// WriteNil write null to stream
func (stream *Stream) WriteNil() { func (stream *Stream) WriteNil() {
stream.writeFourBytes('n', 'u', 'l', 'l') stream.writeFourBytes('n', 'u', 'l', 'l')
} }
// WriteTrue write true to stream
func (stream *Stream) WriteTrue() { func (stream *Stream) WriteTrue() {
stream.writeFourBytes('t', 'r', 'u', 'e') stream.writeFourBytes('t', 'r', 'u', 'e')
} }
// WriteFalse write false to stream
func (stream *Stream) WriteFalse() { func (stream *Stream) WriteFalse() {
stream.writeFiveBytes('f', 'a', 'l', 's', 'e') stream.writeFiveBytes('f', 'a', 'l', 's', 'e')
} }
// WriteBool write true or false into stream
func (stream *Stream) WriteBool(val bool) { func (stream *Stream) WriteBool(val bool) {
if val { if val {
stream.WriteTrue() stream.WriteTrue()
@ -217,12 +231,14 @@ func (stream *Stream) WriteBool(val bool) {
} }
} }
// WriteObjectStart write { with possible indention
func (stream *Stream) WriteObjectStart() { func (stream *Stream) WriteObjectStart() {
stream.indention += stream.cfg.indentionStep stream.indention += stream.cfg.indentionStep
stream.writeByte('{') stream.writeByte('{')
stream.writeIndention(0) stream.writeIndention(0)
} }
// WriteObjectField write "field": with possible indention
func (stream *Stream) WriteObjectField(field string) { func (stream *Stream) WriteObjectField(field string) {
stream.WriteString(field) stream.WriteString(field)
if stream.indention > 0 { if stream.indention > 0 {
@ -232,33 +248,39 @@ func (stream *Stream) WriteObjectField(field string) {
} }
} }
// WriteObjectEnd write } with possible indention
func (stream *Stream) WriteObjectEnd() { func (stream *Stream) WriteObjectEnd() {
stream.writeIndention(stream.cfg.indentionStep) stream.writeIndention(stream.cfg.indentionStep)
stream.indention -= stream.cfg.indentionStep stream.indention -= stream.cfg.indentionStep
stream.writeByte('}') stream.writeByte('}')
} }
// WriteObjectEnd write {}
func (stream *Stream) WriteEmptyObject() { func (stream *Stream) WriteEmptyObject() {
stream.writeByte('{') stream.writeByte('{')
stream.writeByte('}') stream.writeByte('}')
} }
// WriteObjectEnd write , with possible indention
func (stream *Stream) WriteMore() { func (stream *Stream) WriteMore() {
stream.writeByte(',') stream.writeByte(',')
stream.writeIndention(0) stream.writeIndention(0)
} }
// WriteArrayStart write [ with possible indention
func (stream *Stream) WriteArrayStart() { func (stream *Stream) WriteArrayStart() {
stream.indention += stream.cfg.indentionStep stream.indention += stream.cfg.indentionStep
stream.writeByte('[') stream.writeByte('[')
stream.writeIndention(0) stream.writeIndention(0)
} }
// WriteEmptyArray write []
func (stream *Stream) WriteEmptyArray() { func (stream *Stream) WriteEmptyArray() {
stream.writeByte('[') stream.writeByte('[')
stream.writeByte(']') stream.writeByte(']')
} }
// WriteArrayEnd write ] with possible indention
func (stream *Stream) WriteArrayEnd() { func (stream *Stream) WriteArrayEnd() {
stream.writeIndention(stream.cfg.indentionStep) stream.writeIndention(stream.cfg.indentionStep)
stream.indention -= stream.cfg.indentionStep stream.indention -= stream.cfg.indentionStep

View File

@ -36,10 +36,12 @@ func decode(str string) string {
return string(bs) return string(bs)
} }
// MarshalJSON TEST ONLY
func (m MarshalerForTest) MarshalJSON() ([]byte, error) { func (m MarshalerForTest) MarshalJSON() ([]byte, error) {
return []byte(`"MANUAL__` + encode(string(m)) + `"`), nil return []byte(`"MANUAL__` + encode(string(m)) + `"`), nil
} }
// UnmarshalJSON TEST ONLY
func (m *MarshalerForTest) UnmarshalJSON(text []byte) error { func (m *MarshalerForTest) UnmarshalJSON(text []byte) error {
*m = MarshalerForTest(decode(strings.TrimPrefix(strings.Trim(string(text), `"`), "MANUAL__"))) *m = MarshalerForTest(decode(strings.TrimPrefix(strings.Trim(string(text), `"`), "MANUAL__")))
return nil return nil

View File

@ -36,10 +36,12 @@ func decode(str string) string {
return string(bs) return string(bs)
} }
// MarshalText TEST ONLY
func (m MarshalerForTest) MarshalText() ([]byte, error) { func (m MarshalerForTest) MarshalText() ([]byte, error) {
return []byte(`MANUAL__` + encode(string(m))), nil return []byte(`MANUAL__` + encode(string(m))), nil
} }
// UnmarshalText TEST ONLY
func (m *MarshalerForTest) UnmarshalText(text []byte) error { func (m *MarshalerForTest) UnmarshalText(text []byte) error {
*m = MarshalerForTest(decode(strings.TrimPrefix(string(text), "MANUAL__"))) *m = MarshalerForTest(decode(strings.TrimPrefix(string(text), "MANUAL__")))
return nil return nil