github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/dt/print.go (about)

     1  // Copyright 2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package dt
     6  
     7  import (
     8  	"errors"
     9  	"fmt"
    10  	"io"
    11  )
    12  
    13  // PrintDTS prints the FDT in the .dts format.
    14  // TODO: not yet implemented
    15  func (fdt *FDT) PrintDTS(f io.Writer) error {
    16  	return errors.New("not yet implemented")
    17  }
    18  
    19  // String implements String() for an FDT
    20  func (fdt *FDT) String() string {
    21  	return fmt.Sprintf("%#04x %s", fdt.Header, fdt.RootNode)
    22  }
    23  
    24  func (p *Property) String() string {
    25  	var more string
    26  	l := len(p.Value)
    27  	if l > 64 {
    28  		more = "..."
    29  		l = 64
    30  	}
    31  	return fmt.Sprintf("%s[%#02x]%q{%#x}%s", p.Name, len(p.Value), p.Value[:l], p.Value[:l], more)
    32  }
    33  
    34  func (n *Node) String() string {
    35  	var s string
    36  	var indent string
    37  	n.Walk(func(n *Node) error {
    38  		i := indent
    39  		indent += "\t"
    40  		s += fmt.Sprintf("%s%s: [", indent, n.Name)
    41  		for _, p := range n.Properties {
    42  			s += fmt.Sprintf("%s, ", &p)
    43  		}
    44  		s += "]\n"
    45  		indent = i
    46  		return nil
    47  	})
    48  	return s
    49  }