diff options
| author | Stefan Boberg <[email protected]> | 2021-09-28 21:58:40 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-28 21:58:40 +0200 |
| commit | 1caecce8474bd55986d4233614336eb627135504 (patch) | |
| tree | de7b0bc8799295d1257a29ff5a49148e0bae321d /zenhttp/include | |
| parent | Removed MemoryOutStream, MemoryInStream (diff) | |
| download | zen-1caecce8474bd55986d4233614336eb627135504.tar.xz zen-1caecce8474bd55986d4233614336eb627135504.zip | |
Added preliminary CbPackageReader, for handling incremental compact binary package streaming
Diffstat (limited to 'zenhttp/include')
| -rw-r--r-- | zenhttp/include/zenhttp/httpshared.h | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/zenhttp/include/zenhttp/httpshared.h b/zenhttp/include/zenhttp/httpshared.h index 92c1ef9c6..2e728577d 100644 --- a/zenhttp/include/zenhttp/httpshared.h +++ b/zenhttp/include/zenhttp/httpshared.h @@ -13,10 +13,23 @@ class IoBuffer; class CbPackage; class CompositeBuffer; +/** _____ _ _____ _ + / ____| | | __ \ | | + | | | |__ | |__) |_ _ ___| | ____ _ __ _ ___ + | | | '_ \| ___/ _` |/ __| |/ / _` |/ _` |/ _ \ + | |____| |_) | | | (_| | (__| < (_| | (_| | __/ + \_____|_.__/|_| \__,_|\___|_|\_\__,_|\__, |\___| + __/ | + |___/ + + Structures and code related to handling CbPackage transactions + + */ + struct CbPackageHeader { uint32_t HeaderMagic; - uint32_t AttachmentCount; + uint32_t AttachmentCount; // TODO: should add ability to opt out of implicit root document? uint32_t Reserved1; uint32_t Reserved2; }; @@ -27,7 +40,7 @@ static constinit uint32_t kCbPkgMagic = 0xaa77aacc; struct CbAttachmentEntry { - uint64_t AttachmentSize; + uint64_t PayloadSize; uint32_t Flags; IoHash AttachmentHash; @@ -35,6 +48,7 @@ struct CbAttachmentEntry { kIsCompressed = (1u << 0), // Is marshaled using compressed buffer storage format kIsObject = (1u << 1), // Is compact binary object + kIsError = (1u << 2), // Is error (compact binary formatted) object }; }; @@ -48,4 +62,41 @@ CbPackage ParsePackageMessage( return IoBuffer{Size}; }); +/** Streaming reader for compact binary packages + + The goal is to ultimately support zero-copy I/O, but for now there'll be some + copying involved on some platforms at least. + + */ +class CbPackageReader +{ +public: + CbPackageReader(); + ~CbPackageReader(); + + void SetPayloadBufferCreator(std::function<IoBuffer(const IoHash& Cid, uint64_t Size)> CreateBuffer); + + /** Process header data + */ + uint64_t ProcessHeaderData(const void* Data, uint64_t DataBytes); + + std::span<IoBuffer> GetPayloadBuffers() { return m_PayloadBuffers; } + +private: + enum class State + { + kInitialState, + kReadingHeader, + kReadingAttachmentEntries, + kReadingBuffers + } m_CurrentState = State::kInitialState; + + std::function<IoBuffer(const IoHash& Cid, uint64_t Size)> m_CreateBuffer; + std::vector<IoBuffer> m_PayloadBuffers; + std::vector<CbAttachmentEntry> m_AttachmentEntries; + CbPackageHeader m_PackageHeader; +}; + +void forcelink_httpshared(); + } // namespace zen |