github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/format/internal/cyclonedxutil/helpers/properties.go (about) 1 package helpers 2 3 import ( 4 "strings" 5 6 "github.com/CycloneDX/cyclonedx-go" 7 ) 8 9 var ( 10 CycloneDXFields = RequiredTag("cyclonedx") 11 ) 12 13 func EncodeProperties(obj interface{}, prefix string) (out []cyclonedx.Property) { 14 for _, p := range Sorted(Encode(obj, prefix, CycloneDXFields)) { 15 out = append(out, cyclonedx.Property{ 16 Name: p.Name, 17 Value: p.Value, 18 }) 19 } 20 return 21 } 22 23 func decodeProperties(properties []cyclonedx.Property, prefix string) map[string]string { 24 labels := make(map[string]string) 25 for _, property := range properties { 26 if strings.HasPrefix(property.Name, prefix) { 27 labelName := strings.TrimPrefix(property.Name, prefix) 28 labels[labelName] = property.Value 29 } 30 } 31 return labels 32 }