Skip to content

Commit ac2d26f

Browse files
committed
Use stringParts as suggested in review
1 parent 085c631 commit ac2d26f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

serialization/serialization.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Message struct {
2323

2424
func (m *Message) String() (text string) {
2525
text += fmt.Sprintf("Message (version: %d)", m.Version)
26-
for _, line := range strings.Split(m.Format.String(), "\n") {
26+
for _, line := range m.Format.stringParts() {
2727
text += "\n " + line
2828
}
2929
return
@@ -45,16 +45,22 @@ type Format struct {
4545
}
4646

4747
func (f *Format) String() (text string) {
48-
text += fmt.Sprintf("Format (Size: %d, LastNonIgnorableField: %d)\n",
49-
f.Size, f.LastNonIgnorableField)
48+
return strings.Join(f.stringParts(), "\n")
49+
}
50+
51+
func (f *Format) stringParts() (parts []string) {
52+
53+
parts = append(parts, fmt.Sprintf("Format (Size: %d, LastNonIgnorableField: %d)",
54+
f.Size, f.LastNonIgnorableField))
55+
5056
for _, f := range f.Fields {
51-
text += fmt.Sprintf("Field %02d (Name: %s, Skipped: %t, Type: %T)\n",
52-
f.ID, f.Name, f.Skipped, f.Type)
57+
parts = append(parts, fmt.Sprintf("Field %02d (Name: %s, Skipped: %t, Type: %T)",
58+
f.ID, f.Name, f.Skipped, f.Type))
5359
if f.Type != nil {
54-
text += fmt.Sprintf(" Value: %s\n", f.Type.String())
60+
parts = append(parts, fmt.Sprintf(" Value: %s", f.Type.String()))
5561
}
5662
}
57-
return text
63+
return
5864
}
5965

6066
// Field represents a `message_field`

0 commit comments

Comments
 (0)