MCPcopy
hub / github.com/golang/protobuf / Write

Method Write

proto/text_encode.go:125–162  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

123}
124
125func (w *textWriter) Write(p []byte) (n int, _ error) {
126 newlines := bytes.Count(p, newline)
127 if newlines == 0 {
128 if !w.compact && w.complete {
129 w.writeIndent()
130 }
131 w.buf = append(w.buf, p...)
132 w.complete = false
133 return len(p), nil
134 }
135
136 frags := bytes.SplitN(p, newline, newlines+1)
137 if w.compact {
138 for i, frag := range frags {
139 if i > 0 {
140 w.buf = append(w.buf, ' ')
141 n++
142 }
143 w.buf = append(w.buf, frag...)
144 n += len(frag)
145 }
146 return n, nil
147 }
148
149 for i, frag := range frags {
150 if w.complete {
151 w.writeIndent()
152 }
153 w.buf = append(w.buf, frag...)
154 n += len(frag)
155 if i+1 < len(frags) {
156 w.buf = append(w.buf, '\n')
157 n++
158 }
159 }
160 w.complete = len(frags[len(frags)-1]) == 0
161 return n, nil
162}
163
164func (w *textWriter) WriteByte(c byte) error {
165 if w.compact && c == '\n' {

Callers 10

marshalMethod · 0.95
writeProto3AnyMethod · 0.95
writeSingularValueMethod · 0.95
writeUnknownFieldsMethod · 0.95
MarshalMethod · 0.45
generateMethod · 0.45
MarshalMethod · 0.45
json_test.goFile · 0.45

Calls 1

writeIndentMethod · 0.95