lokinet/llarp/util/bencode.h
Thomas Winget 7caa87862e standardize include format and pragma once
All #ifndef guards on headers have been removed, I think,
in favor of #pragma once

Headers are now included as `#include "filename"` if the included file
resides in the same directory as the file including it, or any
subdirectory therein.  Otherwise they are included as
`#include <project/top/dir/relative/path/filename>`

The above does not include system/os headers.
2021-03-09 19:01:41 -05:00

47 lines
1013 B
C++

#pragma once
#include <llarp/constants/proto.hpp>
#include "buffer.hpp"
#include "common.hpp"
#include <functional>
#include <cstdint>
/**
* bencode.h
*
* helper functions for handling bencoding
* https://en.wikipedia.org/wiki/Bencode for more information on the format
* we utilize llarp_buffer which provides memory management
*/
bool
bencode_read_integer(llarp_buffer_t* buffer, uint64_t* result);
bool
bencode_read_string(llarp_buffer_t* buffer, llarp_buffer_t* result);
bool
bencode_write_bytestring(llarp_buffer_t* buff, const void* data, size_t sz);
bool
bencode_write_uint64(llarp_buffer_t* buff, uint64_t i);
/// Write a dictionary entry with a uint64_t value
bool
bencode_write_uint64_entry(llarp_buffer_t* buff, const void* name, size_t sz, uint64_t i);
bool
bencode_start_list(llarp_buffer_t* buff);
bool
bencode_start_dict(llarp_buffer_t* buff);
bool
bencode_end(llarp_buffer_t* buff);
/// read next member, discard it and advance buffer
bool
bencode_discard(llarp_buffer_t* buf);