/*
 * This RPC client stub was autogenerated by idlc (version 8a02fc5d). DO NOT EDIT!
 * Generated from Filesystem.idl for interface Filesystem at 2021-06-26T17:21:48-0500
 *
 * You may use these generated stubs directly as the RPC interface, or you can subclass it to
 * override the behavior of the function calls, or to perform some preprocessing to the data as
 * needed before sending it.
 *
 * See the full RPC documentation for more details.
 */
#ifndef RPC_CLIENT_GENERATED_18393244566832765147
#define RPC_CLIENT_GENERATED_18393244566832765147

#include <string>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <span>
#include <string_view>
#include <vector>

namespace rpc {
namespace rt { class ClientRpcIoStream; }
class FilesystemClient {
    struct MessageHeader {
        enum Flags: uint32_t {
            Request                     = (1 << 0),
            Response                    = (1 << 1),
        };

        uint64_t type;
        Flags flags;
        uint32_t tag;

        std::byte payload[];
    };
    static_assert(!(offsetof(MessageHeader, payload) % sizeof(uintptr_t)),
        "message header's payload is not word aligned");

    constexpr static const std::string_view kServiceName{"Filesystem"};

    protected:
        using IoStream = rt::ClientRpcIoStream;

    public:
        // Return types for method 'OpenFile'
        struct OpenFileReturn {
            int32_t status;
            uint64_t handle;
            uint64_t fileSize;
        };
        // Return types for method 'SlowRead'
        struct SlowReadReturn {
            int32_t status;
            std::vector<std::byte> data;
        };

    public:
        FilesystemClient(const std::shared_ptr<IoStream> &stream);
        virtual ~FilesystemClient();

        virtual OpenFileReturn OpenFile(const std::string &path, uint32_t mode);
        virtual SlowReadReturn SlowRead(uint64_t handle, uint64_t offset, uint16_t numBytes);
        virtual int32_t CloseFile(uint64_t handle);

    // Helpers provided to subclasses for implementation of interface methods
    protected:
        constexpr inline auto &getIo() {
            return this->io;
        }

        /// Handles errors occurring during client operations; typically terminates the task
        virtual void _HandleError(const bool fatal, const std::string_view &what);

    // Implementation details; pretend this does not exist
    private:
        std::shared_ptr<IoStream> io;
        size_t txBufSize{0};
        void *txBuf{nullptr};

        uint32_t nextTag{0};

        void _ensureTxBuf(const size_t);
        uint32_t _sendRequest(const uint64_t type, const size_t payloadBytes);
}; // class FilesystemClient
} // namespace rpc
#endif // defined(RPC_CLIENT_GENERATED_18393244566832765147)
