Skip to content

Commit

Permalink
Support null bytes in definition keys
Browse files Browse the repository at this point in the history
Summary: Since these are byte strings we have to handle the case where one of the bytes is zero

Reviewed By: createdbysk

Differential Revision: D67954736

fbshipit-source-id: 70e57eb1def45e40afa050935111cbed8d794071
  • Loading branch information
iahs authored and facebook-github-bot committed Jan 9, 2025
1 parent 05392a8 commit 5d6851d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ class cpp_mstch_service : public mstch_service {
&cpp_mstch_service::has_service_schema},
{"service:reduced_client?", &cpp_mstch_service::reduced_client},
{"service:definition_key", &cpp_mstch_service::definition_key},
{"service:definition_key_length",
&cpp_mstch_service::definition_key_length},
});

const auto all_functions = mstch_service::get_functions();
Expand Down Expand Up @@ -910,6 +912,10 @@ class cpp_mstch_service : public mstch_service {
schematizer s(*service_->program()->scope(), sm_, {});
return escape_binary_string(s.identify_definition(*service_));
}
mstch::node definition_key_length() {
schematizer s(*service_->program()->scope(), sm_, {});
return escape_binary_string(s.identify_definition(*service_)).length();
}

private:
const std::vector<t_function*>& get_functions() const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ std::optional<apache::thrift::schema::DefinitionsSchema> {{> service_common/serv
{{#program:has_schema?}}
std::optional<apache::thrift::schema::DefinitionsSchema> ret = schema::DefinitionsSchema{};
ret->schema = ::apache::thrift::SchemaRegistry::mergeSchemas(::{{service:qualified_namespace}}::{{program:name}}_constants::{{program:schema_name}}_includes());
ret->definitions = {"{{service:definition_key}}"};
ret->definitions = { {"{{service:definition_key}}", {{service:definition_key_length}}} };
return ret;
{{/program:has_schema?}}
{{^program:has_schema?}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ apache::thrift::ServiceHandler<::cpp2::PrimitivesService>::CreateMethodMetadataR
std::optional<apache::thrift::schema::DefinitionsSchema> apache::thrift::ServiceHandler<::cpp2::PrimitivesService>::getServiceSchema() {
std::optional<apache::thrift::schema::DefinitionsSchema> ret = schema::DefinitionsSchema{};
ret->schema = ::apache::thrift::SchemaRegistry::mergeSchemas(::cpp2::module_constants::_fbthrift_schema_b747839c13cb3aa5_includes());
ret->definitions = {"\x0d\x05\x1d\xbc\xb2\xd5\x1d\x8f\x95\x45\xbb\x51\xfa\xcf\x0f\xfe"};
ret->definitions = { {"\x0d\x05\x1d\xbc\xb2\xd5\x1d\x8f\x95\x45\xbb\x51\xfa\xcf\x0f\xfe", 64} };
return ret;
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ apache::thrift::ServiceHandler<::cpp2::PrimitivesService>::CreateMethodMetadataR
std::optional<apache::thrift::schema::DefinitionsSchema> apache::thrift::ServiceHandler<::cpp2::PrimitivesService>::getServiceSchema() {
std::optional<apache::thrift::schema::DefinitionsSchema> ret = schema::DefinitionsSchema{};
ret->schema = ::apache::thrift::SchemaRegistry::mergeSchemas(::cpp2::module_constants::_fbthrift_schema_b747839c13cb3aa5_includes());
ret->definitions = {"\x0d\x05\x1d\xbc\xb2\xd5\x1d\x8f\x95\x45\xbb\x51\xfa\xcf\x0f\xfe"};
ret->definitions = { {"\x0d\x05\x1d\xbc\xb2\xd5\x1d\x8f\x95\x45\xbb\x51\xfa\xcf\x0f\xfe", 64} };
return ret;
}
#endif
Expand Down

0 comments on commit 5d6851d

Please sign in to comment.