dat

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0

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

func (f *File) MarshalXML(e *xml.Encoder, start xml.StartElement) error

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

func (*File) Reset

func (f *File) Reset()

Reset returns each Game within File f back to its original state

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

func (*Game) Matched

func (g *Game) Matched()

Matched marks Game g as found in some external repository. By doing this it will not be marshalled back into XML

func (*Game) Reset

func (g *Game) Reset()

Reset returns each ROM used by Game g back to its original state

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

func (r *ROM) Checksum(t rom.Checksum) string

Checksum returns the correct checksum value based on the requested checksum type

func (*ROM) MarshalXML

func (r *ROM) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML is required by the xml.Marshaler interface. It encodes the ROM as XML if the ROM has not been matched

func (*ROM) Matched

func (r *ROM) Matched()

Matched marks ROM r as found in some external repository. By doing this it will not be marshalled back into XML

func (*ROM) Reset

func (r *ROM) Reset()

Reset returns ROM r to its original state such that it will be marshalled back into XML

Notes

Bugs

  • Due to how encoding/xml works, <rom> elements are not marshalled as self-closing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL