Skip to content

Commit

Permalink
Add fbstring specialization for AOR populator
Browse files Browse the repository at this point in the history
Summary: Add fbstring specialization which simply forward to std::string version.

Reviewed By: iahs

Differential Revision: D68002568

fbshipit-source-id: 10db20da7b681a00d6c2d7c4a78eacdf8ddce43f
  • Loading branch information
thedavekwon authored and facebook-github-bot committed Jan 13, 2025
1 parent 4c7099f commit 9cab624
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions thrift/lib/cpp2/reflection/populator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
#pragma once

#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <random>
#include <type_traits>
#include <vector>

#include <folly/FBString.h>
#include <folly/Traits.h>
#include <folly/io/Cursor.h>
#include <thrift/lib/cpp2/FieldRefTraits.h>
Expand Down Expand Up @@ -211,6 +210,19 @@ struct populator_methods<type::string_t, std::string> {
}
};

template <>
struct populator_methods<
type::cpp_type<folly::fbstring, type::string_t>,
folly::fbstring> {
template <typename Rng>
static void populate(
Rng& rng, const populator_opts& opts, folly::fbstring& bin) {
std::string t;
populator_methods<type::string_t, std::string>::populate(rng, opts, t);
bin = folly::fbstring(std::move(t));
}
};

template <typename Rng, typename Binary, typename WriteFunc>
void generate_bytes(
Rng& rng, Binary&, const std::size_t length, const WriteFunc& write_func) {
Expand All @@ -232,6 +244,19 @@ struct populator_methods<type::binary_t, std::string> {
}
};

template <>
struct populator_methods<
type::cpp_type<folly::fbstring, type::binary_t>,
folly::fbstring> {
template <typename Rng>
static void populate(
Rng& rng, const populator_opts& opts, folly::fbstring& bin) {
std::string t;
populator_methods<type::binary_t, std::string>::populate(rng, opts, t);
bin = folly::fbstring(std::move(t));
}
};

template <>
struct populator_methods<
type::cpp_type<folly::IOBuf, type::binary_t>,
Expand Down

0 comments on commit 9cab624

Please sign in to comment.