codec/h264/h264dec/bits/bitreader.go: added ReadBool and ReadBitsInt methods

This commit is contained in:
Saxon 2019-07-19 17:25:57 +09:30
parent 38f5f983e8
commit 16b4d570b6
1 changed files with 18 additions and 0 deletions

View File

@ -128,6 +128,24 @@ func (br *BitReader) ReadBits(n int) (uint64, error) {
return r, nil
}
// ReadBitsInt reads n bits from the source, and returns as an int.
func (br *BitReader) ReadBitsInt(n int) (int, error) {
b, err := br.ReadBits(n)
if err != nil {
return 0, err
}
return int(b), nil
}
// ReadBool reads a single bit from the source, converts to a bool and returns.
func (br *BitReader) ReadBool() (bool, error) {
b, err := br.ReadBits(1)
if err != nil {
return false, err
}
return b == 1, nil
}
// PeekBits provides the next n bits returning them in the least-significant
// part of a uint64, without advancing through the source.
// For example, with a source as []byte{0x8f,0xe3} (1000 1111, 1110 0011), we