MCPcopy Create free account
hub / github.com/Comcast/gaad / ReadBitsToByteArray

Method ReadBitsToByteArray

bitreader/bitreader.go:128–148  ·  view source on GitHub ↗

Return n number of bits into a byte array

(n uint)

Source from the content-addressed store, hash-verified

126
127// Return n number of bits into a byte array
128func (p *BitReader) ReadBitsToByteArray(n uint) ([]byte, error) {
129 result := make([]byte, int(math.Ceil(float64(n)/8)))
130
131 temp := make([]byte, n)
132 for i := uint(0); i < n; i++ {
133 bit, err := p.ReadBit()
134 if err != nil {
135 return nil, err
136 }
137 temp[i] = bit
138 }
139
140 bitmask := 0
141 for i := n; i > 0; i-- {
142 index := len(result) - (bitmask / 8) - 1
143 result[index] |= temp[i-1] << uint(bitmask%8)
144 bitmask++
145 }
146
147 return result, nil
148}
149
150// Return n number of bits
151func (p *BitReader) ReadBits(n uint) (byte, error) {

Callers 6

TestReadBitsToByteArrayFunction · 0.95
extension_payloadMethod · 0.80
sbr_extension_dataMethod · 0.80

Calls 1

ReadBitMethod · 0.95

Tested by 1

TestReadBitsToByteArrayFunction · 0.76