1#ifndef RDS2CPP_PARSE_HPP
2#define RDS2CPP_PARSE_HPP
9#include "utils_parse.hpp"
10#include "SharedParseInfo.hpp"
11#include "parse_object.hpp"
49template<
class Reader_>
51 std::unique_ptr<byteme::PerByteInterface<unsigned char> > srcptr;
69 if (src.get() !=
'X') {
70 throw std::runtime_error(
"only RDS files in XDR format are currently supported");
76 if (src.get() !=
'\n') {
77 throw std::runtime_error(
"only RDS files in XDR format are currently supported");
79 }
catch (std::exception& e) {
80 throw traceback(
"failed to read the header from the RDS preamble", e);
85 for (
int i = 0; i < 4; ++i) {
92 }
catch (std::exception& e) {
93 throw traceback(
"failed to read the format version number from the RDS preamble", e);
103 }
catch (std::exception& e) {
104 throw traceback(
"failed to read the writer version number from the RDS preamble", e);
108 if (!src.advance()) {
112 }
catch (std::exception& e) {
113 throw traceback(
"failed to read the reader version number from the RDS preamble", e);
119 size_t encoding_length = 0;
121 for (
int b = 0; b < 4; ++b) {
122 if (!src.advance()) {
125 encoding_length <<= 8;
126 encoding_length += src.get();
128 }
catch (std::exception& e) {
129 throw traceback(
"failed to read the encoding length from the RDS preamble", e);
133 output.
encoding.reserve(encoding_length);
134 for (
size_t b = 0; b < encoding_length; ++b) {
135 if (!src.advance()) {
138 output.
encoding.push_back(as_char(src.get()));
140 }
catch (std::exception& e) {
141 throw traceback(
"failed to read the encoding string from the RDS preamble", e);
146 SharedParseInfo shared;
147 output.
object = parse_object(src, shared);
149 output.
symbols = std::move(shared.symbols);
Information about an RDS file.
Parse an RDS file in C++.
Definition StringEncoding.hpp:10
RdsFile parse_rds(Reader_ &reader, const ParseRdsOptions &options)
Definition parse_rds.hpp:50
RdsFile Parsed
Definition parse_rds.hpp:171
Options for parse_rds().
Definition parse_rds.hpp:26
bool parallel
Definition parse_rds.hpp:30
byteme::SomeFileReaderOptions file_options
Definition parse_rds.hpp:36
Contents of the parsed RDS file.
Definition RdsFile.hpp:21
std::array< unsigned char, 3 > writer_version
Definition RdsFile.hpp:53
std::unique_ptr< RObject > object
Definition RdsFile.hpp:68
std::vector< Symbol > symbols
Definition RdsFile.hpp:80
std::vector< ExternalPointer > external_pointers
Definition RdsFile.hpp:86
std::string encoding
Definition RdsFile.hpp:63
uint32_t format_version
Definition RdsFile.hpp:48
std::vector< Environment > environments
Definition RdsFile.hpp:74
std::array< unsigned char, 3 > reader_version
Definition RdsFile.hpp:58