schnutibox/vendor/github.com/jhump/protoreflect/dynamic/indent.go
Marvin Steadfast ae35d9ab41
Some checks failed
continuous-integration/drone/push Build is failing
uses buf for compiling proto files and implements the server service
2021-05-05 11:14:17 +02:00

77 lines
1.1 KiB
Go

package dynamic
import "bytes"
type indentBuffer struct {
bytes.Buffer
indent string
indentCount int
comma bool
}
func (b *indentBuffer) start() error {
if b.indentCount >= 0 {
b.indentCount++
return b.newLine(false)
}
return nil
}
func (b *indentBuffer) sep() error {
if b.indentCount >= 0 {
_, err := b.WriteString(": ")
return err
} else {
return b.WriteByte(':')
}
}
func (b *indentBuffer) end() error {
if b.indentCount >= 0 {
b.indentCount--
return b.newLine(false)
}
return nil
}
func (b *indentBuffer) maybeNext(first *bool) error {
if *first {
*first = false
return nil
} else {
return b.next()
}
}
func (b *indentBuffer) next() error {
if b.indentCount >= 0 {
return b.newLine(b.comma)
} else if b.comma {
return b.WriteByte(',')
} else {
return b.WriteByte(' ')
}
}
func (b *indentBuffer) newLine(comma bool) error {
if comma {
err := b.WriteByte(',')
if err != nil {
return err
}
}
err := b.WriteByte('\n')
if err != nil {
return err
}
for i := 0; i < b.indentCount; i++ {
_, err := b.WriteString(b.indent)
if err != nil {
return err
}
}
return nil
}