xref: /aosp_15_r20/external/libwebm/webm_parser/src/id_element_parser.h (revision 103e46e4cd4b6efcf6001f23fa8665fb110abf8d)
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_ID_ELEMENT_PARSER_H_
9  #define SRC_ID_ELEMENT_PARSER_H_
10  
11  #include <cstdint>
12  
13  #include "src/element_parser.h"
14  #include "webm/callback.h"
15  #include "webm/reader.h"
16  #include "webm/status.h"
17  
18  namespace webm {
19  
20  class IdElementParser : public ElementParser {
21   public:
22    IdElementParser() = default;
23  
24    IdElementParser(IdElementParser&&) = default;
25    IdElementParser& operator=(IdElementParser&&) = default;
26  
27    IdElementParser(const IdElementParser&) = delete;
28    IdElementParser& operator=(const IdElementParser&) = delete;
29  
30    Status Init(const ElementMetadata& metadata, std::uint64_t max_size) override;
31  
32    Status Feed(Callback* callback, Reader* reader,
33                std::uint64_t* num_bytes_read) override;
34  
35    // Gets the parsed Id. This must not be called until the parse had been
36    // successfully completed.
value()37    Id value() const {
38      assert(num_bytes_remaining_ == 0);
39      return value_;
40    }
41  
42    // Gets the parsed Id. This must not be called until the parse had been
43    // successfully completed.
mutable_value()44    Id* mutable_value() {
45      assert(num_bytes_remaining_ == 0);
46      return &value_;
47    }
48  
49   private:
50    Id value_;
51    int num_bytes_remaining_ = -1;
52  };
53  
54  }  // namespace webm
55  
56  #endif  // SRC_ID_ELEMENT_PARSER_H_
57