1 /*
2  * Copyright (C) 2018 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 __NOGROD_LEB128_DECODER_
18 #define __NOGROD_LEB128_DECODER_
19 
20 #include <stddef.h>
21 
22 #include <cstdint>
23 
24 #include "berberis/base/macros.h"
25 
26 namespace nogrod {
27 
28 class Leb128Decoder {
29  public:
30   Leb128Decoder(const uint8_t* buffer, size_t size);
31 
32   // Returns number of bytes it took do decode the value, 0 if decode has failed.
33   size_t Decode(size_t offset, uint64_t* result) const;
34 
35  private:
36   const uint8_t* buffer_;
37   size_t size_;
38 
39   DISALLOW_IMPLICIT_CONSTRUCTORS(Leb128Decoder);
40 };
41 
42 size_t DecodeLeb128(const uint8_t* buffer, uint64_t size, uint64_t* result);
43 size_t DecodeSleb128(const uint8_t* buffer, uint64_t size, int64_t* result);
44 
45 }  // namespace nogrod
46 #endif  // __NOGROD_LEB128_DECODER_
47