esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
model.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <cstdint>
8#include <string>
9#include <vector>
10
11namespace protogen {
12
13enum class FieldType {
14 Double,
15 Float,
16 Int32,
17 Int64,
18 Uint32,
19 Uint64,
20 Sint32,
21 Sint64,
22 Fixed32,
23 Fixed64,
26 Bool,
27 String,
28 Bytes,
29 Enum, // type_name names a ProtoEnum
30 Message, // type_name names a ProtoMessageDef
31};
32
33struct ProtoField {
34 std::string name; // field name as written (already C++-safe in the proto)
35 std::string type_name; // raw type token ("uint32", "ColorMode", "DeviceInfo", ...)
37 int number = 0;
38 bool repeated = false;
39
40 // Packing for repeated numeric fields. `packed_explicit` records an explicit
41 // [packed=...]; otherwise proto3's default (packed for scalar numerics).
42 bool packed_explicit = false;
43 bool packed_value = false;
44};
45
47 std::string name;
48 std::int64_t number = 0;
49};
50
51struct ProtoEnum {
52 std::string name;
53 std::vector<ProtoEnumValue> values;
54};
55
57 std::string name;
58 std::vector<ProtoField> fields;
59 std::uint32_t id = 0; // (id) option, 0 if absent
60 std::string base_class; // (base_class) option, empty if absent
61};
62
63struct ProtoFile {
64 std::string package;
65 std::vector<ProtoEnum> enums;
66 std::vector<ProtoMessageDef> messages;
67};
68
69// --- type helpers ----------------------------------------------------------
70
72bool is_scalar_type(const std::string& t);
73
75int wire_type_of(const ProtoField& f);
76
78bool is_packed(const ProtoField& f);
79
80} // namespace protogen
Definition emit.hpp:12
int wire_type_of(const ProtoField &f)
Wire type number (0/1/2/5) for a resolved field.
Definition parser.cpp:413
bool is_packed(const ProtoField &f)
True if a repeated field of this type is packed (honoring explicit flag).
Definition parser.cpp:432
bool is_scalar_type(const std::string &t)
True for the 15 proto3 scalar keywords.
Definition parser.cpp:406
FieldType
Definition model.hpp:13
Definition model.hpp:46
std::string name
Definition model.hpp:47
std::int64_t number
Definition model.hpp:48
Definition model.hpp:51
std::string name
Definition model.hpp:52
std::vector< ProtoEnumValue > values
Definition model.hpp:53
Definition model.hpp:33
std::string name
Definition model.hpp:34
std::string type_name
Definition model.hpp:35
FieldType type
Definition model.hpp:36
bool repeated
Definition model.hpp:38
bool packed_value
Definition model.hpp:43
int number
Definition model.hpp:37
bool packed_explicit
Definition model.hpp:42
Definition model.hpp:63
std::string package
Definition model.hpp:64
std::vector< ProtoMessageDef > messages
Definition model.hpp:66
std::vector< ProtoEnum > enums
Definition model.hpp:65
Definition model.hpp:56
std::vector< ProtoField > fields
Definition model.hpp:58
std::string name
Definition model.hpp:57
std::string base_class
Definition model.hpp:60