1pub mod types;
10
11pub use types::{
12 DeprecatedInfo, Encoding, FieldEncoding, ResolvedAnnotations, ResolvedType, TombstoneDef,
13 TypeId, TypeRegistry, WireSize,
14};
15
16use crate::ast::{DefaultValue, EnumBacking};
17use crate::span::Span;
18use smol_str::SmolStr;
19
20#[derive(Debug, Clone)]
26pub struct CompiledSchema {
27 pub namespace: Vec<SmolStr>,
29 pub annotations: ResolvedAnnotations,
31 pub registry: TypeRegistry,
33 pub declarations: Vec<TypeId>,
35}
36
37#[derive(Debug, Clone)]
42#[non_exhaustive]
43pub enum TypeDef {
44 Message(MessageDef),
46 Enum(EnumDef),
48 Flags(FlagsDef),
50 Union(UnionDef),
52 Newtype(NewtypeDef),
54 Config(ConfigDef),
56}
57
58#[derive(Debug, Clone)]
60pub struct MessageDef {
61 pub name: SmolStr,
62 pub span: Span,
63 pub fields: Vec<FieldDef>,
64 pub tombstones: Vec<TombstoneDef>,
65 pub annotations: ResolvedAnnotations,
66 pub wire_size: Option<WireSize>,
67}
68
69#[derive(Debug, Clone)]
71pub struct FieldDef {
72 pub name: SmolStr,
73 pub span: Span,
74 pub ordinal: u32,
75 pub resolved_type: ResolvedType,
76 pub encoding: FieldEncoding,
77 pub annotations: ResolvedAnnotations,
78}
79
80#[derive(Debug, Clone)]
81pub struct EnumDef {
82 pub name: SmolStr,
83 pub span: Span,
84 pub backing: Option<EnumBacking>,
87 pub variants: Vec<EnumVariantDef>,
88 pub tombstones: Vec<TombstoneDef>,
89 pub annotations: ResolvedAnnotations,
90 pub wire_bits: u8,
94}
95
96#[derive(Debug, Clone)]
98pub struct EnumVariantDef {
99 pub name: SmolStr,
100 pub span: Span,
101 pub ordinal: u32,
102 pub annotations: ResolvedAnnotations,
103}
104
105#[derive(Debug, Clone)]
106pub struct FlagsDef {
107 pub name: SmolStr,
108 pub span: Span,
109 pub bits: Vec<FlagsBitDef>,
110 pub tombstones: Vec<TombstoneDef>,
111 pub annotations: ResolvedAnnotations,
112 pub wire_bytes: u8,
114}
115
116#[derive(Debug, Clone)]
118pub struct FlagsBitDef {
119 pub name: SmolStr,
120 pub span: Span,
121 pub bit: u32,
122 pub annotations: ResolvedAnnotations,
123}
124
125#[derive(Debug, Clone)]
127pub struct UnionDef {
128 pub name: SmolStr,
129 pub span: Span,
130 pub variants: Vec<UnionVariantDef>,
131 pub tombstones: Vec<TombstoneDef>,
132 pub annotations: ResolvedAnnotations,
133 pub wire_size: Option<WireSize>,
134}
135
136#[derive(Debug, Clone)]
138pub struct UnionVariantDef {
139 pub name: SmolStr,
140 pub span: Span,
141 pub ordinal: u32,
142 pub fields: Vec<FieldDef>,
143 pub tombstones: Vec<TombstoneDef>,
144 pub annotations: ResolvedAnnotations,
145}
146
147#[derive(Debug, Clone)]
149pub struct NewtypeDef {
150 pub name: SmolStr,
151 pub span: Span,
152 pub inner_type: ResolvedType,
153 pub terminal_type: ResolvedType,
154 pub annotations: ResolvedAnnotations,
155}
156
157#[derive(Debug, Clone)]
159pub struct ConfigDef {
160 pub name: SmolStr,
161 pub span: Span,
162 pub fields: Vec<ConfigFieldDef>,
163 pub annotations: ResolvedAnnotations,
164}
165
166#[derive(Debug, Clone)]
168pub struct ConfigFieldDef {
169 pub name: SmolStr,
170 pub span: Span,
171 pub resolved_type: ResolvedType,
172 pub default_value: DefaultValue,
173 pub annotations: ResolvedAnnotations,
174}