Zachary Turner | 6ba65de | 2016-04-29 17:22:58 +0000 | [diff] [blame^] | 1 | //===- StreamReader.cpp - Reads bytes and objects from a stream -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/DebugInfo/PDB/Raw/StreamReader.h" |
| 11 | |
| 12 | using namespace llvm; |
| 13 | |
| 14 | StreamReader::StreamReader(const StreamInterface &S) : Stream(S), Offset(0) {} |
| 15 | |
| 16 | std::error_code StreamReader::readBytes(MutableArrayRef<uint8_t> Buffer) { |
| 17 | if (auto EC = Stream.readBytes(Offset, Buffer)) |
| 18 | return EC; |
| 19 | Offset += Buffer.size(); |
| 20 | return std::error_code(); |
| 21 | } |
| 22 | |
| 23 | std::error_code StreamReader::readInteger(uint32_t &Dest) { |
| 24 | support::ulittle32_t P; |
| 25 | if (std::error_code EC = readObject(&P)) |
| 26 | return EC; |
| 27 | Dest = P; |
| 28 | return std::error_code(); |
| 29 | } |
| 30 | |
| 31 | std::error_code StreamReader::readZeroString(std::string &Dest) { |
| 32 | Dest.clear(); |
| 33 | char C; |
| 34 | do { |
| 35 | readObject(&C); |
| 36 | if (C != '\0') |
| 37 | Dest.push_back(C); |
| 38 | } while (C != '\0'); |
| 39 | return std::error_code(); |
| 40 | } |