1 #ifndef _MADARA_KNOWLEDGE_FILESTREAMER_H_
2 #define _MADARA_KNOWLEDGE_FILESTREAMER_H_
40 init(key, filename, kb);
73 inline size_t load(
size_t index,
size_t frag_size = 60000)
75 size_t bytes_read = 0;
80 stream_.seekg((std::streampos)index * frag_size, std::ios::beg);
83 std::vector<unsigned char>
frag(frag_size);
87 frag.resize(bytes_read);
Splits files into fragments that can be saved to and loaded from a knowledge base.
containers::Map file_fragments
the crc of the file
containers::FlexMap file_space
records that contain the file fragments
FileStreamer(const std::string &key, const std::string &filename, KnowledgeBase kb)
Constructor.
std::ifstream stream_
the stream to read from
void init(const std::string &key, const std::string &filename, KnowledgeBase kb)
Initializes the file stream and all containers.
std::string filename_
the name of the file
uint32_t get_crc(void)
Returns the crc of the file.
size_t load(size_t index, size_t frag_size=60000)
Loads a fragment into the knowledge base.
containers::Integer file_crc
the crc of the file
void modify(void)
Remodifies the file size and crc.
containers::Integer file_size
the size of the file contents
FileStreamer()
Constructor.
std::string get_filename(void)
Returns the name of the file.
void clear_fragments(void)
Clears the fragment list.
size_t get_size(void)
Returns the size of the file.
This class provides a distributed knowledge base to users.
This class encapsulates an entry in a KnowledgeBase.
void emplace_file(Args &&... args)
Construct a file (vector of unsigned char) within this KnowledgeRecord.
This class stores a flexible map of strings and ints to KaRL variables FlexMap differs from Map in th...
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
void to_container(BufferVector &target) const
Fills a BufferVector container with all subkeys.
This class stores an integer within a variable context.
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the value as an integer (same as *)
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
void modify(void)
Mark the value as modified.
This class stores a map of strings to KaRL variables.
int set(const std::string &key, madara::knowledge::KnowledgeRecord::Integer value=madara::knowledge::KnowledgeRecord::MODIFIED)
Sets a location within the map to the specified value.
void clear(bool clear_knowledge=true)
Clears the map.
Provides functions and classes for the distributed knowledge base.
MADARA_EXPORT void frag(const char *source, uint64_t total_size, const char *originator, const char *domain, uint64_t clock, uint64_t timestamp, uint32_t quality, unsigned char ttl, uint64_t fragment_size, FragmentMap &map)
Breaks a large packet into smaller packets.
unsigned int file_size(const std::string &filename)
Returns the size of a file.
uint32_t file_crc(const std::string &filename, size_t max_block=1000000)
Returns the crc of a file.
Copyright(c) 2020 Galois.