Lines Matching refs:w

74 	w        writer  member
77 func (w *textWriter) WriteString(s string) (n int, err error) {
79 if !w.compact && w.complete {
80 w.writeIndent()
82 w.complete = false
83 return io.WriteString(w.w, s)
88 return w.Write([]byte(s))
91 func (w *textWriter) Write(p []byte) (n int, err error) {
94 if !w.compact && w.complete {
95 w.writeIndent()
97 n, err = w.w.Write(p)
98 w.complete = false
103 if w.compact {
106 if err := w.w.WriteByte(' '); err != nil {
111 nn, err := w.w.Write(frag)
121 if w.complete {
122 w.writeIndent()
124 nn, err := w.w.Write(frag)
130 if err := w.w.WriteByte('\n'); err != nil {
136 w.complete = len(frags[len(frags)-1]) == 0
140 func (w *textWriter) WriteByte(c byte) error {
141 if w.compact && c == '\n' {
144 if !w.compact && w.complete {
145 w.writeIndent()
147 err := w.w.WriteByte(c)
148 w.complete = c == '\n'
152 func (w *textWriter) indent() { w.ind++ }
154 func (w *textWriter) unindent() {
155 if w.ind == 0 {
159 w.ind--
162 func writeName(w *textWriter, props *Properties) error {
163 if _, err := w.WriteString(props.OrigName); err != nil {
167 return w.WriteByte(':')
207 func (tm *TextMarshaler) writeProto3Any(w *textWriter, sv reflect.Value) (bool, error) {
228 w.Write([]byte("["))
231 writeString(w, u)
233 w.Write([]byte(u))
235 if w.compact {
236 w.Write([]byte("]:<"))
238 w.Write([]byte("]: <\n"))
239 w.ind++
241 if err := tm.writeStruct(w, m.Elem()); err != nil {
244 if w.compact {
245 w.Write([]byte("> "))
247 w.ind--
248 w.Write([]byte(">\n"))
253 func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
255 if canExpand, err := tm.writeProto3Any(w, sv); canExpand {
277 if err := writeUnknownStruct(w, fv.Interface().([]byte)); err != nil {
297 if err := writeName(w, props); err != nil {
300 if !w.compact {
301 if err := w.WriteByte(' '); err != nil {
309 if _, err := w.Write([]byte("<nil>\n")); err != nil {
314 if err := tm.writeAny(w, v, props); err != nil {
317 if err := w.WriteByte('\n'); err != nil {
329 if err := writeName(w, props); err != nil {
332 if !w.compact {
333 if err := w.WriteByte(' '); err != nil {
338 if err := w.WriteByte('<'); err != nil {
341 if !w.compact {
342 if err := w.WriteByte('\n'); err != nil {
346 w.indent()
348 if _, err := w.WriteString("key:"); err != nil {
351 if !w.compact {
352 if err := w.WriteByte(' '); err != nil {
356 if err := tm.writeAny(w, key, props.MapKeyProp); err != nil {
359 if err := w.WriteByte('\n'); err != nil {
365 if _, err := w.WriteString("value:"); err != nil {
368 if !w.compact {
369 if err := w.WriteByte(' '); err != nil {
373 if err := tm.writeAny(w, val, props.MapValProp); err != nil {
376 if err := w.WriteByte('\n'); err != nil {
381 w.unindent()
382 if err := w.WriteByte('>'); err != nil {
385 if err := w.WriteByte('\n'); err != nil {
429 if err := writeName(w, props); err != nil {
432 if !w.compact {
433 if err := w.WriteByte(' '); err != nil {
439 if err := tm.writeAny(w, fv, props); err != nil {
443 if err := w.WriteByte('\n'); err != nil {
451 if err := tm.writeExtensions(w, pv); err != nil {
460 func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
476 _, err := w.Write(b)
487 if err := writeString(w, string(v.Bytes())); err != nil {
491 if err := writeString(w, v.String()); err != nil {
500 if err := w.WriteByte(bra); err != nil {
503 if !w.compact {
504 if err := w.WriteByte('\n'); err != nil {
508 w.indent()
527 if _, err = w.Write(text); err != nil {
534 if err := tm.writeStruct(w, v); err != nil {
538 w.unindent()
539 if err := w.WriteByte(ket); err != nil {
543 _, err := fmt.Fprint(w, v.Interface())
559 func writeString(w *textWriter, s string) error {
561 if err := w.WriteByte('"'); err != nil {
572 _, err = w.w.Write(backslashN)
574 _, err = w.w.Write(backslashR)
576 _, err = w.w.Write(backslashT)
578 _, err = w.w.Write(backslashDQ)
580 _, err = w.w.Write(backslashBS)
583 err = w.w.WriteByte(c)
585 _, err = fmt.Fprintf(w.w, "\\%03o", c)
592 return w.WriteByte('"')
595 func writeUnknownStruct(w *textWriter, data []byte) (err error) {
596 if !w.compact {
597 if _, err := fmt.Fprintf(w, "/* %d unknown bytes */\n", len(data)); err != nil {
605 _, err := fmt.Fprintf(w, "/* %v */\n", err)
610 w.unindent()
611 if _, err := w.Write(endBraceNewline); err != nil {
616 if _, err := fmt.Fprint(w, tag); err != nil {
620 if err := w.WriteByte(':'); err != nil {
624 if !w.compact || wire == WireStartGroup {
625 if err := w.WriteByte(' '); err != nil {
633 _, err = fmt.Fprintf(w, "%q", buf)
635 _, err = fmt.Fprintf(w, "/* %v */", e)
639 err = writeUnknownInt(w, x, err)
642 err = writeUnknownInt(w, x, err)
644 err = w.WriteByte('{')
645 w.indent()
648 err = writeUnknownInt(w, x, err)
650 _, err = fmt.Fprintf(w, "/* unknown wire type %d */", wire)
655 if err = w.WriteByte('\n'); err != nil {
662 func writeUnknownInt(w *textWriter, x uint64, err error) error {
664 _, err = fmt.Fprint(w, x)
666 _, err = fmt.Fprintf(w, "/* %v */", err)
679 func (tm *TextMarshaler) writeExtensions(w *textWriter, pv reflect.Value) error {
706 if err := writeUnknownStruct(w, ext.enc); err != nil {
719 if err := tm.writeExtension(w, desc.Name, pb); err != nil {
725 if err := tm.writeExtension(w, desc.Name, v.Index(i).Interface()); err != nil {
734 func (tm *TextMarshaler) writeExtension(w *textWriter, name string, pb interface{}) error {
735 if _, err := fmt.Fprintf(w, "[%s]:", name); err != nil {
738 if !w.compact {
739 if err := w.WriteByte(' '); err != nil {
743 if err := tm.writeAny(w, reflect.ValueOf(pb), nil); err != nil {
746 if err := w.WriteByte('\n'); err != nil {
752 func (w *textWriter) writeIndent() {
753 if !w.complete {
756 remain := w.ind * 2
762 w.w.Write(spaces[:n])
765 w.complete = false
776 func (tm *TextMarshaler) Marshal(w io.Writer, pb Message) error {
779 w.Write([]byte("<nil>"))
783 ww, ok := w.(writer)
785 bw = bufio.NewWriter(w)
789 w: ww,
834 func MarshalText(w io.Writer, pb Message) error { return defaultTextMarshaler.Marshal(w, pb) }
840 func CompactText(w io.Writer, pb Message) error { return compactTextMarshaler.Marshal(w, pb) }