Skip to content

Commit

Permalink
Merge pull request #1 from abclogin/issue/126/fix-long-long-upgrade
Browse files Browse the repository at this point in the history
fix: explicitly cast unspecified chrono rep type
  • Loading branch information
abclogin committed Jun 6, 2016
2 parents e288ae7 + b32339c commit 4bb721c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/formatter/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ struct visitor_t {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), rapidjson::kNullType, allocator);
}

// For `bool`, `std::int64_t`, `std::uint64_t` and `double` types.
template<typename T>
auto operator()(T value) -> void {
static_assert(
std::is_same<T, bool>::value ||
std::is_same<T, std::int64_t>::value ||
std::is_same<T, std::uint64_t>::value ||
std::is_same<T, double>::value, "type mismatch");
auto operator()(bool value) -> void {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator);
}

auto operator()(std::int64_t value) -> void {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator);
}

auto operator()(std::uint64_t value) -> void {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator);
}

auto operator()(double value) -> void {
node.AddMember(rapidjson::StringRef(name.data(), name.size()), value, allocator);
}

Expand Down Expand Up @@ -219,9 +224,10 @@ class json_t::inner_t::builder {
inner.timestamp(record.timestamp(), wr);
apply("timestamp", wr.inner.data(), wr.inner.size());
} else {
apply("timestamp", std::chrono::duration_cast<
const auto timestamp = std::chrono::duration_cast<
std::chrono::microseconds
>(record.timestamp().time_since_epoch()).count());
>(record.timestamp().time_since_epoch()).count();
apply("timestamp", static_cast<std::int64_t>(timestamp));
}
}

Expand Down

0 comments on commit 4bb721c

Please sign in to comment.