blob: 3f6fe59597217604ba508b80ec3a2c6cf5738620 [file] [log] [blame]
Phil Burka8bbc962015-04-01 17:16:31 -07001/*
2 * Copyright 2015, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_AUDIO_BIT_FIELD_PARSER_H
18#define ANDROID_AUDIO_BIT_FIELD_PARSER_H
19
20#include <stdint.h>
21
22namespace android {
23
24/**
25 * Extract bit fields from a byte array.
26 */
27class BitFieldParser {
28public:
29
Chih-Hung Hsieh4b7f50c2016-07-12 12:26:37 -070030 explicit BitFieldParser(uint8_t *data);
Phil Burka8bbc962015-04-01 17:16:31 -070031 virtual ~BitFieldParser();
32
33 /**
34 * Read numBits bits from the data array.
35 * Fields may span byte boundaries but may not exceed 32-bits.
36 * Note that the caller must ensure that there is suffcient data.
37 * Assume data is organized as BigEndian format.
38 */
39 uint32_t readBits(uint32_t numBits);
40
41 /*
42 * When the cursor is zero it points to a position right before
43 * the most significant bit.
44 * When the cursor is seven it points to a position right before
45 * the least significant bit.
46 */
47 uint32_t getBitCursor() const { return mBitCursor; }
48
49private:
50 uint8_t *mData;
51 uint32_t mBitCursor;
52};
53
54
55} // namespace android
56
57#endif // ANDROID_AUDIO_BIT_FIELD_PARSER_H