-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/amd/manifest: marshal PSP entry type names
Signed-off-by: Daniel Maslowski <info@orangecms.org>
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package manifest | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
pspentries "github.com/orangecms/PSP-Entry-Types" | ||
) | ||
|
||
var knownTypes = pspentries.Types() | ||
|
||
func (t BIOSDirectoryTableEntryType) MarshalJSON() ([]byte, error) { | ||
for _, knownType := range knownTypes { | ||
if knownType.Type == uint32(t) { | ||
name := knownType.Name | ||
if name == "" { | ||
name = knownType.ProposedName | ||
} | ||
if name == "" { | ||
return json.Marshal(fmt.Sprintf("0x%x", t)) | ||
} | ||
return json.Marshal(name) | ||
} | ||
} | ||
return json.Marshal(fmt.Sprintf("0x%x", t)) | ||
} | ||
|
||
/* | ||
TODO: extend information, also for PSPDirectoryTableEntry | ||
func (e BIOSDirectoryTableEntry) MarshalJSON() json.RawMessage { | ||
info := TypeInfo{ | ||
Name: name, | ||
Comment: knownType.Comment, | ||
} | ||
entry.TypeInfo = &info | ||
} | ||
*/ | ||
|
||
func (t PSPDirectoryTableEntryType) MarshalJSON() ([]byte, error) { | ||
for _, knownType := range knownTypes { | ||
if knownType.Type == uint32(t) { | ||
name := knownType.Name | ||
if name == "" { | ||
name = knownType.ProposedName | ||
} | ||
if name == "" { | ||
return json.Marshal(fmt.Sprintf("0x%x", t)) | ||
} | ||
return json.Marshal(name) | ||
} | ||
} | ||
return json.Marshal(fmt.Sprintf("0x%x", t)) | ||
} |