lib-ruby-parser (C++ bindings)  4.0.1+ruby-3.1.1
C++ bindings for lib-ruby-parser library
decoder.hpp
Go to the documentation of this file.
1 #ifndef LIB_RUBY_PARSER_DECODER_HPP
2 #define LIB_RUBY_PARSER_DECODER_HPP
3 
4 #include <cstdbool>
5 #include <cstring>
6 #include "string.hpp"
7 #include "bytes.hpp"
8 
9 namespace lib_ruby_parser
10 {
11  class InputError
12  {
13  public:
14  enum class Tag
15  {
18  };
19 
20  union Value
21  {
24 
25  Value();
26  Value(Value &&);
27  ~Value();
28 
29  Value &operator=(Value &&);
30  };
31 
34 
36  InputError(InputError &&) = default;
37  ~InputError();
38 
39  InputError &operator=(InputError &&) = default;
40 
41  static InputError UnsupportedEncoding(String unsupported_encoding);
42  static InputError DecodingError(String decoding_error);
43  };
44 
46  {
47  enum class Tag
48  {
49  OK,
50  ERR
51  };
52 
53  union Value
54  {
57 
58  Value();
59  Value(Value &&);
60  Value &operator=(Value &&);
61  ~Value();
62  };
63 
66 
68  DecoderResult(DecoderResult &&) = default;
69  DecoderResult &operator=(DecoderResult &&) = default;
71 
72  static DecoderResult Ok(ByteList decoded);
73  static DecoderResult Err(InputError err);
74  };
75 
76  extern "C"
77  {
79  {
80  uint8_t bytes[sizeof(DecoderResult)];
81  };
82  }
83 
84  String string_from_string_blob(StringBlob blob);
85  ByteList byte_list_from_byte_list_blob(ByteListBlob blob);
86  DecoderResultBlob decoder_result_to_blob(DecoderResult decoder_result);
87 
88  extern "C"
89  {
91  }
92  class Decoder
93  {
94  public:
96  void *state;
97 
98  explicit Decoder(DecoderFunction f, void *state);
99  };
100 
102  {
103  public:
105 
106  bool is_some() const;
107  bool is_none() const;
108 
109  explicit MaybeDecoder(Decoder decoder);
110 
112  static MaybeDecoder None();
113  };
114 } // namespace lib_ruby_parser
115 
116 #endif // LIB_RUBY_PARSER_DECODER_HPP
lib_ruby_parser::MaybeDecoder::is_none
bool is_none() const
lib_ruby_parser::MaybeDecoder::MaybeDecoder
MaybeDecoder(Decoder decoder)
lib_ruby_parser::DecoderResultBlob::bytes
uint8_t bytes[sizeof(DecoderResult)]
Definition: decoder.hpp:80
lib_ruby_parser::InputError::operator=
InputError & operator=(InputError &&)=default
lib_ruby_parser::byte_list_from_byte_list_blob
ByteList byte_list_from_byte_list_blob(ByteListBlob blob)
lib_ruby_parser::DecoderResult::Value
Definition: decoder.hpp:53
lib_ruby_parser::InputError::Value::operator=
Value & operator=(Value &&)
lib_ruby_parser::InputError::Value::unsupported_encoding
String unsupported_encoding
Definition: decoder.hpp:22
lib_ruby_parser::InputError
Definition: decoder.hpp:11
lib_ruby_parser::MaybeDecoder
Definition: decoder.hpp:101
lib_ruby_parser::DecoderResult::Tag::ERR
@ ERR
lib_ruby_parser::InputError::InputError
InputError(Tag tag, Value as)
lib_ruby_parser::MaybeDecoder::decoder
Decoder decoder
Definition: decoder.hpp:104
lib_ruby_parser::Decoder
Definition: decoder.hpp:92
lib_ruby_parser::ByteList
Definition: bytes.hpp:11
lib_ruby_parser::InputError::Tag::UNSUPPORTED_ENCODING
@ UNSUPPORTED_ENCODING
string.hpp
lib_ruby_parser::decoder_result_to_blob
DecoderResultBlob decoder_result_to_blob(DecoderResult decoder_result)
lib_ruby_parser::DecoderResult::Value::err
InputError err
Definition: decoder.hpp:56
lib_ruby_parser::DecoderResult::operator=
DecoderResult & operator=(DecoderResult &&)=default
lib_ruby_parser::DecoderResult::Value::~Value
~Value()
lib_ruby_parser::DecoderResult::Value::operator=
Value & operator=(Value &&)
lib_ruby_parser::DecoderResult::~DecoderResult
~DecoderResult()
lib_ruby_parser::StringBlob
Definition: string.hpp:37
lib_ruby_parser::Decoder::f
DecoderFunction f
Definition: decoder.hpp:95
lib_ruby_parser::DecoderResultBlob
Definition: decoder.hpp:78
lib_ruby_parser::MaybeDecoder::Some
static MaybeDecoder Some(Decoder decoder)
lib_ruby_parser::Decoder::Decoder
Decoder(DecoderFunction f, void *state)
lib_ruby_parser::InputError::Tag
Tag
Definition: decoder.hpp:14
lib_ruby_parser::ByteListBlob
Definition: bytes.hpp:39
lib_ruby_parser::DecoderResult
Definition: decoder.hpp:45
lib_ruby_parser::InputError::Tag::DECODING_ERROR
@ DECODING_ERROR
lib_ruby_parser::MaybeDecoder::None
static MaybeDecoder None()
lib_ruby_parser::InputError::DecodingError
static InputError DecodingError(String decoding_error)
lib_ruby_parser::InputError::tag
Tag tag
Definition: decoder.hpp:32
lib_ruby_parser::String
Definition: string.hpp:13
lib_ruby_parser::Decoder::state
void * state
Definition: decoder.hpp:96
lib_ruby_parser::DecoderResult::as
Value as
Definition: decoder.hpp:65
lib_ruby_parser::DecoderResult::Ok
static DecoderResult Ok(ByteList decoded)
lib_ruby_parser::InputError::as
Value as
Definition: decoder.hpp:33
lib_ruby_parser
Definition: api.hpp:7
lib_ruby_parser::DecoderResult::Tag
Tag
Definition: decoder.hpp:47
lib_ruby_parser::string_from_string_blob
String string_from_string_blob(StringBlob blob)
lib_ruby_parser::DecoderResult::Err
static DecoderResult Err(InputError err)
lib_ruby_parser::DecoderFunction
DecoderResultBlob(* DecoderFunction)(void *, StringBlob, ByteListBlob)
Definition: decoder.hpp:90
lib_ruby_parser::DecoderResult::Tag::OK
@ OK
lib_ruby_parser::InputError::Value
Definition: decoder.hpp:20
lib_ruby_parser::DecoderResult::Value::Value
Value()
lib_ruby_parser::InputError::Value::decoding_error
String decoding_error
Definition: decoder.hpp:23
lib_ruby_parser::DecoderResult::Value::ok
ByteList ok
Definition: decoder.hpp:55
lib_ruby_parser::InputError::~InputError
~InputError()
lib_ruby_parser::InputError::Value::~Value
~Value()
lib_ruby_parser::MaybeDecoder::is_some
bool is_some() const
lib_ruby_parser::InputError::UnsupportedEncoding
static InputError UnsupportedEncoding(String unsupported_encoding)
lib_ruby_parser::DecoderResult::tag
Tag tag
Definition: decoder.hpp:64
bytes.hpp
lib_ruby_parser::InputError::Value::Value
Value()
lib_ruby_parser::DecoderResult::DecoderResult
DecoderResult(Tag tag, Value as)