mirror of https://github.com/dsoprea/go-exif.git
common/type.go: Rename Format() to FormatFromBytes()
parent
82afccee6b
commit
6554f89879
|
@ -256,11 +256,9 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(dustin): Rename Format() to FormatFromBytes()
|
||||
|
||||
// Format returns a stringified value for the given encoding. Automatically
|
||||
// parses. Automatically calculates count based on type size.
|
||||
func Format(rawBytes []byte, tagType TagTypePrimitive, justFirst bool, byteOrder binary.ByteOrder) (phrase string, err error) {
|
||||
func FormatFromBytes(rawBytes []byte, tagType TagTypePrimitive, justFirst bool, byteOrder binary.ByteOrder) (phrase string, err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
|
|
|
@ -105,7 +105,7 @@ func TestTypeSignedRational_Size(t *testing.T) {
|
|||
func TestFormat__Byte(t *testing.T) {
|
||||
r := []byte{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
|
||||
s, err := Format(r, TypeByte, false, TestDefaultByteOrder)
|
||||
s, err := FormatFromBytes(r, TypeByte, false, TestDefaultByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
if s != "01 02 03 04 05 06 07 08" {
|
||||
|
@ -116,7 +116,7 @@ func TestFormat__Byte(t *testing.T) {
|
|||
func TestFormat__Ascii(t *testing.T) {
|
||||
r := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 0}
|
||||
|
||||
s, err := Format(r, TypeAscii, false, TestDefaultByteOrder)
|
||||
s, err := FormatFromBytes(r, TypeAscii, false, TestDefaultByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
if s != "abcdefg" {
|
||||
|
@ -127,7 +127,7 @@ func TestFormat__Ascii(t *testing.T) {
|
|||
func TestFormat__AsciiNoNul(t *testing.T) {
|
||||
r := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}
|
||||
|
||||
s, err := Format(r, TypeAsciiNoNul, false, TestDefaultByteOrder)
|
||||
s, err := FormatFromBytes(r, TypeAsciiNoNul, false, TestDefaultByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
if s != "abcdefgh" {
|
||||
|
@ -138,7 +138,7 @@ func TestFormat__AsciiNoNul(t *testing.T) {
|
|||
func TestFormat__Short(t *testing.T) {
|
||||
r := []byte{0, 1, 0, 2}
|
||||
|
||||
s, err := Format(r, TypeShort, false, TestDefaultByteOrder)
|
||||
s, err := FormatFromBytes(r, TypeShort, false, TestDefaultByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
if s != "[1 2]" {
|
||||
|
@ -149,7 +149,7 @@ func TestFormat__Short(t *testing.T) {
|
|||
func TestFormat__Long(t *testing.T) {
|
||||
r := []byte{0, 0, 0, 1, 0, 0, 0, 2}
|
||||
|
||||
s, err := Format(r, TypeLong, false, TestDefaultByteOrder)
|
||||
s, err := FormatFromBytes(r, TypeLong, false, TestDefaultByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
if s != "[1 2]" {
|
||||
|
@ -163,7 +163,7 @@ func TestFormat__Rational(t *testing.T) {
|
|||
0, 0, 0, 3, 0, 0, 0, 4,
|
||||
}
|
||||
|
||||
s, err := Format(r, TypeRational, false, TestDefaultByteOrder)
|
||||
s, err := FormatFromBytes(r, TypeRational, false, TestDefaultByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
if s != "[1/2 3/4]" {
|
||||
|
@ -174,7 +174,7 @@ func TestFormat__Rational(t *testing.T) {
|
|||
func TestFormat__SignedLong(t *testing.T) {
|
||||
r := []byte{0, 0, 0, 1, 0, 0, 0, 2}
|
||||
|
||||
s, err := Format(r, TypeSignedLong, false, TestDefaultByteOrder)
|
||||
s, err := FormatFromBytes(r, TypeSignedLong, false, TestDefaultByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
if s != "[1 2]" {
|
||||
|
@ -188,7 +188,7 @@ func TestFormat__SignedRational(t *testing.T) {
|
|||
0, 0, 0, 3, 0, 0, 0, 4,
|
||||
}
|
||||
|
||||
s, err := Format(r, TypeSignedRational, false, TestDefaultByteOrder)
|
||||
s, err := FormatFromBytes(r, TypeSignedRational, false, TestDefaultByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
if s != "[1/2 3/4]" {
|
||||
|
@ -199,7 +199,7 @@ func TestFormat__SignedRational(t *testing.T) {
|
|||
func TestFormat__Undefined(t *testing.T) {
|
||||
r := []byte{'a', 'b'}
|
||||
|
||||
_, err := Format(r, TypeUndefined, false, TestDefaultByteOrder)
|
||||
_, err := FormatFromBytes(r, TypeUndefined, false, TestDefaultByteOrder)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error.")
|
||||
} else if err.Error() != "can not determine tag-value size for type (7): [UNDEFINED]" {
|
||||
|
|
|
@ -165,7 +165,7 @@ func (vc *ValueContext) Format() (value string, err error) {
|
|||
rawBytes, err := vc.readRawEncoded()
|
||||
log.PanicIf(err)
|
||||
|
||||
phrase, err := Format(rawBytes, vc.effectiveValueType(), false, vc.byteOrder)
|
||||
phrase, err := FormatFromBytes(rawBytes, vc.effectiveValueType(), false, vc.byteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
return phrase, nil
|
||||
|
@ -183,7 +183,7 @@ func (vc *ValueContext) FormatFirst() (value string, err error) {
|
|||
rawBytes, err := vc.readRawEncoded()
|
||||
log.PanicIf(err)
|
||||
|
||||
phrase, err := Format(rawBytes, vc.tagType, true, vc.byteOrder)
|
||||
phrase, err := FormatFromBytes(rawBytes, vc.tagType, true, vc.byteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
return phrase, nil
|
||||
|
|
|
@ -138,7 +138,7 @@ func (bt *BuilderTag) String() string {
|
|||
if bt.value.IsBytes() == true {
|
||||
var err error
|
||||
|
||||
valueString, err = exifcommon.Format(bt.value.Bytes(), bt.typeId, false, bt.byteOrder)
|
||||
valueString, err = exifcommon.FormatFromBytes(bt.value.Bytes(), bt.typeId, false, bt.byteOrder)
|
||||
log.PanicIf(err)
|
||||
} else {
|
||||
valueString = fmt.Sprintf("%v", bt.value)
|
||||
|
|
Loading…
Reference in New Issue