Skip to content

Commit

Permalink
decode: Rename s/FieldTryFormat/TryFieldFormat for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Nov 30, 2021
1 parent c0eebcc commit f801cc0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion format/ape/apev2.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func apev2Decode(d *decode.D, in interface{}) interface{} {
d.LenFn(int64(itemSize)*8, func(d *decode.D) {
d.FieldUTF8Null("filename")
// assume image if binary
dv, _, _ := d.FieldTryFormat("value", imageFormat, nil)
dv, _, _ := d.TryFieldFormat("value", imageFormat, nil)
if dv == nil {
// TODO: framed and unknown instead?
d.FieldRawLen("value", d.BitsLeft())
Expand Down
6 changes: 3 additions & 3 deletions format/mp3/mp3.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func mp3Decode(d *decode.D, in interface{}) interface{} {
// there are mp3s files in the wild with multiple headers, two id3v2 tags etc
d.FieldArray("headers", func(d *decode.D) {
for d.NotEnd() {
if dv, _, _ := d.FieldTryFormat("header", headerFormat, nil); dv == nil {
if dv, _, _ := d.TryFieldFormat("header", headerFormat, nil); dv == nil {
return
}
}
Expand All @@ -78,7 +78,7 @@ func mp3Decode(d *decode.D, in interface{}) interface{} {
d.SeekRel(syncLen)
}

dv, v, _ := d.FieldTryFormat("frame", mp3Frame, nil)
dv, v, _ := d.TryFieldFormat("frame", mp3Frame, nil)
if dv == nil {
decodeFailures++
d.SeekRel(8)
Expand Down Expand Up @@ -113,7 +113,7 @@ func mp3Decode(d *decode.D, in interface{}) interface{} {

d.FieldArray("footers", func(d *decode.D) {
for d.NotEnd() {
if dv, _, _ := d.FieldTryFormat("footer", footerFormat, nil); dv == nil {
if dv, _, _ := d.TryFieldFormat("footer", footerFormat, nil); dv == nil {
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion format/mpeg/adts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
func adtsDecoder(d *decode.D, in interface{}) interface{} {
validFrames := 0
for !d.End() {
if dv, _, _ := d.FieldTryFormat("frame", adtsFrame, nil); dv == nil {
if dv, _, _ := d.TryFieldFormat("frame", adtsFrame, nil); dv == nil {
break
}
validFrames++
Expand Down
2 changes: 1 addition & 1 deletion format/mpeg/mp3_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func frameDecode(d *decode.D, in interface{}) interface{} {
calcFrameBytes := int64(144*bitRate/sampleRate + paddingBytes)
dataWithPaddingBytes := calcFrameBytes - headerBytes - crcBytes - sideInfoBytes

if dv, _, _ := d.FieldTryFormat("xing", xingHeader, nil); dv != nil {
if dv, _, _ := d.TryFieldFormat("xing", xingHeader, nil); dv != nil {
// TODO: allow shorter?
paddingBytes := dataWithPaddingBytes - dv.Range.Len/8
d.FieldRawLen("padding", paddingBytes*8)
Expand Down
2 changes: 1 addition & 1 deletion format/mpeg/mpeg_pes.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func pesDecode(d *decode.D, in interface{}) interface{} {
spuD := d.FieldArrayValue("spus")

for d.NotEnd() {
dv, v, err := d.FieldTryFormat("packet", pesPacketFormat, nil)
dv, v, err := d.TryFieldFormat("packet", pesPacketFormat, nil)
if dv == nil || err != nil {
log.Printf("errs[0]: %#+v\n", err)
break
Expand Down
2 changes: 1 addition & 1 deletion format/ogg/ogg.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func decodeOgg(d *decode.D, in interface{}) interface{} {

d.FieldArray("pages", func(d *decode.D) {
for !d.End() {
_, dv, _ := d.FieldTryFormat("page", oggPageFormat, nil)
_, dv, _ := d.TryFieldFormat("page", oggPageFormat, nil)
if dv == nil {
break
}
Expand Down
4 changes: 2 additions & 2 deletions format/wav/wav.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ func decodeChunks(d *decode.D, stringData bool) {

func wavDecode(d *decode.D, in interface{}) interface{} {
// there are wav files in the wild with id3v2 header id3v1 footer
_, _, _ = d.FieldTryFormat("header", headerFormat, nil)
_, _, _ = d.TryFieldFormat("header", headerFormat, nil)

decodeChunk(d, "RIFF", false)

_, _, _ = d.FieldTryFormat("footer", footerFormat, nil)
_, _, _ = d.TryFieldFormat("footer", footerFormat, nil)

return nil
}
8 changes: 4 additions & 4 deletions pkg/decode/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func (d *D) Format(group Group, inArg interface{}) interface{} {
return v
}

func (d *D) FieldTryFormat(name string, group Group, inArg interface{}) (*Value, interface{}, error) {
func (d *D) TryFieldFormat(name string, group Group, inArg interface{}) (*Value, interface{}, error) {
dv, v, err := decode(d.Ctx, d.bitBuf, group, Options{
Name: name,
Force: d.Options.Force,
Expand All @@ -748,7 +748,7 @@ func (d *D) FieldTryFormat(name string, group Group, inArg interface{}) (*Value,
}

func (d *D) FieldFormat(name string, group Group, inArg interface{}) (*Value, interface{}) {
dv, v, err := d.FieldTryFormat(name, group, inArg)
dv, v, err := d.TryFieldFormat(name, group, inArg)
if dv == nil || dv.Errors() != nil {
panic(err)
}
Expand Down Expand Up @@ -786,7 +786,7 @@ func (d *D) FieldFormatLen(name string, nBits int64, group Group, inArg interfac
}

// TODO: return decooder?
func (d *D) FieldTryFormatRange(name string, firstBit int64, nBits int64, group Group, inArg interface{}) (*Value, interface{}, error) {
func (d *D) TryFieldFormatRange(name string, firstBit int64, nBits int64, group Group, inArg interface{}) (*Value, interface{}, error) {
dv, v, err := decode(d.Ctx, d.bitBuf, group, Options{
Name: name,
Force: d.Options.Force,
Expand All @@ -806,7 +806,7 @@ func (d *D) FieldTryFormatRange(name string, firstBit int64, nBits int64, group
}

func (d *D) FieldFormatRange(name string, firstBit int64, nBits int64, group Group, inArg interface{}) (*Value, interface{}) {
dv, v, err := d.FieldTryFormatRange(name, firstBit, nBits, group, inArg)
dv, v, err := d.TryFieldFormatRange(name, firstBit, nBits, group, inArg)
if dv == nil || dv.Errors() != nil {
panic(err)
}
Expand Down

0 comments on commit f801cc0

Please sign in to comment.