On Thu, Aug 15, 2019, at 22:35, Nigel Tao wrote:
> That does have its benefits, but IIUC, as I said, that'll make "image"
> transitively depend on "encoding/xml". Also, "union... of the
> implementations" is a tricky concept. One of the purposes of the image
> package is that third parties can define their own codecs, which could
> have their own metadata.
Does this mean that metadata is always decoded immediately when decoding
the image? I'd probably prefer to decode it later (if at all), or first
(and then only decode the image under certain circumstances but not have
to decode the metadata all over again) if possible. I wonder if it would
be better to just keep metadata as raw bytes (or a reader so that
implementations could decide whether to buffer or point directly into
the file for as long as it was still open) and maybe a marker type for
what type of metadata was discovered.
Then if you get eg. PNG metadata out that can have its own field for XMP
or EXIF metadata bytes and the PNG package can have functionality for
decoding the PNG metadata into a struct and the metadata/xmp package can
have structs for use with the encoding/xml package.
Eg.
type RGBA struct {
…
Metadata []byte
Type MetadataType
}
// This could just be a string constant that varies by package,
// or it could be a key that you you type switch on similar to
// context keys so that we know there are no conflicts, or we could
// just leave it out entirely and assume that if you decode an image
// with the PNG package you have to remember what type its metadata
// is likely to be.
type MetadataType interface{}
switch myImage.Type.(type) {
case xmp.MetadataKey:
xmpMetadata, err := xmp.Decode(myImage.Metadata)
…
case png.MetadataKey:
…
}
This also means we don't have to use the "registration" pattern for
metadata which I personally don't like (and means we don't have to
iterate over all registered metadata types if the user already knows
what type its going to be).
—Sam
--
Sam Whited