spudplate
Template scaffolding compiler for spudlang .spud files
Loading...
Searching...
No Matches
binary_serializer.h
1#ifndef SPUDPLATE_BINARY_SERIALIZER_H
2#define SPUDPLATE_BINARY_SERIALIZER_H
3
4#include <cstddef>
5#include <cstdint>
6#include <stdexcept>
7#include <string>
8#include <vector>
9
10#include "spudplate/ast.h"
11
12namespace spudplate {
13
24enum class ExprTag : std::uint8_t {
25 StringLiteral = 0,
26 IntegerLiteral = 1,
27 BoolLiteral = 2,
28 Identifier = 3,
29 Unary = 4,
30 Binary = 5,
31 FunctionCall = 6,
32 TemplateString = 7,
33};
34
36enum class StmtTag : std::uint8_t {
37 Ask = 0,
38 Let = 1,
39 Assign = 2,
40 Mkdir = 3,
41 File = 4,
42 Repeat = 5,
43 Copy = 6,
44 Include = 7,
45 Run = 8,
46 If = 9,
47};
48
50enum class PathSegTag : std::uint8_t {
51 Literal = 0,
52 Var = 1,
53 Interp = 2,
54};
55
57enum class FileSrcTag : std::uint8_t {
58 From = 0,
59 Content = 1,
60};
61
63enum class TemplatePartTag : std::uint8_t {
64 Literal = 0,
65 Expression = 1,
66};
67
69class BinarySerializeError : public std::runtime_error {
70 public:
71 using std::runtime_error::runtime_error;
72};
73
80class BinaryDeserializeError : public std::runtime_error {
81 public:
83 BinaryDeserializeError(std::string message, std::size_t offset);
84
86 std::size_t offset() const noexcept { return offset_; }
87
88 private:
89 std::size_t offset_;
90};
91
105std::vector<std::uint8_t> serialize_program(const Program& program);
106
122Program deserialize_program(const std::uint8_t* data, std::size_t size,
123 std::uint8_t pack_version = 4);
124
125} // namespace spudplate
126
127#endif // SPUDPLATE_BINARY_SERIALIZER_H
Raised when the byte stream cannot be decoded.
Definition binary_serializer.h:80
std::size_t offset() const noexcept
Byte offset within the decoded buffer where the failure occurred.
Definition binary_serializer.h:86
Raised when an AST cannot be encoded (e.g.
Definition binary_serializer.h:69