func (n *Number) format(i interface{}) (string, error) {
	base := n.Display().Base()
	if base < 2 || base > 36 {
		return "", &validationError{e: n, err: fmt.Errorf("invalid base %d", base)}
	}
	bits := int(reflect.ValueOf(i).Type().Size()) * 8
	return formatInt(i, base, bits)
}
format returns a formatted string of the given int. The int must be one of int{8,16,32,64} or
uint{8,16,32,64} types.
package ufwb
import (
	"encoding/hex"
	"fmt"
	"strings"
	"bytes"
	"io"
	"reflect"
)
var (
	indent = 0  
)
func leftPad(s string, pad string, width int) string {
	if len(s) >= width {
		return s
	}
	return strings.Repeat(pad, width-len(s)) + s
}
func (u *Ufwb) Format(file io.ReaderAt, value *Value) (string, error) {
	indent = 0
	return u.Grammar.Format(file, value)
}
func (p *Padding) Format(file io.ReaderAt, value *Value) (string, error) {
	return fmt.Sprintf("<padding len:%d>", value.Len), nil
}
func (g *Grammar) Format(file io.ReaderAt, value *Value) (string, error) {
	var buffer bytes.Buffer
	buffer.WriteString(g.Name())
	buffer.WriteString(": ")
	str, err := g.Start.Format(file, value)
	if err != nil {
		return "<format error>", err
	}
	buffer.WriteString(str)
	return buffer.String(), nil
}
func (n *Structure) Format(file io.ReaderAt, value *Value) (string, error) {
	indent++
	var buffer bytes.Buffer
	buffer.WriteString(fmt.Sprintf("(%d children)", len(value.Children)))
	buffer.WriteString("\n")
	pad := ""
	for i := 0; i < indent; i++ {
		pad += "  "
	}
	for i, child := range value.Children {
		buffer.WriteString(pad)
		buffer.WriteString(fmt.Sprintf("[%d] ", i))
		buffer.WriteString(child.Name())
		buffer.WriteString(": ")
		child.Format(file)
		value, err := child.Format(file)
		if err != nil {
			indent--
			return "<format error>", err
		}
		buffer.WriteString(strings.TrimSpace(value))
		buffer.WriteString("\n")
	}
	indent--
	return buffer.String(), nil
}
func (s *String) Format(file io.ReaderAt, value *Value) (string, error) {
	b := make([]byte, value.Len, value.Len)
	n, err := file.ReadAt(b, value.Offset)
	if err != nil {
		return string(b[:n]), &validationError{e: s, err: err}
	}
	switch s.Typ() {
	case "zero-terminated":
		if b[n-1] == 0 {
			return string(b[:n-1]), nil
		}
	case "pascal":
		panic("TODO pascal string format")
	}
	return string(b), nil
}