From 16b4d570b6a3c6343ca6e5bcbb5f2acf24be2a8d Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 19 Jul 2019 17:25:57 +0930 Subject: [PATCH] codec/h264/h264dec/bits/bitreader.go: added ReadBool and ReadBitsInt methods --- codec/h264/decode/bits/bitreader.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/codec/h264/decode/bits/bitreader.go b/codec/h264/decode/bits/bitreader.go index 7e17f407..08cc5d41 100644 --- a/codec/h264/decode/bits/bitreader.go +++ b/codec/h264/decode/bits/bitreader.go @@ -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