Skip to content

Commit e27994b

Browse files
thedavekwonfacebook-github-bot
authored andcommitted
move rawAnnotation to detail/TypeSystem.h
Summary: plan to share this method in materializing SerializableTypeSystem from TypeSystem Reviewed By: pranavtbhat Differential Revision: D79855966 fbshipit-source-id: 8f29b2053539ca2c3cb6a35a18a746485052ed7c
1 parent 41cc512 commit e27994b

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed

third-party/thrift/src/thrift/lib/cpp2/dynamic/TypeSystem.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <thrift/lib/cpp2/dynamic/SerializableRecord.h>
2020
#include <thrift/lib/cpp2/dynamic/TypeId.h>
2121
#include <thrift/lib/cpp2/dynamic/detail/Traits.h>
22+
#include <thrift/lib/cpp2/dynamic/detail/TypeSystem.h>
2223
#include <thrift/lib/thrift/gen-cpp2/type_system_types.h>
2324

2425
#include <folly/CppAttributes.h>
@@ -499,11 +500,7 @@ class InvalidTypeError : public std::runtime_error {
499500
using std::runtime_error::runtime_error;
500501
};
501502

502-
using AnnotationsMap = folly::F14FastMap<
503-
Uri,
504-
SerializableRecord,
505-
detail::UriHeterogeneousHash,
506-
std::equal_to<>>;
503+
using AnnotationsMap = detail::AnnotationsMap;
507504

508505
namespace detail {
509506

third-party/thrift/src/thrift/lib/cpp2/dynamic/TypeSystemBuilder.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <thrift/lib/cpp2/dynamic/TypeSystemBuilder.h>
18+
#include <thrift/lib/cpp2/dynamic/detail/TypeSystem.h>
1819

1920
#include <folly/Overload.h>
2021
#include <folly/container/F14Set.h>
@@ -459,20 +460,6 @@ void TypeSystemBuilder::tryEmplace(Uri uri, DefinitionEntry&& def) {
459460
}
460461
}
461462

462-
namespace {
463-
464-
using RawAnnotations = folly::F14FastMap<Uri, SerializableRecordUnion>;
465-
466-
static RawAnnotations toRawAnnotations(const AnnotationsMap& annotations) {
467-
RawAnnotations raw;
468-
for (const auto& [uri, record] : annotations) {
469-
raw.emplace(uri, SerializableRecord::toThrift(record));
470-
}
471-
return raw;
472-
}
473-
474-
} // namespace
475-
476463
/* static */ FieldIdentity TypeSystemBuilder::DefinitionHelper::Identity(
477464
std::int16_t id, std::string_view name) {
478465
return FieldIdentity{FieldId{id}, std::string(name)};
@@ -492,7 +479,7 @@ TypeSystemBuilder::DefinitionHelper::Field(
492479
if (customDefault.has_value()) {
493480
def.customDefaultValue() = SerializableRecord::toThrift(*customDefault);
494481
}
495-
def.annotations() = toRawAnnotations(annotations);
482+
def.annotations() = detail::toRawAnnotations(annotations);
496483
return def;
497484
}
498485

@@ -504,7 +491,7 @@ TypeSystemBuilder::DefinitionHelper::Struct(
504491
SerializableStructDefinition def;
505492
def.fields() = fields;
506493
def.isSealed() = isSealed;
507-
def.annotations() = toRawAnnotations(annotations);
494+
def.annotations() = detail::toRawAnnotations(annotations);
508495
return def;
509496
}
510497

@@ -516,7 +503,7 @@ TypeSystemBuilder::DefinitionHelper::Union(
516503
SerializableUnionDefinition def;
517504
def.fields() = fields;
518505
def.isSealed() = isSealed;
519-
def.annotations() = toRawAnnotations(annotations);
506+
def.annotations() = detail::toRawAnnotations(annotations);
520507
return def;
521508
}
522509

@@ -528,10 +515,10 @@ TypeSystemBuilder::DefinitionHelper::Enum(
528515
SerializableEnumValueDefinition v;
529516
v.name() = name;
530517
v.datum() = value;
531-
v.annotations() = toRawAnnotations(enumValueAnnotations);
518+
v.annotations() = detail::toRawAnnotations(enumValueAnnotations);
532519
enumDef.values()->emplace_back(std::move(v));
533520
}
534-
enumDef.annotations() = toRawAnnotations(annotations);
521+
enumDef.annotations() = detail::toRawAnnotations(annotations);
535522
return enumDef;
536523
}
537524

@@ -540,7 +527,7 @@ TypeSystemBuilder::DefinitionHelper::OpaqueAlias(
540527
TypeId targetType, const AnnotationsMap& annotations) {
541528
SerializableOpaqueAliasDefinition def;
542529
def.targetType() = targetType;
543-
def.annotations() = toRawAnnotations(annotations);
530+
def.annotations() = detail::toRawAnnotations(annotations);
544531
return def;
545532
}
546533

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <folly/container/F14Map.h>
20+
#include <thrift/lib/cpp2/dynamic/SerializableRecord.h>
21+
#include <thrift/lib/cpp2/dynamic/TypeId.h>
22+
23+
namespace apache::thrift::type_system::detail {
24+
25+
using RawAnnotations = folly::F14FastMap<
26+
apache::thrift::type_system::Uri,
27+
apache::thrift::type_system::SerializableRecordUnion>;
28+
29+
using AnnotationsMap = folly::
30+
F14FastMap<Uri, SerializableRecord, UriHeterogeneousHash, std::equal_to<>>;
31+
32+
inline RawAnnotations toRawAnnotations(const AnnotationsMap& annotations) {
33+
RawAnnotations raw;
34+
for (const auto& [uri, record] : annotations) {
35+
raw.emplace(uri, SerializableRecord::toThrift(record));
36+
}
37+
return raw;
38+
}
39+
} // namespace apache::thrift::type_system::detail

0 commit comments

Comments
 (0)