1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/util/bencode.h
Stephen Shelton 273270916e
The Great Wall of Blame
This commit reflects changes to clang-format rules. Unfortunately,
these rule changes create a massive change to the codebase, which
causes an apparent rewrite of git history.

Git blame's --ignore-rev flag can be used to ignore this commit when
attempting to `git blame` some code.
2020-04-07 12:38:56 -06:00

49 lines
1 KiB
C++

#ifndef LLARP_BENCODE_H
#define LLARP_BENCODE_H
#include <constants/proto.hpp>
#include <util/buffer.hpp>
#include <util/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);
#endif