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.
62 lines
1.4 KiB
C
62 lines
1.4 KiB
C
7 years ago
|
#ifndef LLARP_BENCODE_H
|
||
|
#define LLARP_BENCODE_H
|
||
|
#include <stdbool.h>
|
||
|
#include <stdint.h>
|
||
|
#include <llarp/buffer.h>
|
||
|
#include <llarp/version.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_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
|