Skip to content

Commit

Permalink
put zlib namespace into kphp namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
apolyakov committed Dec 26, 2024
1 parent c4fbe48 commit 2d49b6c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions runtime-light/server/http/init-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ task_t<void> finalize_http_server(const string_buffer &output) noexcept {
const bool deflate_encoded{static_cast<bool>(http_server_instance_st.encoding & HttpServerInstanceState::ENCODING_DEFLATE)};
// compress body if needed
if (gzip_encoded || deflate_encoded) {
auto encoded_body{zlib::encode({body.c_str(), static_cast<size_t>(body.size())}, zlib::DEFAULT_COMPRESSION_LEVEL,
gzip_encoded ? zlib::ENCODING_GZIP : zlib::ENCODING_DEFLATE)};
auto encoded_body{kphp::zlib::encode({body.c_str(), static_cast<size_t>(body.size())}, kphp::zlib::DEFAULT_COMPRESSION_LEVEL,
gzip_encoded ? kphp::zlib::ENCODING_GZIP : kphp::zlib::ENCODING_DEFLATE)};
if (encoded_body.has_value()) [[likely]] {
body = std::move(*encoded_body);

Expand Down
4 changes: 4 additions & 0 deletions runtime-light/stdlib/zlib/zlib-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void zlib_static_free([[maybe_unused]] voidpf opaque, [[maybe_unused]] voidpf ad

} // namespace

namespace kphp {

namespace zlib {

std::optional<string> encode(std::span<const char> data, int64_t level, int64_t encoding) noexcept {
Expand Down Expand Up @@ -116,3 +118,5 @@ std::optional<string> decode(std::span<const char> data, int64_t encoding) noexc
}

} // namespace zlib

} // namespace kphp
12 changes: 8 additions & 4 deletions runtime-light/stdlib/zlib/zlib-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "runtime-common/core/runtime-core.h"

namespace kphp {

namespace zlib {

inline constexpr int64_t ENCODING_RAW = -0x0f;
Expand All @@ -27,11 +29,13 @@ std::optional<string> decode(std::span<const char> data, int64_t encoding) noexc

} // namespace zlib

inline string f$gzcompress(const string &data, int64_t level = zlib::MIN_COMPRESSION_LEVEL) noexcept {
level = level == zlib::MIN_COMPRESSION_LEVEL ? zlib::DEFAULT_COMPRESSION_LEVEL : level;
return zlib::encode({data.c_str(), static_cast<size_t>(data.size())}, level, zlib::ENCODING_DEFLATE).value_or(string{});
} // namespace kphp

inline string f$gzcompress(const string &data, int64_t level = kphp::zlib::MIN_COMPRESSION_LEVEL) noexcept {
level = level == kphp::zlib::MIN_COMPRESSION_LEVEL ? kphp::zlib::DEFAULT_COMPRESSION_LEVEL : level;
return kphp::zlib::encode({data.c_str(), static_cast<size_t>(data.size())}, level, kphp::zlib::ENCODING_DEFLATE).value_or(string{});
}

inline string f$gzuncompress(const string &data) noexcept {
return zlib::decode({data.c_str(), static_cast<size_t>(data.size())}, zlib::ENCODING_DEFLATE).value_or(string{});
return kphp::zlib::decode({data.c_str(), static_cast<size_t>(data.size())}, kphp::zlib::ENCODING_DEFLATE).value_or(string{});
}

0 comments on commit 2d49b6c

Please sign in to comment.