mirror of
https://github.com/wader/fq.git
synced 2024-12-23 13:22:58 +03:00
decode: Rename s/FieldTryFormat/TryFieldFormat for consistency
This commit is contained in:
parent
c0eebcc23f
commit
f801cc0af7
@ -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())
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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++
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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)
|
||||
}
|
||||
@ -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,
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user