MusicXML icon indicating copy to clipboard operation
MusicXML copied to clipboard

Create a MusicXMLDecoder: XMLDecoder subclass

Open jsbean opened this issue 5 years ago • 2 comments

Now that we are disabling .trimValueWhitespaces from our decoder, it may make sense to create an XMLDecoder subclass MusicXMLDecoder.

This way we can use MusicXMLDecoder when testing atomic units, so we know we are working with the same thing when decoding a whole MusicXML object.

This will also allow us to wipe XMLCoder from testing, which has seemed slightly out of place.

jsbean avatar Oct 16 '19 21:10 jsbean

(This could also be made symmetrical as MusicXMLEncoder.)

jsbean avatar Oct 16 '19 21:10 jsbean

We could also tighten up the API a little, because we know we are always dealing with .utf8:

extension MusicXMLDecoder {
    func decode <T> (_ type: T.Type, from string: String) throws -> T where T: Decodable {
        return try decode(type, string.data(using: utf8)!)
    }
}

jsbean avatar Oct 16 '19 22:10 jsbean