1 // Copyright 2015 The Chromium OS 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 "buffer_reader.h" 6 7 #include <string.h> 8 9 namespace quipper { 10 ReadData(const size_t size,void * dest)11bool BufferReader::ReadData(const size_t size, void* dest) { 12 if (offset_ + size > size_) return false; 13 14 memcpy(dest, buffer_ + offset_, size); 15 offset_ += size; 16 return true; 17 } 18 ReadString(size_t size,string * str)19bool BufferReader::ReadString(size_t size, string* str) { 20 if (offset_ + size > size_) return false; 21 22 size_t actual_length = strnlen(buffer_ + offset_, size); 23 *str = string(buffer_ + offset_, actual_length); 24 offset_ += size; 25 return true; 26 } 27 28 } // namespace quipper 29