Max Yakimakha | dad3c64 | 2019-05-24 17:25:30 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Jordan Bayles | a26582d | 2019-07-10 14:44:58 -0700 | [diff] [blame] | 5 | #include "util/big_endian.h" |
Max Yakimakha | dad3c64 | 2019-05-24 17:25:30 -0700 | [diff] [blame] | 6 | |
| 7 | namespace openscreen { |
| 8 | |
| 9 | BigEndianReader::BigEndianReader(const uint8_t* buffer, size_t length) |
Max Yakimakha | b7da13f | 2019-06-11 16:59:06 -0700 | [diff] [blame] | 10 | : BigEndianBuffer(buffer, length) {} |
Max Yakimakha | dad3c64 | 2019-05-24 17:25:30 -0700 | [diff] [blame] | 11 | |
Max Yakimakha | 55bbe80 | 2019-06-19 15:04:28 -0700 | [diff] [blame] | 12 | bool BigEndianReader::Read(size_t length, void* out) { |
Max Yakimakha | b7da13f | 2019-06-11 16:59:06 -0700 | [diff] [blame] | 13 | const uint8_t* read_position = current(); |
| 14 | if (Skip(length)) { |
| 15 | memcpy(out, read_position, length); |
| 16 | return true; |
Max Yakimakha | dad3c64 | 2019-05-24 17:25:30 -0700 | [diff] [blame] | 17 | } |
Max Yakimakha | b7da13f | 2019-06-11 16:59:06 -0700 | [diff] [blame] | 18 | return false; |
Max Yakimakha | dad3c64 | 2019-05-24 17:25:30 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | BigEndianWriter::BigEndianWriter(uint8_t* buffer, size_t length) |
Max Yakimakha | b7da13f | 2019-06-11 16:59:06 -0700 | [diff] [blame] | 22 | : BigEndianBuffer(buffer, length) {} |
Max Yakimakha | dad3c64 | 2019-05-24 17:25:30 -0700 | [diff] [blame] | 23 | |
Max Yakimakha | 2b8a98c | 2019-06-19 14:39:22 -0700 | [diff] [blame] | 24 | bool BigEndianWriter::Write(const void* buffer, size_t length) { |
Max Yakimakha | b7da13f | 2019-06-11 16:59:06 -0700 | [diff] [blame] | 25 | uint8_t* write_position = current(); |
| 26 | if (Skip(length)) { |
| 27 | memcpy(write_position, buffer, length); |
| 28 | return true; |
Max Yakimakha | dad3c64 | 2019-05-24 17:25:30 -0700 | [diff] [blame] | 29 | } |
Max Yakimakha | b7da13f | 2019-06-11 16:59:06 -0700 | [diff] [blame] | 30 | return false; |
Max Yakimakha | dad3c64 | 2019-05-24 17:25:30 -0700 | [diff] [blame] | 31 | } |
| 32 | |
mark a. foltz | b4e53be | 2020-05-28 11:42:36 -0700 | [diff] [blame] | 33 | } // namespace openscreen |