@@ -200,7 +200,7 @@ class TypeSystem {
200200 * Resolves an arbitrary TypeId ito a TypeRef.
201201 *
202202 * Throws:
203- * - InvalidTypeError if the TypeId references user-defined tyeps that are
203+ * - InvalidTypeError if the TypeId references user-defined types that are
204204 * not defined in the type system.
205205 */
206206 TypeRef resolveTypeId (const TypeId& typeId) const ;
@@ -218,6 +218,71 @@ class TypeSystem {
218218 * serializable.
219219 */
220220 virtual std::optional<folly::F14FastSet<Uri>> getKnownUris () const = 0;
221+
222+ /* *
223+ * Creates a TypeRef for the `bool` type — either true or false.
224+ */
225+ static TypeRef Bool () noexcept ;
226+ /* *
227+ * Creates a TypeRef for the `byte` type — 8-bit signed integer.
228+ */
229+ static TypeRef Byte () noexcept ;
230+ /* *
231+ * Creates a TypeRef for the `i16` type — 16-bit signed integer.
232+ */
233+ static TypeRef I16 () noexcept ;
234+ /* *
235+ * Creates a TypeRef for the `i32` type — 32-bit signed integer.
236+ */
237+ static TypeRef I32 () noexcept ;
238+ /* *
239+ * Creates a TypeRef for the `i64` type — 64-bit signed integer.
240+ */
241+ static TypeRef I64 () noexcept ;
242+ /* *
243+ * Creates a TypeRef for the `float` type — IEEE 754 binary32.
244+ */
245+ static TypeRef Float () noexcept ;
246+ /* *
247+ * Creates a TypeRef for the `double` type — IEEE 754 binary64.
248+ */
249+ static TypeRef Double () noexcept ;
250+ /* *
251+ * Creates a TypeRef for the `string` type — UTF-8 encoded bytes.
252+ */
253+ static TypeRef String () noexcept ;
254+ /* *
255+ * Creates a TypeRef for the `binary` type — a sequence of bytes.
256+ */
257+ static TypeRef Binary () noexcept ;
258+ /* *
259+ * Creates a TypeRef for the `any` type — a type-erased Thrift value.
260+ */
261+ static TypeRef Any () noexcept ;
262+
263+ /* *
264+ * Creates a TypeRef for a `list` type.
265+ * The provided element type must from the same type system.
266+ */
267+ TypeRef ListOf (TypeRef elementType) const ;
268+ /* *
269+ * Creates a TypeRef for a `set` type.
270+ * The provided element type must from the same type system.
271+ */
272+ TypeRef SetOf (TypeRef elementType) const ;
273+ /* *
274+ * Creates a TypeRef for a `list` type.
275+ * The provided key and value types must from the same type system.
276+ */
277+ TypeRef MapOf (TypeRef keyType, TypeRef valueType) const ;
278+
279+ /* *
280+ * Creates a TypeRef for a user-defined type.
281+ *
282+ * Throws:
283+ * - InvalidTypeError if the type is not defined in the type system.
284+ */
285+ TypeRef UserDefined (UriView) const ;
221286};
222287
223288/* *
@@ -997,6 +1062,62 @@ template <typename K, typename V>
9971062
9981063} // namespace detail
9991064
1065+ /* static */ inline TypeRef TypeSystem::Bool () noexcept {
1066+ return TypeRef (TypeRef::Bool ());
1067+ }
1068+
1069+ /* static */ inline TypeRef TypeSystem::Byte () noexcept {
1070+ return TypeRef (TypeRef::Byte ());
1071+ }
1072+
1073+ /* static */ inline TypeRef TypeSystem::I16 () noexcept {
1074+ return TypeRef (TypeRef::I16 ());
1075+ }
1076+
1077+ /* static */ inline TypeRef TypeSystem::I32 () noexcept {
1078+ return TypeRef (TypeRef::I32 ());
1079+ }
1080+
1081+ /* static */ inline TypeRef TypeSystem::I64 () noexcept {
1082+ return TypeRef (TypeRef::I64 ());
1083+ }
1084+
1085+ /* static */ inline TypeRef TypeSystem::Float () noexcept {
1086+ return TypeRef (TypeRef::Float ());
1087+ }
1088+
1089+ /* static */ inline TypeRef TypeSystem::Double () noexcept {
1090+ return TypeRef (TypeRef::Double ());
1091+ }
1092+
1093+ /* static */ inline TypeRef TypeSystem::String () noexcept {
1094+ return TypeRef (TypeRef::String ());
1095+ }
1096+
1097+ /* static */ inline TypeRef TypeSystem::Binary () noexcept {
1098+ return TypeRef (TypeRef::Binary ());
1099+ }
1100+
1101+ /* static */ inline TypeRef TypeSystem::Any () noexcept {
1102+ return TypeRef (TypeRef::Any ());
1103+ }
1104+
1105+ inline TypeRef TypeSystem::ListOf (TypeRef elementType) const {
1106+ return TypeRef (TypeRef::List::of (std::move (elementType)));
1107+ }
1108+
1109+ inline TypeRef TypeSystem::SetOf (TypeRef elementType) const {
1110+ return TypeRef (TypeRef::Set::of (std::move (elementType)));
1111+ }
1112+
1113+ inline TypeRef TypeSystem::MapOf (TypeRef keyType, TypeRef valueType) const {
1114+ return TypeRef (TypeRef::Map::of (std::move (keyType), std::move (valueType)));
1115+ }
1116+
1117+ inline TypeRef TypeSystem::UserDefined (UriView uri) const {
1118+ return TypeRef::fromDefinition (this ->getUserDefinedTypeOrThrow (uri));
1119+ }
1120+
10001121} // namespace apache::thrift::type_system
10011122
10021123namespace std {
0 commit comments