Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: Add the support for structured annotations #13

Merged
merged 10 commits into from
Oct 10, 2024
Merged
Prev Previous commit
Next Next commit
lib/rb: Handle the PreviouslyKnownAs annotation seamlessly
  • Loading branch information
AlexisMontagne committed Oct 8, 2024
commit ad51db7d2892b43bcb1ab56e61e41e425c485400
15 changes: 10 additions & 5 deletions compiler/cpp/src/generate/t_rb_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class t_rb_generator : public t_oop_generator {
t_type* field_type,
const std::string& field_name,
t_const_value* field_value,
bool optional);
bool optional,
bool embed_annotations);

/**
* Service-level generation functions
Expand Down Expand Up @@ -747,7 +748,8 @@ void t_rb_generator::generate_field_defns(t_rb_ofstream& out, t_struct* tstruct)
(*f_iter)->get_type(),
(*f_iter)->get_name(),
(*f_iter)->get_value(),
(*f_iter)->get_req() == t_field::T_OPTIONAL);
(*f_iter)->get_req() == t_field::T_OPTIONAL,
true);
}
out.indent_down();
out << endl;
Expand All @@ -760,7 +762,8 @@ void t_rb_generator::generate_field_data(t_rb_ofstream& out,
t_type* field_type,
const std::string& field_name = "",
t_const_value* field_value = NULL,
bool optional = false) {
bool optional = false,
bool embed_annotations = false) {
field_type = get_true_type(field_type);

// Begin this field's defn
Expand Down Expand Up @@ -804,8 +807,10 @@ void t_rb_generator::generate_field_data(t_rb_ofstream& out,
out << ", enum_class: " << full_type_name(field_type);
}

out << ", legacy_annotations: THRIFT_FIELD_" << upcase_string(field_name) << "_LEGACY_ANNOTATIONS";
out << ", structured_annotations: THRIFT_FIELD_" << upcase_string(field_name) << "_STRUCTURED_ANNOTATIONS";
if (embed_annotations) {
out << ", legacy_annotations: THRIFT_FIELD_" << upcase_string(field_name) << "_LEGACY_ANNOTATIONS";
out << ", structured_annotations: THRIFT_FIELD_" << upcase_string(field_name) << "_STRUCTURED_ANNOTATIONS";
}

// End of this field's defn
out << "}";
Expand Down
19 changes: 19 additions & 0 deletions lib/rb/lib/thrift/definition.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module Thrift
class DefaultCanonicalNameExtractor
class << self
def extract(definition)
[definition.struct_type]
end
end
end

class StructDefinition
attr_reader :klass

Expand All @@ -25,6 +33,12 @@ def name
def struct_type
"#{namespace}.#{name}"
end

def canonical_names
CANONICAL_NAME_EXTRACTORS.reduce([]) do |acc, cur|
acc + cur.extract(self)
end
end
end

class ServiceDefinition < StructDefinition
Expand All @@ -51,6 +65,7 @@ def service_type

STRUCT_DEFINITIONS = {}
SERVICE_DEFINITIONS = {}
CANONICAL_NAME_EXTRACTORS = [DefaultCanonicalNameExtractor]

class << self
def register_struct_type(klass)
Expand All @@ -62,5 +77,9 @@ def register_service_type(klass)
definition = ServiceDefinition.new(klass)
SERVICE_DEFINITIONS[definition.service_type] = definition
end

def register_canonical_name_extractor(klass)
CANONICAL_NAME_EXTRACTORS << klass
end
end
end
14 changes: 14 additions & 0 deletions lib/rb/lib/thrift/types/annotation/naming_types.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/rb/lib/thrift/types/value_types.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading