Lines Matching refs:stream

34 func (stream *Stream) Pool() StreamPool {
35 return stream.cfg
39 func (stream *Stream) Reset(out io.Writer) {
40 stream.out = out
41 stream.n = 0
45 func (stream *Stream) Available() int {
46 return len(stream.buf) - stream.n
50 func (stream *Stream) Buffered() int {
51 return stream.n
55 func (stream *Stream) Buffer() []byte {
56 return stream.buf[:stream.n]
63 func (stream *Stream) Write(p []byte) (nn int, err error) {
64 for len(p) > stream.Available() && stream.Error == nil {
65 if stream.out == nil {
66 stream.growAtLeast(len(p))
69 if stream.Buffered() == 0 {
72 n, stream.Error = stream.out.Write(p)
74 n = copy(stream.buf[stream.n:], p)
75 stream.n += n
76 stream.Flush()
82 if stream.Error != nil {
83 return nn, stream.Error
85 n := copy(stream.buf[stream.n:], p)
86 stream.n += n
92 func (stream *Stream) writeByte(c byte) {
93 if stream.Error != nil {
96 if stream.Available() < 1 {
97 stream.growAtLeast(1)
99 stream.buf[stream.n] = c
100 stream.n++
103 func (stream *Stream) writeTwoBytes(c1 byte, c2 byte) {
104 if stream.Error != nil {
107 if stream.Available() < 2 {
108 stream.growAtLeast(2)
110 stream.buf[stream.n] = c1
111 stream.buf[stream.n+1] = c2
112 stream.n += 2
115 func (stream *Stream) writeThreeBytes(c1 byte, c2 byte, c3 byte) {
116 if stream.Error != nil {
119 if stream.Available() < 3 {
120 stream.growAtLeast(3)
122 stream.buf[stream.n] = c1
123 stream.buf[stream.n+1] = c2
124 stream.buf[stream.n+2] = c3
125 stream.n += 3
128 func (stream *Stream) writeFourBytes(c1 byte, c2 byte, c3 byte, c4 byte) {
129 if stream.Error != nil {
132 if stream.Available() < 4 {
133 stream.growAtLeast(4)
135 stream.buf[stream.n] = c1
136 stream.buf[stream.n+1] = c2
137 stream.buf[stream.n+2] = c3
138 stream.buf[stream.n+3] = c4
139 stream.n += 4
142 func (stream *Stream) writeFiveBytes(c1 byte, c2 byte, c3 byte, c4 byte, c5 byte) {
143 if stream.Error != nil {
146 if stream.Available() < 5 {
147 stream.growAtLeast(5)
149 stream.buf[stream.n] = c1
150 stream.buf[stream.n+1] = c2
151 stream.buf[stream.n+2] = c3
152 stream.buf[stream.n+3] = c4
153 stream.buf[stream.n+4] = c5
154 stream.n += 5
158 func (stream *Stream) Flush() error {
159 if stream.out == nil {
162 if stream.Error != nil {
163 return stream.Error
165 if stream.n == 0 {
168 n, err := stream.out.Write(stream.buf[0:stream.n])
169 if n < stream.n && err == nil {
173 if n > 0 && n < stream.n {
174 copy(stream.buf[0:stream.n-n], stream.buf[n:stream.n])
176 stream.n -= n
177 stream.Error = err
180 stream.n = 0
184 func (stream *Stream) ensure(minimal int) {
185 available := stream.Available()
187 stream.growAtLeast(minimal)
191 func (stream *Stream) growAtLeast(minimal int) {
192 if stream.out != nil {
193 stream.Flush()
195 toGrow := len(stream.buf)
199 newBuf := make([]byte, len(stream.buf)+toGrow)
200 copy(newBuf, stream.Buffer())
201 stream.buf = newBuf
205 func (stream *Stream) WriteRaw(s string) {
206 stream.ensure(len(s))
207 if stream.Error != nil {
210 n := copy(stream.buf[stream.n:], s)
211 stream.n += n
215 func (stream *Stream) WriteNil() {
216 stream.writeFourBytes('n', 'u', 'l', 'l')
220 func (stream *Stream) WriteTrue() {
221 stream.writeFourBytes('t', 'r', 'u', 'e')
225 func (stream *Stream) WriteFalse() {
226 stream.writeFiveBytes('f', 'a', 'l', 's', 'e')
230 func (stream *Stream) WriteBool(val bool) {
232 stream.WriteTrue()
234 stream.WriteFalse()
239 func (stream *Stream) WriteObjectStart() {
240 stream.indention += stream.cfg.indentionStep
241 stream.writeByte('{')
242 stream.writeIndention(0)
246 func (stream *Stream) WriteObjectField(field string) {
247 stream.WriteString(field)
248 if stream.indention > 0 {
249 stream.writeTwoBytes(':', ' ')
251 stream.writeByte(':')
256 func (stream *Stream) WriteObjectEnd() {
257 stream.writeIndention(stream.cfg.indentionStep)
258 stream.indention -= stream.cfg.indentionStep
259 stream.writeByte('}')
263 func (stream *Stream) WriteEmptyObject() {
264 stream.writeByte('{')
265 stream.writeByte('}')
269 func (stream *Stream) WriteMore() {
270 stream.writeByte(',')
271 stream.writeIndention(0)
275 func (stream *Stream) WriteArrayStart() {
276 stream.indention += stream.cfg.indentionStep
277 stream.writeByte('[')
278 stream.writeIndention(0)
282 func (stream *Stream) WriteEmptyArray() {
283 stream.writeByte('[')
284 stream.writeByte(']')
288 func (stream *Stream) WriteArrayEnd() {
289 stream.writeIndention(stream.cfg.indentionStep)
290 stream.indention -= stream.cfg.indentionStep
291 stream.writeByte(']')
294 func (stream *Stream) writeIndention(delta int) {
295 if stream.indention == 0 {
298 stream.writeByte('\n')
299 toWrite := stream.indention - delta
300 stream.ensure(toWrite)
301 for i := 0; i < toWrite && stream.n < len(stream.buf); i++ {
302 stream.buf[stream.n] = ' '
303 stream.n++