blob: 18d29953e252f63f4c9d8ba2dfead3ce4b89cd7d [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;
Zachary Turner2f09b502016-04-29 17:28:47 +000013using namespace llvm::pdb;
Zachary Turner6ba65de2016-04-29 17:22:58 +000014
15StreamReader::StreamReader(const StreamInterface &S) : Stream(S), Offset(0) {}
16
17std::error_code StreamReader::readBytes(MutableArrayRef<uint8_t> Buffer) {
18 if (auto EC = Stream.readBytes(Offset, Buffer))
19 return EC;
20 Offset += Buffer.size();
21 return std::error_code();
22}
23
24std::error_code StreamReader::readInteger(uint32_t &Dest) {
25 support::ulittle32_t P;
26 if (std::error_code EC = readObject(&P))
27 return EC;
28 Dest = P;
29 return std::error_code();
30}
31
32std::error_code StreamReader::readZeroString(std::string &Dest) {
33 Dest.clear();
34 char C;
35 do {
36 readObject(&C);
37 if (C != '\0')
38 Dest.push_back(C);
39 } while (C != '\0');
40 return std::error_code();
41}
Zachary Turnerf5c59652016-05-03 00:28:21 +000042
43std::error_code StreamReader::getArrayRef(ArrayRef<uint8_t> &Array,
44 uint32_t Length) {
45 if (auto EC = Stream.getArrayRef(Offset, Array, Length))
46 return EC;
47 Offset += Length;
48 return std::error_code();
49}