Change code formatting in shared/protobuf_asio 74/234774/8
authorDariusz Michaluk <d.michaluk@samsung.com>
Thu, 28 May 2020 09:40:20 +0000 (11:40 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 6 Jul 2020 09:59:38 +0000 (11:59 +0200)
Change-Id: I1fb44ed5992955dc18f340407fccdfc2169a518a

shared/protobuf_asio.cpp
shared/protobuf_asio.h

index bacba2b..fd8a9fd 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************
  *
- * Copyright 2017 Samsung Electronics All Rights Reserved.
+ * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved.
  *
  * Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
  *
  *
  ******************************************************************/
 
-#include "protobuf_asio.h"
-#include <google/protobuf/io/coded_stream.h>
 #include <stdexcept>
 
+#include <google/protobuf/io/coded_stream.h>
+
+#include "protobuf_asio.h"
+
 protobuf_sync_message_serialization::protobuf_sync_message_serialization(
        boost::asio::local::stream_protocol::socket& socket) :
        fSocket(socket)
@@ -62,7 +64,7 @@ void protobuf_sync_message_deserialization::decodeMessage(google::protobuf::Mess
        boost::asio::read(fSocket, boost::asio::buffer(header));
        google::protobuf::io::CodedInputStream::ReadLittleEndian32FromArray(header, &length);
 
-       if(length < 1 || length > kDCMMessageMaxLength) {
+       if(length < 1 || length > MESSAGE_LENGHT_MAX) {
                throw std::length_error("Invalid message length");
        }
 
index c7ff16d..a040352 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************
  *
- * Copyright 2017 - 2019 Samsung Electronics All Rights Reserved.
+ * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved.
  *
  * Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
  *
 #ifndef SHARED_PROTOBUF_ASIO_H_
 #define SHARED_PROTOBUF_ASIO_H_
 
+#include <vector>
+
 #include <boost/asio.hpp>
 #include <boost/noncopyable.hpp>
 #include <google/protobuf/message_lite.h>
 #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
 #include <google/protobuf/io/coded_stream.h>
-#include <vector>
 
-static const size_t kDCMMessageMaxLength = 65536;
+static const size_t MESSAGE_LENGHT_MAX = 65536;
 
 class protobuf_sync_message_serialization final :
        boost::noncopyable,
@@ -37,26 +38,23 @@ class protobuf_sync_message_serialization final :
        boost::asio::local::stream_protocol::socket& fSocket;
 public:
        protobuf_sync_message_serialization(boost::asio::local::stream_protocol::socket& socket);
-
        void encodeMessage(const google::protobuf::MessageLite& message);
 
 private:
        virtual bool Write(const void* buffer, int size) override;
 };
 
-class protobuf_sync_message_deserialization final :
-       boost::noncopyable
+class protobuf_sync_message_deserialization final : boost::noncopyable
 {
        boost::asio::local::stream_protocol::socket& fSocket;
 public:
        protobuf_sync_message_deserialization(boost::asio::local::stream_protocol::socket& socket);
-
        void decodeMessage(google::protobuf::MessageLite& message);
 };
 
 class protobuf_async_message_serialization final : boost::noncopyable
 {
-       std::vector<char>               fBuffer;
+       std::vector<char> fBuffer;
 public:
        void encodeMessage(const google::protobuf::MessageLite& message);
 
@@ -67,51 +65,41 @@ public:
 
 class protobuf_async_message_deserialization final : public boost::noncopyable
 {
-       std::vector<char>       fBuffer;
+       std::vector<char> fBuffer;
        google::protobuf::uint32 fMessageLength = 0;
 public:
        protobuf_async_message_deserialization();
 
-       template<typename ReadSocket, typename ReadHandler> void read_message(ReadSocket& socket,
-                       ReadHandler&& handler) {
+       template<typename ReadSocket, typename ReadHandler> void read_message(ReadSocket& socket, ReadHandler&& handler) {
                fBuffer.resize(4);
                fMessageLength = 0;
 
                boost::asio::async_read(socket, boost::asio::buffer(fBuffer),
-                               [this, handler, &socket](const boost::system::error_code& error, std::size_t bytes_read) {
-                                       if(!error) {
-                                               assert(bytes_read == fBuffer.size());
-                                               (void)bytes_read;
-                                               assert(fMessageLength == 0);
-
-                                               google::protobuf::io::CodedInputStream::ReadLittleEndian32FromArray(
-                                                               (const google::protobuf::uint8 *)&fBuffer[0],
-                                                               &fMessageLength);
-
-                                               if(fMessageLength >= 1 && fMessageLength < kDCMMessageMaxLength) {
-                                                       try {
-                                                               fBuffer.resize(fMessageLength);
-                                                       } catch(...) {
-                                                               handler(
-                                                                               boost::system::errc::make_error_code(
-                                                                                               boost::system::errc::not_enough_memory),
-                                                                               0);
-                                                               return;
-                                                       }
-
-                                                       boost::asio::async_read(socket,
-                                                                       boost::asio::buffer(fBuffer),
-                                                                       handler);
-                                               } else {
-                                                       handler(
-                                                                       boost::system::errc::make_error_code(
-                                                                                       boost::system::errc::message_size),
-                                                                       0);
+                       [this, handler, &socket](const boost::system::error_code& error, std::size_t bytes_read) {
+                               if(!error) {
+                                       assert(bytes_read == fBuffer.size());
+                                       (void)bytes_read;
+                                       assert(fMessageLength == 0);
+
+                                       google::protobuf::io::CodedInputStream::ReadLittleEndian32FromArray(
+                                               (const google::protobuf::uint8 *)&fBuffer[0], &fMessageLength);
+
+                                       if(fMessageLength >= 1 && fMessageLength < MESSAGE_LENGHT_MAX) {
+                                               try {
+                                                       fBuffer.resize(fMessageLength);
+                                               } catch(...) {
+                                                       handler(boost::system::errc::make_error_code(boost::system::errc::not_enough_memory), 0);
+                                                       return;
                                                }
+
+                                               boost::asio::async_read(socket, boost::asio::buffer(fBuffer), handler);
                                        } else {
-                                               handler(error, 0);
+                                               handler(boost::system::errc::make_error_code(boost::system::errc::message_size), 0);
                                        }
-                               });
+                               } else {
+                                       handler(error, 0);
+                               }
+               });
        }
 
        bool decode_received_message(google::protobuf::MessageLite& message);