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 
5 #include "util/big_endian.h"
6 
7 namespace openscreen {
8 
BigEndianReader(const uint8_t * buffer,size_t length)9 BigEndianReader::BigEndianReader(const uint8_t* buffer, size_t length)
10     : BigEndianBuffer(buffer, length) {}
11 
Read(size_t length,void * out)12 bool BigEndianReader::Read(size_t length, void* out) {
13   const uint8_t* read_position = current();
14   if (Skip(length)) {
15     memcpy(out, read_position, length);
16     return true;
17   }
18   return false;
19 }
20 
BigEndianWriter(uint8_t * buffer,size_t length)21 BigEndianWriter::BigEndianWriter(uint8_t* buffer, size_t length)
22     : BigEndianBuffer(buffer, length) {}
23 
Write(const void * buffer,size_t length)24 bool BigEndianWriter::Write(const void* buffer, size_t length) {
25   uint8_t* write_position = current();
26   if (Skip(length)) {
27     memcpy(write_position, buffer, length);
28     return true;
29   }
30   return false;
31 }
32 
33 }  // namespace openscreen
34