mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
C
68 lines
1.5 KiB
C
#ifndef LLARP_BENCODE_H
|
|
#define LLARP_BENCODE_H
|
|
#include <llarp/common.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <llarp/buffer.h>
|
|
#include <llarp/proto.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
bool INLINE bencode_write_bytestring(llarp_buffer_t * buff, const void * data, size_t sz)
|
|
{
|
|
if(!llarp_buffer_writef(buff, "%ld:", sz)) return false;
|
|
return llarp_buffer_write(buff, data, sz);
|
|
}
|
|
|
|
bool INLINE bencode_write_int(llarp_buffer_t * buff, int i)
|
|
{
|
|
return llarp_buffer_writef(buff, "i%de", i);
|
|
}
|
|
|
|
bool INLINE bencode_write_uint16(llarp_buffer_t * buff, uint16_t i)
|
|
{
|
|
return llarp_buffer_writef(buff, "i%de", i);
|
|
}
|
|
|
|
bool INLINE bencode_write_int64(llarp_buffer_t * buff, int64_t i)
|
|
{
|
|
return llarp_buffer_writef(buff, "i%lde", i);
|
|
}
|
|
|
|
bool INLINE bencode_write_uint64(llarp_buffer_t * buff, uint64_t i)
|
|
{
|
|
return llarp_buffer_writef(buff, "i%lde", i);
|
|
}
|
|
|
|
bool INLINE bencode_write_sizeint(llarp_buffer_t * buff, size_t i)
|
|
{
|
|
return llarp_buffer_writef(buff, "i%lde", i);
|
|
}
|
|
|
|
bool INLINE bencode_start_list(llarp_buffer_t * buff)
|
|
{
|
|
return llarp_buffer_write(buff, "l", 1);
|
|
}
|
|
|
|
bool INLINE bencode_start_dict(llarp_buffer_t * buff)
|
|
{
|
|
return llarp_buffer_write(buff, "d", 1);
|
|
}
|
|
|
|
bool INLINE bencode_end(llarp_buffer_t * buff)
|
|
{
|
|
return llarp_buffer_write(buff, "e", 1);
|
|
}
|
|
|
|
bool INLINE bencode_write_version_entry(llarp_buffer_t * buff)
|
|
{
|
|
return llarp_buffer_writef(buff, "1:vi%de", LLARP_PROTO_VERSION);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|