szaszm commented on code in PR #1974: URL: https://github.com/apache/nifi-minifi-cpp/pull/1974#discussion_r2382900318
########## libminifi/include/sitetosite/CompressionOutputStream.h: ########## @@ -0,0 +1,49 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include "io/OutputStream.h" +#include "io/BaseStream.h" +#include "utils/gsl.h" +#include "CompressionConsts.h" +#include "core/logging/LoggerFactory.h" + +namespace org::apache::nifi::minifi::sitetosite { + +class CompressionOutputStream : public io::StreamImpl, public virtual io::OutputStreamImpl { + public: + explicit CompressionOutputStream(gsl::not_null<io::OutputStream*> internal_stream) Review Comment: same. In parameters, we don't need mutability, so references are a simpler way to represent not nullable pointers. ########## libminifi/include/sitetosite/CompressionInputStream.h: ########## @@ -0,0 +1,53 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include "io/InputStream.h" +#include "io/BufferStream.h" +#include "CompressionConsts.h" +#include "core/logging/LoggerFactory.h" + +namespace org::apache::nifi::minifi::sitetosite { + +class CompressionInputStream : public io::InputStreamImpl { + public: + explicit CompressionInputStream(gsl::not_null<io::InputStream*> internal_stream) Review Comment: I'd make that a reference and convert to pointer on the init list ########## libminifi/src/sitetosite/CompressionOutputStream.cpp: ########## @@ -0,0 +1,127 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "sitetosite/CompressionOutputStream.h" + +#include "io/ZlibStream.h" +#include "io/StreamPipe.h" +#include "io/BufferStream.h" +#include "core/logging/LoggerFactory.h" + +namespace org::apache::nifi::minifi::sitetosite { + +size_t CompressionOutputStream::write(const uint8_t *value, size_t len) { + if (value == nullptr || len == 0) { + return 0; + } + + size_t bytes_left_to_write = len; + size_t bytes_written = 0; + while (bytes_left_to_write > 0) { + size_t free_spaces_left_in_buffer = buffer_.size() - buffer_offset_; + size_t bytes_to_write = std::min(bytes_left_to_write, free_spaces_left_in_buffer); + std::memcpy(reinterpret_cast<uint8_t*>(buffer_.data()) + buffer_offset_, value + bytes_written, bytes_to_write); Review Comment: Please use `std::span` in new code instead of pointer arithmetic and `reinterpret_cast`s -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
