| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 | package exifundefined
import (
	"encoding/binary"
	"github.com/dsoprea/go-logging"
	"github.com/dsoprea/go-exif/v3/common"
)
// Encode encodes the given encodeable undefined value to bytes.
func Encode(value EncodeableValue, byteOrder binary.ByteOrder) (encoded []byte, unitCount uint32, err error) {
	defer func() {
		if state := recover(); state != nil {
			err = log.Wrap(state.(error))
		}
	}()
	encoderName := value.EncoderName()
	encoder, found := encoders[encoderName]
	if found == false {
		log.Panicf("no encoder registered for type [%s]", encoderName)
	}
	encoded, unitCount, err = encoder.Encode(value, byteOrder)
	log.PanicIf(err)
	return encoded, unitCount, nil
}
// Decode constructs a value from raw encoded bytes
func Decode(valueContext *exifcommon.ValueContext) (value EncodeableValue, err error) {
	defer func() {
		if state := recover(); state != nil {
			err = log.Wrap(state.(error))
		}
	}()
	uth := UndefinedTagHandle{
		IfdPath: valueContext.IfdPath(),
		TagId:   valueContext.TagId(),
	}
	decoder, found := decoders[uth]
	if found == false {
		// We have no choice but to return the error. We have no way of knowing how
		// much data there is without already knowing what data-type this tag is.
		return nil, exifcommon.ErrUnhandledUndefinedTypedTag
	}
	value, err = decoder.Decode(valueContext)
	if err != nil {
		if err == ErrUnparseableValue {
			return nil, err
		}
		log.Panic(err)
	}
	return value, nil
}
 |