adamdebreceni commented on a change in pull request #864:
URL: https://github.com/apache/nifi-minifi-cpp/pull/864#discussion_r486275648



##########
File path: libminifi/include/io/CRCStream.h
##########
@@ -34,307 +35,111 @@
 #endif
 #include "BaseStream.h"
 #include "Exception.h"
-#include "Serializable.h"
 
 namespace org {
 namespace apache {
 namespace nifi {
 namespace minifi {
 namespace io {
+namespace internal {
 
-template<typename T>
-class CRCStream : public BaseStream {
+template<typename StreamType>
+class CRCStreamBase : public virtual Stream {
  public:
-  /**
-   * Raw pointer because the caller guarantees that
-   * it will exceed our lifetime.
-   */
-  explicit CRCStream(T *child_stream);
-  CRCStream(T *child_stream, uint64_t initial_crc);
-
-  CRCStream(CRCStream<T>&&) noexcept;
-
-  ~CRCStream() override = default;
-
-  T *getstream() const {
+  StreamType *getstream() const {
     return child_stream_;
   }
 
-  void disableEncoding() {
-    disable_encoding_ = true;
-  }
-
-  /**
-   * Reads data and places it into buf
-   * @param buf buffer in which we extract data
-   * @param buflen
-   */
-  int readData(std::vector<uint8_t> &buf, int buflen) override;
-  /**
-   * Reads data and places it into buf
-   * @param buf buffer in which we extract data
-   * @param buflen
-   */
-  int readData(uint8_t *buf, int buflen) override;
-
-  /**
-   * Write value to the stream using std::vector
-   * @param buf incoming buffer
-   * @param buflen buffer to write
-   */
-  virtual int writeData(std::vector<uint8_t> &buf, int buflen);
-
-  /**
-   * writes value to stream
-   * @param value value to write
-   * @param size size of value
-   */
-  int writeData(uint8_t *value, int size) override;
-
-  using BaseStream::write;
-
-  /**
-   * write 4 bytes to stream
-   * @param base_value non encoded value
-   * @param stream output stream
-   * @param is_little_endian endianness determination
-   * @return resulting write size
-   **/
-  int write(uint32_t base_value, bool is_little_endian = 
EndiannessCheck::IS_LITTLE) override;
-  /**
-   * write 2 bytes to stream
-   * @param base_value non encoded value
-   * @param stream output stream
-   * @param is_little_endian endianness determination
-   * @return resulting write size
-   **/
-  int write(uint16_t base_value, bool is_little_endian = 
EndiannessCheck::IS_LITTLE) override;
-
-  /**
-   * write 8 bytes to stream
-   * @param base_value non encoded value
-   * @param stream output stream
-   * @param is_little_endian endianness determination
-   * @return resulting write size
-   **/
-  int write(uint64_t base_value, bool is_little_endian = 
EndiannessCheck::IS_LITTLE) override;
+  void close() override { child_stream_->close(); }
 
-  /**
-   * Reads a system word
-   * @param value value to write
-   */
-  int read(uint64_t &value, bool is_little_endian = 
EndiannessCheck::IS_LITTLE) override;
-
-  /**
-   * Reads a uint32_t
-   * @param value value to write
-   */
-  int read(uint32_t &value, bool is_little_endian = 
EndiannessCheck::IS_LITTLE) override;
-
-  /**
-   * Reads a system short
-   * @param value value to write
-   */
-  int read(uint16_t &value, bool is_little_endian = 
EndiannessCheck::IS_LITTLE) override;
-
-  const size_t getSize() const override { return child_stream_->getSize(); }
-
-  void closeStream() override { child_stream_->closeStream(); }
-
-  short initialize() override { // NOLINT
+  int initialize() override {
     child_stream_->initialize();
     reset();
     return 0;
   }
 
-  void updateCRC(uint8_t *buffer, uint32_t length);
+  void updateCRC(uint8_t *buffer, uint32_t length) {
+    crc_ = crc32(crc_, buffer, length);
+  }
 
   uint64_t getCRC() {
-    return crc_;
+    return gsl::narrow<uint64_t>(crc_);
   }
 
-  void reset();
-
- protected:
-  /**
-   * Creates a vector and returns the vector using the provided
-   * type name.
-   * @param t incoming object
-   * @returns vector.
-   */
-  template<typename K>
-  std::vector<uint8_t> readBuffer(const K& t) {
-    std::vector<uint8_t> buf;
-    readBuffer(buf, t);
-    return buf;
+  void reset() {
+    crc_ = crc32(0L, Z_NULL, 0);
   }
 
-  /**
-   * Populates the vector using the provided type name.
-   * @param buf output buffer
-   * @param t incoming object
-   * @returns number of bytes read.
-   */
-  template<typename K>
-  int readBuffer(std::vector<uint8_t>& buf, const K& t) {
-    buf.resize(sizeof t);
-    return readData(reinterpret_cast<uint8_t*>(buf.data()), sizeof(t));
+ protected:
+  explicit CRCStreamBase(gsl::not_null<StreamType*> child_stream) : 
child_stream_(child_stream) {}
+  //  this implementation is here to make MSVC happy, declaration would be 
enough
+  //  as it will never get called (and should not be called)
+  CRCStreamBase() : child_stream_(gsl::make_not_null<StreamType*>(nullptr)) {
+    assert(false);

Review comment:
       I am not sure what is the standard-compliant behavior here, but gcc and 
clang both accept the following, but msvc complained for the undefined 
reference `A::A()`
   
   ```
   struct A {
     A();  // is a declaration enough?
     A(int x) : x(x) {}
   
    private:
     int x;
   };
   
   struct B : virtual A {};
   
   struct C : virtual A {};
   
   struct D : B, C {
     D(int x): A(x) {} 
   };
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to