go-exif/v2/undefined/exif_iop_0002_interop_version.go
Dustin Oprea 32a5d88770 New integration of common/ and undefined/ subpackages
- common/type.go: Add FormatFromType() .
- Renamed common/type_encode.go to common/value_encoder.go .
2020-01-12 18:56:35 -05:00

66 lines
1.3 KiB
Go

package exifundefined
import (
"encoding/binary"
"github.com/dsoprea/go-logging"
"github.com/dsoprea/go-exif/v2/common"
)
type Tag0002InteropVersion struct {
string
}
func (Tag0002InteropVersion) EncoderName() string {
return "Codec0002InteropVersion"
}
func (iv Tag0002InteropVersion) String() string {
return iv.string
}
type Codec0002InteropVersion struct {
}
func (Codec0002InteropVersion) Encode(value interface{}, byteOrder binary.ByteOrder) (encoded []byte, unitCount uint32, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
s, ok := value.(Tag0002InteropVersion)
if ok == false {
log.Panicf("can only encode a Tag0002InteropVersion")
}
return []byte(s.string), uint32(len(s.string)), nil
}
func (Codec0002InteropVersion) Decode(valueContext *exifcommon.ValueContext) (value EncodeableValue, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
valueContext.SetUndefinedValueType(exifcommon.TypeAsciiNoNul)
valueString, err := valueContext.ReadAsciiNoNul()
log.PanicIf(err)
return Tag0002InteropVersion{valueString}, nil
}
func init() {
registerEncoder(
Tag0002InteropVersion{},
Codec0002InteropVersion{})
registerDecoder(
exifcommon.IfdPathStandardExifIop,
0x0002,
Codec0002InteropVersion{})
}