~emersion/drmdb

02f28664e23d474b2290382775d2d84683891a53 — Simon Ser 1 year, 1 month ago 6f22b95
Pretty-print enums spec
2 files changed, 22 insertions(+), 19 deletions(-)

M cmd/drmdump/main.go
M drmtree/drmtree.go
M cmd/drmdump/main.go => cmd/drmdump/main.go +2 -2
@@ 190,9 190,9 @@ func properties(n *drm.Node, id drm.AnyID) (map[string]drmtree.Property, error) 
			spec = &drmtree.PropertySpecRange{Min: min, Max: max}
		case drm.PropertyEnum, drm.PropertyBitmask:
			enums, _ := prop.Enums()
			l := make([]drmtree.PropertySpecEnum, len(enums))
			l := make(drmtree.PropertySpecEnum, len(enums))
			for i, e := range enums {
				l[i] = drmtree.PropertySpecEnum(e)
				l[i] = drmtree.PropertySpecEnumEntry(e)
			}
			spec = l
		case drm.PropertyObject:

M drmtree/drmtree.go => drmtree/drmtree.go +20 -17
@@ 229,11 229,25 @@ type PlaneInFormatsModifier struct {
	Formats  []drm.Format `json:"formats"`
}

type PropertySpecEnum struct {
type PropertySpecEnumEntry struct {
	Name  string `json:"name"`
	Value uint64 `json:"value"`
}

func (spec *PropertySpecEnumEntry) String() string {
	return fmt.Sprintf("%q (0x%X)", spec.Name, spec.Value)
}

type PropertySpecEnum []PropertySpecEnumEntry

func (spec PropertySpecEnum) String() string {
	l := make([]string, len(spec))
	for i, e := range spec {
		l[i] = fmt.Sprintf("%q", e.Name)
	}
	return "{" + strings.Join(l, ", ") + "}"
}

type PropertySpecRange struct {
	Min uint64 `json:"min"`
	Max uint64 `json:"max`


@@ 293,7 307,7 @@ func (prop *Property) UnmarshalJSON(b []byte) error {
			err = json.Unmarshal(rawSpec, &spec)
			rawProp.Spec = &spec
		case drm.PropertyEnum, drm.PropertyBitmask:
			var spec []PropertySpecEnum
			var spec PropertySpecEnum
			err = json.Unmarshal(rawSpec, &spec)
			rawProp.Spec = spec
		case drm.PropertyObject:


@@ 416,19 430,8 @@ func (m *PropertyMap) FormatTree(tf treefmt.Formatter) {
		s += ": " + prop.Type.String()

		var specStr string
		switch spec := prop.Spec.(type) {
		case *PropertySpecRange:
			specStr = spec.String()
		case []PropertySpecEnum:
			var names []string
			for _, e := range spec {
				names = append(names, e.Name)
			}
			specStr = "{" + strings.Join(names, ", ") + "}"
		case drm.ObjectType:
			specStr = spec.String()
		case *PropertySpecSignedRange:
			specStr = spec.String()
		if s, ok := prop.Spec.(fmt.Stringer); ok {
			specStr = s.String()
		}
		if specStr != "" {
			s += " " + specStr


@@ 459,7 462,7 @@ func (m *PropertyMap) FormatTree(tf treefmt.Formatter) {
			switch prop.Type {
			case drm.PropertyEnum:
				u := val.(uint64)
				entries := prop.Spec.([]PropertySpecEnum)
				entries := prop.Spec.(PropertySpecEnum)
				val = "<invalid>"
				for _, e := range entries {
					if e.Value == u {


@@ 469,7 472,7 @@ func (m *PropertyMap) FormatTree(tf treefmt.Formatter) {
				}
			case drm.PropertyBitmask:
				u := val.(uint64)
				entries := prop.Spec.([]PropertySpecEnum)
				entries := prop.Spec.(PropertySpecEnum)
				var names []string
				for _, e := range entries {
					if e.Value&u == e.Value {