From 060471a0cef0ee12840dc9367909a17978069a0e Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Thu, 20 Jul 2017 16:52:28 -0700 Subject: [PATCH] Apply clang-format to folly/experimental/bser/ Summary: [Folly] Apply `clang-format` to `folly/experimental/bser/`. Reviewed By: Orvid Differential Revision: D5460552 fbshipit-source-id: e103f8920eb29b7c14688f5bbb3e28129ef35e96 --- folly/experimental/bser/Bser.h | 5 +- folly/experimental/bser/Dump.cpp | 56 +++++++++++++---------- folly/experimental/bser/Load.cpp | 16 ++++--- folly/experimental/bser/test/BserTest.cpp | 28 +++++++----- 4 files changed, 59 insertions(+), 46 deletions(-) diff --git a/folly/experimental/bser/Bser.h b/folly/experimental/bser/Bser.h index c054cd4b..be06e9ff 100644 --- a/folly/experimental/bser/Bser.h +++ b/folly/experimental/bser/Bser.h @@ -94,8 +94,9 @@ folly::dynamic parseBser(const folly::IOBuf*); size_t decodePduLength(const folly::IOBuf*); folly::fbstring toBser(folly::dynamic const&, const serialization_opts&); -std::unique_ptr toBserIOBuf(folly::dynamic const&, - const serialization_opts&); +std::unique_ptr toBserIOBuf( + folly::dynamic const&, + const serialization_opts&); } } diff --git a/folly/experimental/bser/Dump.cpp b/folly/experimental/bser/Dump.cpp index 461f38ae..58a2da1d 100644 --- a/folly/experimental/bser/Dump.cpp +++ b/folly/experimental/bser/Dump.cpp @@ -27,15 +27,17 @@ namespace bser { const uint8_t kMagic[2] = {0, 1}; -static void bserEncode(dynamic const& dyn, - QueueAppender& appender, - const serialization_opts& opts); +static void bserEncode( + dynamic const& dyn, + QueueAppender& appender, + const serialization_opts& opts); serialization_opts::serialization_opts() : sort_keys(false), growth_increment(8192) {} -static const dynamic* getTemplate(const serialization_opts& opts, - dynamic const& dynArray) { +static const dynamic* getTemplate( + const serialization_opts& opts, + dynamic const& dynArray) { if (!opts.templates.hasValue()) { return nullptr; } @@ -50,9 +52,9 @@ static const dynamic* getTemplate(const serialization_opts& opts, static void bserEncodeInt(int64_t ival, QueueAppender& appender) { /* Return the smallest size int that can store the value */ auto size = - ((ival == ((int8_t)ival)) ? 1 : (ival == ((int16_t)ival)) - ? 2 - : (ival == ((int32_t)ival)) ? 4 : 8); + ((ival == ((int8_t)ival)) + ? 1 + : (ival == ((int16_t)ival)) ? 2 : (ival == ((int32_t)ival)) ? 4 : 8); switch (size) { case 1: @@ -82,9 +84,10 @@ static void bserEncodeString(folly::StringPiece str, QueueAppender& appender) { appender.push((uint8_t*)str.data(), str.size()); } -static void bserEncodeArraySimple(dynamic const& dyn, - QueueAppender& appender, - const serialization_opts& opts) { +static void bserEncodeArraySimple( + dynamic const& dyn, + QueueAppender& appender, + const serialization_opts& opts) { appender.write((int8_t)BserType::Array); bserEncodeInt(int64_t(dyn.size()), appender); for (const auto& ele : dyn) { @@ -92,10 +95,10 @@ static void bserEncodeArraySimple(dynamic const& dyn, } } -static void bserEncodeArray(dynamic const& dyn, - QueueAppender& appender, - const serialization_opts& opts) { - +static void bserEncodeArray( + dynamic const& dyn, + QueueAppender& appender, + const serialization_opts& opts) { auto templ = getTemplate(opts, dyn); if (UNLIKELY(templ != nullptr)) { appender.write((int8_t)BserType::Template); @@ -129,15 +132,16 @@ static void bserEncodeArray(dynamic const& dyn, bserEncodeArraySimple(dyn, appender, opts); } -static void bserEncodeObject(dynamic const& dyn, - QueueAppender& appender, - const serialization_opts& opts) { +static void bserEncodeObject( + dynamic const& dyn, + QueueAppender& appender, + const serialization_opts& opts) { appender.write((int8_t)BserType::Object); bserEncodeInt(int64_t(dyn.size()), appender); if (opts.sort_keys) { - std::vector> sorted(dyn.items().begin(), - dyn.items().end()); + std::vector> sorted( + dyn.items().begin(), dyn.items().end()); std::sort(sorted.begin(), sorted.end()); for (const auto& item : sorted) { bserEncode(item.first, appender, opts); @@ -151,9 +155,10 @@ static void bserEncodeObject(dynamic const& dyn, } } -static void bserEncode(dynamic const& dyn, - QueueAppender& appender, - const serialization_opts& opts) { +static void bserEncode( + dynamic const& dyn, + QueueAppender& appender, + const serialization_opts& opts) { switch (dyn.type()) { case dynamic::Type::NULLT: appender.write((int8_t)BserType::Null); @@ -183,8 +188,9 @@ static void bserEncode(dynamic const& dyn, } } -std::unique_ptr toBserIOBuf(folly::dynamic const& dyn, - const serialization_opts& opts) { +std::unique_ptr toBserIOBuf( + folly::dynamic const& dyn, + const serialization_opts& opts) { IOBufQueue q(IOBufQueue::cacheChainLength()); uint8_t hdrbuf[sizeof(kMagic) + 1 + sizeof(int64_t)]; diff --git a/folly/experimental/bser/Load.cpp b/folly/experimental/bser/Load.cpp index 1c210817..d1b8185b 100644 --- a/folly/experimental/bser/Load.cpp +++ b/folly/experimental/bser/Load.cpp @@ -28,10 +28,11 @@ static dynamic parseBser(Cursor& curs); template [[noreturn]] static void throwDecodeError(Cursor& curs, ARGS&&... args) { - throw BserDecodeError(folly::to(std::forward(args)..., - " with ", - curs.length(), - " bytes remaining in cursor")); + throw BserDecodeError(folly::to( + std::forward(args)..., + " with ", + curs.length(), + " bytes remaining in cursor")); } static int64_t decodeInt(Cursor& curs) { @@ -65,9 +66,10 @@ static std::string decodeString(Cursor& curs) { if (available == 0) { // Saw this case when we decodeHeader was returning the incorrect length // and we were splitting off too few bytes from the IOBufQueue - throwDecodeError(curs, - "no data available while decoding a string, header was " - "not decoded properly"); + throwDecodeError( + curs, + "no data available while decoding a string, header was " + "not decoded properly"); } str.append(reinterpret_cast(curs.data()), available); curs.skipAtMost(available); diff --git a/folly/experimental/bser/test/BserTest.cpp b/folly/experimental/bser/test/BserTest.cpp index 5f03dd81..9c053558 100644 --- a/folly/experimental/bser/test/BserTest.cpp +++ b/folly/experimental/bser/test/BserTest.cpp @@ -67,7 +67,8 @@ TEST(Bser, RoundTrip) { } catch (const std::exception& err) { LOG(ERROR) << err.what() << "\nInput: " << dyn.typeName() << ": " << dyn << " decoded back as " << decoded.typeName() << ": " << decoded - << "\n" << folly::hexDump(str.data(), str.size()); + << "\n" + << folly::hexDump(str.data(), str.size()); throw; } } @@ -80,8 +81,8 @@ TEST(Bser, Template) { decoded = folly::bser::parseBser( folly::ByteRange(template_blob, sizeof(template_blob) - 1)); EXPECT_EQ(decoded, template_dynamic) - << "Didn't load template value." - "\nInput: " << template_dynamic.typeName() << ": " << template_dynamic + << "Didn't load template value.\n" + << "Input: " << template_dynamic.typeName() << ": " << template_dynamic << " decoded back as " << decoded.typeName() << ": " << decoded << "\n" << folly::hexDump(template_blob, sizeof(template_blob) - 1); @@ -92,21 +93,24 @@ TEST(Bser, Template) { opts.templates = templates; str = folly::bser::toBser(decoded, opts); - EXPECT_EQ(folly::ByteRange((const uint8_t*)str.data(), str.size()), - folly::ByteRange(template_blob, sizeof(template_blob) - 1)) + EXPECT_EQ( + folly::ByteRange((const uint8_t*)str.data(), str.size()), + folly::ByteRange(template_blob, sizeof(template_blob) - 1)) << "Expected:\n" << folly::hexDump(template_blob, sizeof(template_blob) - 1) << "\nGot:\n" << folly::hexDump(str.data(), str.size()); } TEST(Bser, PduLength) { - EXPECT_THROW([] { - // Try to decode PDU for a short buffer that doesn't even have the - // complete length available - auto buf = folly::IOBuf::wrapBuffer(template_blob, 3); - auto len = folly::bser::decodePduLength(&*buf); - LOG(ERROR) << "managed to return a length, but only had 3 bytes"; - }(), std::out_of_range); + EXPECT_THROW( + [] { + // Try to decode PDU for a short buffer that doesn't even have the + // complete length available + auto buf = folly::IOBuf::wrapBuffer(template_blob, 3); + auto len = folly::bser::decodePduLength(&*buf); + LOG(ERROR) << "managed to return a length, but only had 3 bytes"; + }(), + std::out_of_range); auto buf = folly::IOBuf::wrapBuffer(template_blob, sizeof(template_blob)); auto len = folly::bser::decodePduLength(&*buf); -- 2.34.1