Skip to content

Commit

Permalink
marc: add Unmarshal function
Browse files Browse the repository at this point in the history
  • Loading branch information
boutros committed Mar 11, 2019
1 parent 08ad549 commit c2ae81b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions marc/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ import (
"unicode/utf8"
)

func Unmarshal(b []byte, f Format, rec *Record) error {
switch f {
case MARCXML:
dec := Decoder{
xmlDec: xml.NewDecoder(bytes.NewBuffer(b)),
}
for {
t, err := dec.xmlDec.Token()
if err != nil {
return err
}
switch elem := t.(type) {
case xml.SyntaxError:
return errors.New(elem.Error())
case xml.StartElement:
if elem.Name.Local == "record" {
return dec.decodeMARCXMLRecord(rec)
}
}
}

default:
panic("Unmarshal: TODO")
}
}

// Decoder can decode MARC records from a stream, in one of the supported formats:
// MARCXML (ISO25577), LineMARC or Standard MARC (ISO2709)
type Decoder struct {
Expand Down

0 comments on commit c2ae81b

Please sign in to comment.