mirror of
https://gitlab.com/niansa/llama_any.git
synced 2025-03-06 20:48:27 +01:00
35 lines
872 B
C++
35 lines
872 B
C++
#ifndef _RECEIVER_HPP
|
|
#define _RECEIVER_HPP
|
|
#include "Runtime.hpp"
|
|
#include "AsyncManager.hpp"
|
|
|
|
#include <string>
|
|
#include <cstddef>
|
|
#include "basic-coro/AwaitableTask.hpp"
|
|
|
|
|
|
namespace Receiver {
|
|
class Simple {
|
|
Runtime& runtime;
|
|
AsyncManager &aMan;
|
|
|
|
protected:
|
|
int fd;
|
|
|
|
public:
|
|
Simple(AsyncManager& asyncManager, int fd) : runtime(asyncManager.getRuntime()), aMan(asyncManager), fd(fd) {}
|
|
|
|
// Reads the exact amount of bytes given
|
|
basiccoro::AwaitableTask<std::string> read(size_t amount);
|
|
basiccoro::AwaitableTask<Result> read(std::byte *buffer, size_t size);
|
|
// Reads at max. the amount of bytes given
|
|
basiccoro::AwaitableTask<std::string> readSome(size_t max);
|
|
|
|
// Reads an object of type T
|
|
template<typename T>
|
|
auto readObject(T& o) {
|
|
return read(reinterpret_cast<std::byte *>(&o), sizeof(o));
|
|
}
|
|
};
|
|
}
|
|
#endif
|