1#ifndef RDS2CPP_PARSE_HPP
2#define RDS2CPP_PARSE_HPP
9#include "utils_parse.hpp"
10#include "SharedParseInfo.hpp"
11#include "parse_object.hpp"
50template<
class Reader_>
52 std::unique_ptr<byteme::BufferedReader<unsigned char> > srcptr;
64 std::string header(2,
'\0');
65 quick_extract(src, 2,
reinterpret_cast<unsigned char*
>(header.data()));
66 if (header !=
"X\n") {
67 throw std::runtime_error(
"only RDS files in XDR format are currently supported");
69 }
catch (std::exception& e) {
70 throw traceback(
"failed to read the header from the RDS preamble", e);
76 }
catch (std::exception& e) {
77 throw traceback(
"failed to read the format version number from the RDS preamble", e);
82 }
catch (std::exception& e) {
83 throw traceback(
"failed to read the writer version number from the RDS preamble", e);
88 }
catch (std::exception& e) {
89 throw traceback(
"failed to read the reader version number from the RDS preamble", e);
95 std::int32_t encoding_length = 0;
97 encoding_length = quick_integer<I<
decltype(encoding_length)> >(src);
98 if (encoding_length < 0) {
99 throw std::runtime_error(
"encoding length should be non-negative");
101 }
catch (std::exception& e) {
102 throw traceback(
"failed to read the encoding length from the RDS preamble", e);
107 quick_extract(src, encoding_length,
reinterpret_cast<unsigned char*
>(encoding.data()));
108 output.
encoding = string_encoding_from_name(encoding);
109 }
catch (std::exception& e) {
110 throw traceback(
"failed to read the encoding string from the RDS preamble", e);
115 SharedParseInfo shared;
116 output.
object = parse_object(src, shared);
118 output.
symbols = std::move(shared.symbols);
Information about an RDS file.
Parse an RDS file in C++.
Definition StringEncoding.hpp:12
RdsFile parse_rds(Reader_ &reader, const ParseRdsOptions &options)
Definition parse_rds.hpp:51
RdsFile Parsed
Definition parse_rds.hpp:140
Container_ create(Value_ x, Args_ &&... args)
constexpr Dest_ cap(Value_ x)
Options for parse_rds().
Definition parse_rds.hpp:27
bool parallel
Definition parse_rds.hpp:31
std::size_t buffer_size
Definition parse_rds.hpp:37
Contents of the parsed RDS file.
Definition RdsFile.hpp:21
std::int32_t format_version
Definition RdsFile.hpp:25
std::unique_ptr< RObject > object
Definition RdsFile.hpp:45
std::vector< Symbol > symbols
Definition RdsFile.hpp:57
std::vector< ExternalPointer > external_pointers
Definition RdsFile.hpp:63
Version reader_version
Definition RdsFile.hpp:35
StringEncoding encoding
Definition RdsFile.hpp:40
Version writer_version
Definition RdsFile.hpp:30
std::vector< Environment > environments
Definition RdsFile.hpp:51