aboutsummaryrefslogtreecommitdiff
path: root/zenhttp/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-16 15:41:11 +0200
committerStefan Boberg <[email protected]>2021-09-16 15:41:11 +0200
commit7f138c4cfc6d6d6fc3e9b29f5cbb750d2462ca96 (patch)
tree2fb68b9fd21cc27523f9347bdbbab2ccd9918ae8 /zenhttp/include
parentPass on ZEN_NOT_IMPLEMENTED arguments into the resulting ZEN_ASSERT macro (diff)
downloadzen-7f138c4cfc6d6d6fc3e9b29f5cbb750d2462ca96.tar.xz
zen-7f138c4cfc6d6d6fc3e9b29f5cbb750d2462ca96.zip
Improved package serialization to allow round tripping
Diffstat (limited to 'zenhttp/include')
-rw-r--r--zenhttp/include/zenhttp/httpshared.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/zenhttp/include/zenhttp/httpshared.h b/zenhttp/include/zenhttp/httpshared.h
new file mode 100644
index 000000000..06dc4a872
--- /dev/null
+++ b/zenhttp/include/zenhttp/httpshared.h
@@ -0,0 +1,51 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <zencore/iobuffer.h>
+#include <zencore/iohash.h>
+
+#include <functional>
+
+namespace zen {
+
+class IoBuffer;
+class CbPackage;
+class CompositeBuffer;
+
+struct CbPackageHeader
+{
+ uint32_t HeaderMagic;
+ uint32_t AttachmentCount;
+ uint32_t Reserved1;
+ uint32_t Reserved2;
+};
+
+static_assert(sizeof(CbPackageHeader) == 16);
+
+static constinit uint32_t kCbPkgMagic = 0xaa77aacc;
+
+struct CbAttachmentEntry
+{
+ uint64_t AttachmentSize;
+ uint32_t Flags;
+ IoHash AttachmentHash;
+
+ enum
+ {
+ kIsCompressed = (1u << 0), // Is marshaled using compressed buffer storage format
+ kIsObject = (1u << 1), // Is compact binary object
+ };
+};
+
+static_assert(sizeof(CbAttachmentEntry) == 32);
+
+std::vector<IoBuffer> FormatPackageMessage(const CbPackage& Data);
+CompositeBuffer FormatPackageMessageBuffer(const CbPackage& Data);
+CbPackage ParsePackageMessage(
+ IoBuffer Payload,
+ std::function<IoBuffer(const IoHash& Cid, uint64_t Size)> CreateBuffer = [](const IoHash&, uint64_t Size) -> IoBuffer {
+ return IoBuffer{Size};
+ });
+
+} // namespace zen