mirror of https://bitbucket.org/ausocean/av.git
codec/h264/h26dec/read.go: added fieldReader type to provide sticky error and specific methods for bool and int reading
This commit is contained in:
parent
46c709404f
commit
404e6493b6
|
@ -228,3 +228,43 @@ func readFlags(br *bits.BitReader, flags []flag) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fieldReader provides methods for reading bool and int fields from a
|
||||||
|
// bits.BitReader with a sticky error that may be checked after a series of
|
||||||
|
// parsing read calls.
|
||||||
|
type fieldReader struct {
|
||||||
|
e error
|
||||||
|
br *bits.BitReader
|
||||||
|
}
|
||||||
|
|
||||||
|
// newFieldReader returns a new fieldReader.
|
||||||
|
func newFieldReader(br *bits.BitReader) fieldReader {
|
||||||
|
return fieldReader{br: br}
|
||||||
|
}
|
||||||
|
|
||||||
|
// readBool returns a bool from reading one bit from br. If we have an error
|
||||||
|
// already, we do not continue with the read.
|
||||||
|
func (r fieldReader) readBool() bool {
|
||||||
|
if r.e != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var b uint64
|
||||||
|
b, r.e = r.br.ReadBits(1)
|
||||||
|
return b == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// readBitsInt returns an int from reading n bits from br. If we have an error
|
||||||
|
// already, we do not continue with the read.
|
||||||
|
func (r fieldReader) readBitsInt(n int) int {
|
||||||
|
if r.e != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var b uint64
|
||||||
|
b, r.e = r.br.ReadBits(n)
|
||||||
|
return int(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// err returns the fieldReader's error e.
|
||||||
|
func (r fieldReader) err() error {
|
||||||
|
return r.e
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue