2019-12-09 12:57:37 +01:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-12-09 12:57:37 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
2020-03-08 09:06:23 +01:00
|
|
|
#include <stratosphere/kvdb/kvdb_auto_buffer.hpp>
|
2019-12-09 12:57:37 +01:00
|
|
|
|
|
|
|
namespace ams::kvdb {
|
|
|
|
|
|
|
|
/* Functionality for parsing/generating a key value archive. */
|
|
|
|
class ArchiveReader {
|
|
|
|
private:
|
2021-10-10 09:14:06 +02:00
|
|
|
AutoBuffer &m_buffer;
|
|
|
|
size_t m_offset;
|
2019-12-09 12:57:37 +01:00
|
|
|
public:
|
2021-10-10 09:14:06 +02:00
|
|
|
ArchiveReader(AutoBuffer &b) : m_buffer(b), m_offset(0) { /* ... */ }
|
2019-12-09 12:57:37 +01:00
|
|
|
private:
|
|
|
|
Result Peek(void *dst, size_t size);
|
|
|
|
Result Read(void *dst, size_t size);
|
|
|
|
public:
|
|
|
|
Result ReadEntryCount(size_t *out);
|
|
|
|
Result GetEntrySize(size_t *out_key_size, size_t *out_value_size);
|
|
|
|
Result ReadEntry(void *out_key, size_t key_size, void *out_value, size_t value_size);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ArchiveWriter {
|
|
|
|
private:
|
2021-10-10 09:14:06 +02:00
|
|
|
AutoBuffer &m_buffer;
|
|
|
|
size_t m_offset;
|
2019-12-09 12:57:37 +01:00
|
|
|
public:
|
2021-10-10 09:14:06 +02:00
|
|
|
ArchiveWriter(AutoBuffer &b) : m_buffer(b), m_offset(0) { /* ... */ }
|
2019-12-09 12:57:37 +01:00
|
|
|
private:
|
|
|
|
Result Write(const void *src, size_t size);
|
|
|
|
public:
|
|
|
|
void WriteHeader(size_t entry_count);
|
|
|
|
void WriteEntry(const void *key, size_t key_size, const void *value, size_t value_size);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ArchiveSizeHelper {
|
|
|
|
private:
|
2021-10-10 09:14:06 +02:00
|
|
|
size_t m_size;
|
2019-12-09 12:57:37 +01:00
|
|
|
public:
|
|
|
|
ArchiveSizeHelper();
|
|
|
|
|
|
|
|
void AddEntry(size_t key_size, size_t value_size);
|
|
|
|
|
|
|
|
size_t GetSize() const {
|
2021-10-10 09:14:06 +02:00
|
|
|
return m_size;
|
2019-12-09 12:57:37 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|