P4C
The P4 Compiler
Loading...
Searching...
No Matches
marshal.h
1
19#ifndef PARDE_MARSHAL_H_
20#define PARDE_MARSHAL_H_
21
22#include <iostream>
23
24#include "backends/tofino/bf-p4c/ir/gress.h"
25#include "lib/cstring.h"
26
27namespace P4 {
28
29class JSONGenerator;
30class JSONLoader;
31
33 // use those two to uniquely identify a field.
34 gress_t gress;
35 cstring field_name;
41 // size_t post_padding;
42
43 std::string toString() const;
44
45 bool operator==(const MarshaledFrom &other) const {
46 return gress == other.gress && field_name == other.field_name &&
47 pre_padding == other.pre_padding;
48 }
49
51 void toJSON(JSONGenerator &json) const;
52 static MarshaledFrom fromJSON(JSONLoader &json);
53
54 friend std::ostream &operator<<(std::ostream &s, const MarshaledFrom &m);
55 friend P4::JSONGenerator &operator<<(P4::JSONGenerator &out, const MarshaledFrom &c);
56
57 MarshaledFrom() : gress(INGRESS), field_name(""), pre_padding(0) {}
58 MarshaledFrom(gress_t gress, cstring name) : gress(gress), field_name(name), pre_padding(0) {}
59 MarshaledFrom(gress_t gress, cstring name, size_t pre_padding)
60 : gress(gress), field_name(name), pre_padding(pre_padding) {}
61};
62
63inline std::ostream &operator<<(std::ostream &s, const MarshaledFrom &m) {
64 s << "(" << m.gress << ", " << m.field_name << ", " << m.pre_padding << ")";
65 return s;
66}
67
68inline JSONGenerator &operator<<(JSONGenerator &out, const MarshaledFrom &c) {
69 c.toJSON(out);
70 return out;
71}
72
73} // namespace P4
74
75#endif /* PARDE_MARSHAL_H_ */
Definition json_generator.h:37
Definition json_loader.h:39
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition marshal.h:32
size_t pre_padding
Definition marshal.h:40
void toJSON(JSONGenerator &json) const
JSON serialization/deserialization.
Definition marshal.cpp:29
std::string toString() const
Definition marshal.cpp:23