github.com/protolambda/zssz@v0.1.5/pretty/pretty.go (about)

     1  package pretty
     2  
     3  import (
     4  	"io"
     5  	"strings"
     6  	"unsafe"
     7  )
     8  
     9  type PrettyFn func(indent uint32, w *PrettyWriter, p unsafe.Pointer)
    10  
    11  type PrettyWriter struct {
    12  	w      io.Writer
    13  	indent string
    14  }
    15  
    16  func NewPrettyWriter(w io.Writer, indent string) *PrettyWriter {
    17  	return &PrettyWriter{w: w, indent: indent}
    18  }
    19  
    20  // Write writes len(p) bytes from p to the underlying accumulated buffer.
    21  func (pw *PrettyWriter) Write(p string) {
    22  	_, _ = pw.w.Write([]byte(p))
    23  }
    24  
    25  // Write writes len(p) bytes from p to the underlying accumulated buffer.
    26  func (pw *PrettyWriter) WriteIndent(indent uint32) {
    27  	pw.Write(strings.Repeat(pw.indent, int(indent)))
    28  }