text.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. // Extensions for Protocol Buffers to create more go like structures.
  2. //
  3. // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
  4. // http://code.google.com/p/gogoprotobuf/gogoproto
  5. //
  6. // Go support for Protocol Buffers - Google's data interchange format
  7. //
  8. // Copyright 2010 The Go Authors. All rights reserved.
  9. // http://code.google.com/p/goprotobuf/
  10. //
  11. // Redistribution and use in source and binary forms, with or without
  12. // modification, are permitted provided that the following conditions are
  13. // met:
  14. //
  15. // * Redistributions of source code must retain the above copyright
  16. // notice, this list of conditions and the following disclaimer.
  17. // * Redistributions in binary form must reproduce the above
  18. // copyright notice, this list of conditions and the following disclaimer
  19. // in the documentation and/or other materials provided with the
  20. // distribution.
  21. // * Neither the name of Google Inc. nor the names of its
  22. // contributors may be used to endorse or promote products derived from
  23. // this software without specific prior written permission.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. package proto
  37. // Functions for writing the text protocol buffer format.
  38. import (
  39. "bufio"
  40. "bytes"
  41. "fmt"
  42. "io"
  43. "log"
  44. "math"
  45. "os"
  46. "reflect"
  47. "sort"
  48. "strings"
  49. )
  50. var (
  51. newline = []byte("\n")
  52. spaces = []byte(" ")
  53. gtNewline = []byte(">\n")
  54. endBraceNewline = []byte("}\n")
  55. backslashN = []byte{'\\', 'n'}
  56. backslashR = []byte{'\\', 'r'}
  57. backslashT = []byte{'\\', 't'}
  58. backslashDQ = []byte{'\\', '"'}
  59. backslashBS = []byte{'\\', '\\'}
  60. posInf = []byte("inf")
  61. negInf = []byte("-inf")
  62. nan = []byte("nan")
  63. )
  64. type writer interface {
  65. io.Writer
  66. WriteByte(byte) error
  67. }
  68. // textWriter is an io.Writer that tracks its indentation level.
  69. type textWriter struct {
  70. ind int
  71. complete bool // if the current position is a complete line
  72. compact bool // whether to write out as a one-liner
  73. w writer
  74. }
  75. // textMarshaler is implemented by Messages that can marshal themsleves.
  76. // It is identical to encoding.TextMarshaler, introduced in go 1.2,
  77. // which will eventually replace it.
  78. type textMarshaler interface {
  79. MarshalText() (text []byte, err error)
  80. }
  81. func (w *textWriter) WriteString(s string) (n int, err error) {
  82. if !strings.Contains(s, "\n") {
  83. if !w.compact && w.complete {
  84. w.writeIndent()
  85. }
  86. w.complete = false
  87. return io.WriteString(w.w, s)
  88. }
  89. // WriteString is typically called without newlines, so this
  90. // codepath and its copy are rare. We copy to avoid
  91. // duplicating all of Write's logic here.
  92. return w.Write([]byte(s))
  93. }
  94. func (w *textWriter) Write(p []byte) (n int, err error) {
  95. newlines := bytes.Count(p, newline)
  96. if newlines == 0 {
  97. if !w.compact && w.complete {
  98. w.writeIndent()
  99. }
  100. n, err = w.w.Write(p)
  101. w.complete = false
  102. return n, err
  103. }
  104. frags := bytes.SplitN(p, newline, newlines+1)
  105. if w.compact {
  106. for i, frag := range frags {
  107. if i > 0 {
  108. if err := w.w.WriteByte(' '); err != nil {
  109. return n, err
  110. }
  111. n++
  112. }
  113. nn, err := w.w.Write(frag)
  114. n += nn
  115. if err != nil {
  116. return n, err
  117. }
  118. }
  119. return n, nil
  120. }
  121. for i, frag := range frags {
  122. if w.complete {
  123. w.writeIndent()
  124. }
  125. nn, err := w.w.Write(frag)
  126. n += nn
  127. if err != nil {
  128. return n, err
  129. }
  130. if i+1 < len(frags) {
  131. if err := w.w.WriteByte('\n'); err != nil {
  132. return n, err
  133. }
  134. n++
  135. }
  136. }
  137. w.complete = len(frags[len(frags)-1]) == 0
  138. return n, nil
  139. }
  140. func (w *textWriter) WriteByte(c byte) error {
  141. if w.compact && c == '\n' {
  142. c = ' '
  143. }
  144. if !w.compact && w.complete {
  145. w.writeIndent()
  146. }
  147. err := w.w.WriteByte(c)
  148. w.complete = c == '\n'
  149. return err
  150. }
  151. func (w *textWriter) indent() { w.ind++ }
  152. func (w *textWriter) unindent() {
  153. if w.ind == 0 {
  154. log.Printf("proto: textWriter unindented too far")
  155. return
  156. }
  157. w.ind--
  158. }
  159. func writeName(w *textWriter, props *Properties) error {
  160. if _, err := w.WriteString(props.OrigName); err != nil {
  161. return err
  162. }
  163. if props.Wire != "group" {
  164. return w.WriteByte(':')
  165. }
  166. return nil
  167. }
  168. var (
  169. messageSetType = reflect.TypeOf((*MessageSet)(nil)).Elem()
  170. )
  171. // raw is the interface satisfied by RawMessage.
  172. type raw interface {
  173. Bytes() []byte
  174. }
  175. func writeStruct(w *textWriter, sv reflect.Value) error {
  176. if sv.Type() == messageSetType {
  177. return writeMessageSet(w, sv.Addr().Interface().(*MessageSet))
  178. }
  179. st := sv.Type()
  180. sprops := GetProperties(st)
  181. for i := 0; i < sv.NumField(); i++ {
  182. fv := sv.Field(i)
  183. props := sprops.Prop[i]
  184. name := st.Field(i).Name
  185. if strings.HasPrefix(name, "XXX_") {
  186. // There are two XXX_ fields:
  187. // XXX_unrecognized []byte
  188. // XXX_extensions map[int32]proto.Extension
  189. // The first is handled here;
  190. // the second is handled at the bottom of this function.
  191. if name == "XXX_unrecognized" && !fv.IsNil() {
  192. if err := writeUnknownStruct(w, fv.Interface().([]byte)); err != nil {
  193. return err
  194. }
  195. }
  196. continue
  197. }
  198. if fv.Kind() == reflect.Ptr && fv.IsNil() {
  199. // Field not filled in. This could be an optional field or
  200. // a required field that wasn't filled in. Either way, there
  201. // isn't anything we can show for it.
  202. continue
  203. }
  204. if fv.Kind() == reflect.Slice && fv.IsNil() {
  205. // Repeated field that is empty, or a bytes field that is unused.
  206. continue
  207. }
  208. if props.Repeated && fv.Kind() == reflect.Slice {
  209. // Repeated field.
  210. for j := 0; j < fv.Len(); j++ {
  211. if err := writeName(w, props); err != nil {
  212. return err
  213. }
  214. if !w.compact {
  215. if err := w.WriteByte(' '); err != nil {
  216. return err
  217. }
  218. }
  219. if len(props.Enum) > 0 {
  220. if err := writeEnum(w, fv.Index(j), props); err != nil {
  221. return err
  222. }
  223. } else if err := writeAny(w, fv.Index(j), props); err != nil {
  224. return err
  225. }
  226. if err := w.WriteByte('\n'); err != nil {
  227. return err
  228. }
  229. }
  230. continue
  231. }
  232. if err := writeName(w, props); err != nil {
  233. return err
  234. }
  235. if !w.compact {
  236. if err := w.WriteByte(' '); err != nil {
  237. return err
  238. }
  239. }
  240. if b, ok := fv.Interface().(raw); ok {
  241. if err := writeRaw(w, b.Bytes()); err != nil {
  242. return err
  243. }
  244. continue
  245. }
  246. if len(props.Enum) > 0 {
  247. if err := writeEnum(w, fv, props); err != nil {
  248. return err
  249. }
  250. } else if err := writeAny(w, fv, props); err != nil {
  251. return err
  252. }
  253. if err := w.WriteByte('\n'); err != nil {
  254. return err
  255. }
  256. }
  257. // Extensions (the XXX_extensions field).
  258. pv := sv.Addr()
  259. if pv.Type().Implements(extendableProtoType) {
  260. if err := writeExtensions(w, pv); err != nil {
  261. return err
  262. }
  263. }
  264. return nil
  265. }
  266. // writeRaw writes an uninterpreted raw message.
  267. func writeRaw(w *textWriter, b []byte) error {
  268. if err := w.WriteByte('<'); err != nil {
  269. return err
  270. }
  271. if !w.compact {
  272. if err := w.WriteByte('\n'); err != nil {
  273. return err
  274. }
  275. }
  276. w.indent()
  277. if err := writeUnknownStruct(w, b); err != nil {
  278. return err
  279. }
  280. w.unindent()
  281. if err := w.WriteByte('>'); err != nil {
  282. return err
  283. }
  284. return nil
  285. }
  286. // writeAny writes an arbitrary field.
  287. func writeAny(w *textWriter, v reflect.Value, props *Properties) error {
  288. v = reflect.Indirect(v)
  289. if props != nil && len(props.CustomType) > 0 {
  290. var custom Marshaler = v.Interface().(Marshaler)
  291. data, err := custom.Marshal()
  292. if err != nil {
  293. return err
  294. }
  295. if err := writeString(w, string(data)); err != nil {
  296. return err
  297. }
  298. return nil
  299. }
  300. // Floats have special cases.
  301. if v.Kind() == reflect.Float32 || v.Kind() == reflect.Float64 {
  302. x := v.Float()
  303. var b []byte
  304. switch {
  305. case math.IsInf(x, 1):
  306. b = posInf
  307. case math.IsInf(x, -1):
  308. b = negInf
  309. case math.IsNaN(x):
  310. b = nan
  311. }
  312. if b != nil {
  313. _, err := w.Write(b)
  314. return err
  315. }
  316. // Other values are handled below.
  317. }
  318. // We don't attempt to serialise every possible value type; only those
  319. // that can occur in protocol buffers.
  320. switch v.Kind() {
  321. case reflect.Slice:
  322. // Should only be a []byte; repeated fields are handled in writeStruct.
  323. if err := writeString(w, string(v.Interface().([]byte))); err != nil {
  324. return err
  325. }
  326. case reflect.String:
  327. if err := writeString(w, v.String()); err != nil {
  328. return err
  329. }
  330. case reflect.Struct:
  331. // Required/optional group/message.
  332. var bra, ket byte = '<', '>'
  333. if props != nil && props.Wire == "group" {
  334. bra, ket = '{', '}'
  335. }
  336. if err := w.WriteByte(bra); err != nil {
  337. return err
  338. }
  339. if !w.compact {
  340. if err := w.WriteByte('\n'); err != nil {
  341. return err
  342. }
  343. }
  344. w.indent()
  345. if tm, ok := v.Interface().(textMarshaler); ok {
  346. text, err := tm.MarshalText()
  347. if err != nil {
  348. return err
  349. }
  350. if _, err = w.Write(text); err != nil {
  351. return err
  352. }
  353. } else if err := writeStruct(w, v); err != nil {
  354. return err
  355. }
  356. w.unindent()
  357. if err := w.WriteByte(ket); err != nil {
  358. return err
  359. }
  360. default:
  361. _, err := fmt.Fprint(w, v.Interface())
  362. return err
  363. }
  364. return nil
  365. }
  366. // equivalent to C's isprint.
  367. func isprint(c byte) bool {
  368. return c >= 0x20 && c < 0x7f
  369. }
  370. // writeString writes a string in the protocol buffer text format.
  371. // It is similar to strconv.Quote except we don't use Go escape sequences,
  372. // we treat the string as a byte sequence, and we use octal escapes.
  373. // These differences are to maintain interoperability with the other
  374. // languages' implementations of the text format.
  375. func writeString(w *textWriter, s string) error {
  376. // use WriteByte here to get any needed indent
  377. if err := w.WriteByte('"'); err != nil {
  378. return err
  379. }
  380. // Loop over the bytes, not the runes.
  381. for i := 0; i < len(s); i++ {
  382. var err error
  383. // Divergence from C++: we don't escape apostrophes.
  384. // There's no need to escape them, and the C++ parser
  385. // copes with a naked apostrophe.
  386. switch c := s[i]; c {
  387. case '\n':
  388. _, err = w.w.Write(backslashN)
  389. case '\r':
  390. _, err = w.w.Write(backslashR)
  391. case '\t':
  392. _, err = w.w.Write(backslashT)
  393. case '"':
  394. _, err = w.w.Write(backslashDQ)
  395. case '\\':
  396. _, err = w.w.Write(backslashBS)
  397. default:
  398. if isprint(c) {
  399. err = w.w.WriteByte(c)
  400. } else {
  401. _, err = fmt.Fprintf(w.w, "\\%03o", c)
  402. }
  403. }
  404. if err != nil {
  405. return err
  406. }
  407. }
  408. return w.WriteByte('"')
  409. }
  410. func writeMessageSet(w *textWriter, ms *MessageSet) error {
  411. for _, item := range ms.Item {
  412. id := *item.TypeId
  413. if msd, ok := messageSetMap[id]; ok {
  414. // Known message set type.
  415. if _, err := fmt.Fprintf(w, "[%s]: <\n", msd.name); err != nil {
  416. return err
  417. }
  418. w.indent()
  419. pb := reflect.New(msd.t.Elem())
  420. if err := Unmarshal(item.Message, pb.Interface().(Message)); err != nil {
  421. if _, err := fmt.Fprintf(w, "/* bad message: %v */\n", err); err != nil {
  422. return err
  423. }
  424. } else {
  425. if err := writeStruct(w, pb.Elem()); err != nil {
  426. return err
  427. }
  428. }
  429. } else {
  430. // Unknown type.
  431. if _, err := fmt.Fprintf(w, "[%d]: <\n", id); err != nil {
  432. return err
  433. }
  434. w.indent()
  435. if err := writeUnknownStruct(w, item.Message); err != nil {
  436. return err
  437. }
  438. }
  439. w.unindent()
  440. if _, err := w.Write(gtNewline); err != nil {
  441. return err
  442. }
  443. }
  444. return nil
  445. }
  446. func writeUnknownStruct(w *textWriter, data []byte) (err error) {
  447. if !w.compact {
  448. if _, err := fmt.Fprintf(w, "/* %d unknown bytes */\n", len(data)); err != nil {
  449. return err
  450. }
  451. }
  452. b := NewBuffer(data)
  453. for b.index < len(b.buf) {
  454. x, err := b.DecodeVarint()
  455. if err != nil {
  456. _, err := fmt.Fprintf(w, "/* %v */\n", err)
  457. return err
  458. }
  459. wire, tag := x&7, x>>3
  460. if wire == WireEndGroup {
  461. w.unindent()
  462. if _, err := w.Write(endBraceNewline); err != nil {
  463. return err
  464. }
  465. continue
  466. }
  467. if _, err := fmt.Fprint(w, tag); err != nil {
  468. return err
  469. }
  470. if wire != WireStartGroup {
  471. if err := w.WriteByte(':'); err != nil {
  472. return err
  473. }
  474. }
  475. if !w.compact || wire == WireStartGroup {
  476. if err := w.WriteByte(' '); err != nil {
  477. return err
  478. }
  479. }
  480. switch wire {
  481. case WireBytes:
  482. buf, e := b.DecodeRawBytes(false)
  483. if e == nil {
  484. _, err = fmt.Fprintf(w, "%q", buf)
  485. } else {
  486. _, err = fmt.Fprintf(w, "/* %v */", e)
  487. }
  488. case WireFixed32:
  489. x, err = b.DecodeFixed32()
  490. err = writeUnknownInt(w, x, err)
  491. case WireFixed64:
  492. x, err = b.DecodeFixed64()
  493. err = writeUnknownInt(w, x, err)
  494. case WireStartGroup:
  495. err = w.WriteByte('{')
  496. w.indent()
  497. case WireVarint:
  498. x, err = b.DecodeVarint()
  499. err = writeUnknownInt(w, x, err)
  500. default:
  501. _, err = fmt.Fprintf(w, "/* unknown wire type %d */", wire)
  502. }
  503. if err != nil {
  504. return err
  505. }
  506. if err = w.WriteByte('\n'); err != nil {
  507. return err
  508. }
  509. }
  510. return nil
  511. }
  512. func writeUnknownInt(w *textWriter, x uint64, err error) error {
  513. if err == nil {
  514. _, err = fmt.Fprint(w, x)
  515. } else {
  516. _, err = fmt.Fprintf(w, "/* %v */", err)
  517. }
  518. return err
  519. }
  520. type int32Slice []int32
  521. func (s int32Slice) Len() int { return len(s) }
  522. func (s int32Slice) Less(i, j int) bool { return s[i] < s[j] }
  523. func (s int32Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
  524. // writeExtensions writes all the extensions in pv.
  525. // pv is assumed to be a pointer to a protocol message struct that is extendable.
  526. func writeExtensions(w *textWriter, pv reflect.Value) error {
  527. emap := extensionMaps[pv.Type().Elem()]
  528. ep := pv.Interface().(extendableProto)
  529. // Order the extensions by ID.
  530. // This isn't strictly necessary, but it will give us
  531. // canonical output, which will also make testing easier.
  532. var m map[int32]Extension
  533. if em, ok := ep.(extensionsMap); ok {
  534. m = em.ExtensionMap()
  535. } else if em, ok := ep.(extensionsBytes); ok {
  536. eb := em.GetExtensions()
  537. var err error
  538. m, err = BytesToExtensionsMap(*eb)
  539. if err != nil {
  540. return err
  541. }
  542. }
  543. ids := make([]int32, 0, len(m))
  544. for id := range m {
  545. ids = append(ids, id)
  546. }
  547. sort.Sort(int32Slice(ids))
  548. for _, extNum := range ids {
  549. ext := m[extNum]
  550. var desc *ExtensionDesc
  551. if emap != nil {
  552. desc = emap[extNum]
  553. }
  554. if desc == nil {
  555. // Unknown extension.
  556. if err := writeUnknownStruct(w, ext.enc); err != nil {
  557. return err
  558. }
  559. continue
  560. }
  561. pb, err := GetExtension(ep, desc)
  562. if err != nil {
  563. if _, err := fmt.Fprintln(os.Stderr, "proto: failed getting extension: ", err); err != nil {
  564. return err
  565. }
  566. continue
  567. }
  568. // Repeated extensions will appear as a slice.
  569. if !desc.repeated() {
  570. if err := writeExtension(w, desc.Name, pb); err != nil {
  571. return err
  572. }
  573. } else {
  574. v := reflect.ValueOf(pb)
  575. for i := 0; i < v.Len(); i++ {
  576. if err := writeExtension(w, desc.Name, v.Index(i).Interface()); err != nil {
  577. return err
  578. }
  579. }
  580. }
  581. }
  582. return nil
  583. }
  584. func writeExtension(w *textWriter, name string, pb interface{}) error {
  585. if _, err := fmt.Fprintf(w, "[%s]:", name); err != nil {
  586. return err
  587. }
  588. if !w.compact {
  589. if err := w.WriteByte(' '); err != nil {
  590. return err
  591. }
  592. }
  593. if err := writeAny(w, reflect.ValueOf(pb), nil); err != nil {
  594. return err
  595. }
  596. if err := w.WriteByte('\n'); err != nil {
  597. return err
  598. }
  599. return nil
  600. }
  601. func (w *textWriter) writeIndent() {
  602. if !w.complete {
  603. return
  604. }
  605. remain := w.ind * 2
  606. for remain > 0 {
  607. n := remain
  608. if n > len(spaces) {
  609. n = len(spaces)
  610. }
  611. w.w.Write(spaces[:n])
  612. remain -= n
  613. }
  614. w.complete = false
  615. }
  616. func marshalText(w io.Writer, pb Message, compact bool) error {
  617. val := reflect.ValueOf(pb)
  618. if pb == nil || val.IsNil() {
  619. w.Write([]byte("<nil>"))
  620. return nil
  621. }
  622. var bw *bufio.Writer
  623. ww, ok := w.(writer)
  624. if !ok {
  625. bw = bufio.NewWriter(w)
  626. ww = bw
  627. }
  628. aw := &textWriter{
  629. w: ww,
  630. complete: true,
  631. compact: compact,
  632. }
  633. if tm, ok := pb.(textMarshaler); ok {
  634. text, err := tm.MarshalText()
  635. if err != nil {
  636. return err
  637. }
  638. if _, err = aw.Write(text); err != nil {
  639. return err
  640. }
  641. if bw != nil {
  642. return bw.Flush()
  643. }
  644. return nil
  645. }
  646. // Dereference the received pointer so we don't have outer < and >.
  647. v := reflect.Indirect(val)
  648. if err := writeStruct(aw, v); err != nil {
  649. return err
  650. }
  651. if bw != nil {
  652. return bw.Flush()
  653. }
  654. return nil
  655. }
  656. // MarshalText writes a given protocol buffer in text format.
  657. // The only errors returned are from w.
  658. func MarshalText(w io.Writer, pb Message) error {
  659. return marshalText(w, pb, false)
  660. }
  661. // MarshalTextString is the same as MarshalText, but returns the string directly.
  662. func MarshalTextString(pb Message) string {
  663. var buf bytes.Buffer
  664. marshalText(&buf, pb, false)
  665. return buf.String()
  666. }
  667. // CompactText writes a given protocol buffer in compact text format (one line).
  668. func CompactText(w io.Writer, pb Message) error { return marshalText(w, pb, true) }
  669. // CompactTextString is the same as CompactText, but returns the string directly.
  670. func CompactTextString(pb Message) string {
  671. var buf bytes.Buffer
  672. marshalText(&buf, pb, true)
  673. return buf.String()
  674. }