Documentation
¶
Overview ¶
Package dat implements parsing of XML dat files as commonly used by ROM/Disc preservation projects such as http://redump.org and https://no-intro.org. The DTD supports more elements but currently just the minimal subset used by these two projects are implemented.
It has the facility to mark a ROM as matched/found and so when the File is marshalled back to XML, any such ROMs are not included in the output. This means if all of the ROMs for a particular Game are matched, that Game will not be included at all in the output and consequently if all ROMs for all Games are matched, no XML will be output at all for the entire File.
An example:
import ( "encoding/xml" "os" "github.com/bodgit/rom/dat" ) func main() { b, err := os.ReadFile(os.Args[1]) if err != nil { panic(err) } f := new(dat.File) if err := xml.Unmarshal(b, f); err != nil { panic(err) } // Mark the first ROM of the first Game as matched f.Game[0].ROM[0].Matched() b, err = xml.MarshalIndent(f, "", "\t") if err != nil { panic(err) } fmt.Println(string(b)) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct { XMLName xml.Name `xml:"datafile"` Header Header `xml:"header"` Game []Game `xml:"game"` }
File represents the whole XML dat file. It consists of one Header followed zero or more Games
func (*File) MarshalXML ¶
MarshalXML is required by the xml.Marshaler interface. It encodes the File as XML if at least one of its Games has at least one ROM that has not been matched
type Game ¶
type Game struct { XMLName xml.Name `xml:"game"` Name string `xml:"name,attr"` Category string `xml:"category"` Description string `xml:"description"` ROM []ROM `xml:"rom"` }
Game represents one game within an XML dat file. It contains zero or more ROMs
type Header ¶
type Header struct { XMLName xml.Name `xml:"header"` Name string `xml:"name"` Description string `xml:"description"` Version string `xml:"version"` Date string `xml:"date"` Author string `xml:"author"` Homepage string `xml:"homepage"` URL string `xml:"url"` }
Header represents the header section in the XML dat file
type ROM ¶
type ROM struct { XMLName xml.Name `xml:"rom"` Name string `xml:"name,attr"` Size uint64 `xml:"size,attr"` CRC32 string `xml:"crc,attr"` MD5 string `xml:"md5,attr"` SHA1 string `xml:"sha1,attr"` // contains filtered or unexported fields }
ROM represents one ROM within an XML dat file
func (*ROM) Checksum ¶
Checksum returns the correct checksum value based on the requested checksum type
func (*ROM) MarshalXML ¶
MarshalXML is required by the xml.Marshaler interface. It encodes the ROM as XML if the ROM has not been matched
Notes ¶
Bugs ¶
Due to how encoding/xml works, <rom> elements are not marshalled as self-closing