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);
102 for (
int pos = 0; pos < 3; ++pos) {
103 if (!src.advance()) {
108 }
catch (std::exception& e) {
109 throw traceback(
"failed to read the writer version number from the RDS preamble", e);
113 if (!src.advance()) {
116 for (
int pos = 0; pos < 3; ++pos) {
117 if (!src.advance()) {
122 }
catch (std::exception& e) {
123 throw traceback(
"failed to read the reader version number from the RDS preamble", e);
129 size_t encoding_length = 0;
131 for (
int b = 0; b < 4; ++b) {
132 if (!src.advance()) {
135 encoding_length <<= 8;
136 encoding_length += src.get();
138 }
catch (std::exception& e) {
139 throw traceback(
"failed to read the encoding length from the RDS preamble", e);
143 output.
encoding.reserve(encoding_length);
144 for (
size_t b = 0; b < encoding_length; ++b) {
145 if (!src.advance()) {
148 output.
encoding.push_back(src.get());
150 }
catch (std::exception& e) {
151 throw traceback(
"failed to read the encoding string from the RDS preamble", e);
156 SharedParseInfo shared;
157 output.
object = parse_object(src, shared);
159 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:181
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