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 #include "src/id_element_parser.h" 9 10 #include <cassert> 11 #include <cstdint> 12 13 #include "src/element_parser.h" 14 #include "src/parser_utils.h" 15 #include "webm/callback.h" 16 #include "webm/element.h" 17 #include "webm/reader.h" 18 #include "webm/status.h" 19 20 namespace webm { 21 Init(const ElementMetadata & metadata,std::uint64_t max_size)22Status IdElementParser::Init(const ElementMetadata& metadata, 23 std::uint64_t max_size) { 24 assert(metadata.size == kUnknownElementSize || metadata.size <= max_size); 25 26 if (metadata.size == 0 || metadata.size > 4) { 27 return Status(Status::kInvalidElementSize); 28 } 29 30 num_bytes_remaining_ = static_cast<int>(metadata.size); 31 value_ = static_cast<Id>(0); 32 33 return Status(Status::kOkCompleted); 34 } 35 Feed(Callback * callback,Reader * reader,std::uint64_t * num_bytes_read)36Status IdElementParser::Feed(Callback* callback, Reader* reader, 37 std::uint64_t* num_bytes_read) { 38 assert(callback != nullptr); 39 assert(reader != nullptr); 40 assert(num_bytes_read != nullptr); 41 42 const Status status = AccumulateIntegerBytes(num_bytes_remaining_, reader, 43 &value_, num_bytes_read); 44 num_bytes_remaining_ -= static_cast<int>(*num_bytes_read); 45 46 return status; 47 } 48 49 } // namespace webm 50