aboutsummaryrefslogtreecommitdiff
path: root/zenhttp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-09-29 09:25:29 +0200
committerGitHub <[email protected]>2022-09-29 00:25:29 -0700
commitf87631dd0d283ad04eb3873c1a7510a9d1423792 (patch)
treefb6da8ce9b1e55beff73c82d8943dc0303c7ae05 /zenhttp
parentDe/more upstream details (#168) (diff)
downloadzen-f87631dd0d283ad04eb3873c1a7510a9d1423792.tar.xz
zen-f87631dd0d283ad04eb3873c1a7510a9d1423792.zip
Format all rpc package responses using `FormatPackageMessageBuffer` to avoid memory copy (#174)
When reading upstream, fall back to old rpc response to handle older instances.
Diffstat (limited to 'zenhttp')
-rw-r--r--zenhttp/httpshared.cpp11
-rw-r--r--zenhttp/include/zenhttp/httpshared.h2
2 files changed, 13 insertions, 0 deletions
diff --git a/zenhttp/httpshared.cpp b/zenhttp/httpshared.cpp
index 769b5e3f3..2b96f32fc 100644
--- a/zenhttp/httpshared.cpp
+++ b/zenhttp/httpshared.cpp
@@ -339,6 +339,17 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint
return Package;
}
+bool
+ParsePackageMessageWithLegacyFallback(const IoBuffer& Response, CbPackage& OutPackage)
+{
+ if (IsPackageMessage(Response))
+ {
+ OutPackage = ParsePackageMessage(Response);
+ return true;
+ }
+ return OutPackage.TryLoad(Response);
+}
+
CbPackageReader::CbPackageReader() : m_CreateBuffer([](const IoHash&, uint64_t Size) -> IoBuffer { return IoBuffer{Size}; })
{
}
diff --git a/zenhttp/include/zenhttp/httpshared.h b/zenhttp/include/zenhttp/httpshared.h
index 24ce0c85a..0265d8d1e 100644
--- a/zenhttp/include/zenhttp/httpshared.h
+++ b/zenhttp/include/zenhttp/httpshared.h
@@ -93,6 +93,8 @@ CbPackage ParsePackageMessage(
});
bool IsPackageMessage(IoBuffer Payload);
+bool ParsePackageMessageWithLegacyFallback(const IoBuffer& Response, CbPackage& OutPackage);
+
std::vector<IoBuffer> FormatPackageMessage(const CbPackage& Data);
CompositeBuffer FormatPackageMessageBuffer(const CbPackage& Data);