1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the LICENSE file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 #ifndef SRC_VAR_INT_PARSER_H_ 9 #define SRC_VAR_INT_PARSER_H_ 10 11 #include <cassert> 12 #include <cstdint> 13 14 #include "src/parser.h" 15 #include "webm/callback.h" 16 #include "webm/reader.h" 17 #include "webm/status.h" 18 19 namespace webm { 20 21 class VarIntParser : public Parser { 22 public: 23 VarIntParser() = default; 24 VarIntParser(VarIntParser&&) = default; 25 VarIntParser& operator=(VarIntParser&&) = default; 26 27 VarIntParser(const VarIntParser&) = delete; 28 VarIntParser& operator=(const VarIntParser&) = delete; 29 30 Status Feed(Callback* callback, Reader* reader, 31 std::uint64_t* num_bytes_read) override; 32 33 // Gets the parsed value. This must not be called until the parse had been 34 // successfully completed. value()35 std::uint64_t value() const { 36 assert(num_bytes_remaining_ == 0); 37 return value_; 38 } 39 40 // Gets the number of bytes which were used to encode the integer value in the 41 // byte stream. This must not be called until the parse had been successfully 42 // completed. encoded_length()43 int encoded_length() const { 44 assert(num_bytes_remaining_ == 0); 45 return total_data_bytes_ + 1; 46 } 47 48 private: 49 int num_bytes_remaining_ = -1; 50 int total_data_bytes_; 51 std::uint64_t value_; 52 }; 53 54 } // namespace webm 55 56 #endif // SRC_VAR_INT_PARSER_H_ 57