Skip to content

Commit 361e958

Browse files
Mizuchimeta-codesync[bot]
authored andcommitted
Change map to use key-value array for binary, integer, etc
Summary: After this diff, we only use object form for string/enum keys. Note that today both string and binary are TType::T_STRING. We need to pass type tag to `writeMapBegin` in order to distinguish them. Reviewed By: iahs Differential Revision: D95452478 fbshipit-source-id: 3b48c722c1571d65a0084f876f0f553c33ccd42f
1 parent 61e3e72 commit 361e958

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

  • third-party/thrift/src/thrift/lib/cpp2/op/detail

third-party/thrift/src/thrift/lib/cpp2/op/detail/Encode.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,17 @@ struct MapEncode {
694694
template <typename Protocol, typename T>
695695
uint32_t operator()(Protocol& prot, const T& map) const {
696696
uint32_t xfer = 0;
697-
xfer += prot.writeMapBegin(
698-
typeTagToTType<Key>,
699-
typeTagToTType<Value>,
700-
checked_container_size(map.size()));
697+
if constexpr (requires {
698+
prot.template writeMapBegin<Key, Value>(std::int32_t{});
699+
}) {
700+
xfer += prot.template writeMapBegin<Key, Value>(
701+
checked_container_size(map.size()));
702+
} else {
703+
xfer += prot.writeMapBegin(
704+
typeTagToTType<Key>,
705+
typeTagToTType<Value>,
706+
checked_container_size(map.size()));
707+
}
701708

702709
if constexpr (
703710
!folly::is_detected_v<

0 commit comments

Comments
 (0)