blob: 707f77f5d73274285006cb7e10c4a0113c77077d [file] [log] [blame]
Zachary Turner6ba65de2016-04-29 17:22:58 +00001//===- 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
12using namespace llvm;
13
14StreamReader::StreamReader(const StreamInterface &S) : Stream(S), Offset(0) {}
15
16std::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
23std::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
31std::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}