2016-11-17 20:07:59 +00:00
|
|
|
/***
|
|
|
|
* IPFS has the notion of storage blocks.
|
2016-12-14 17:07:43 +00:00
|
|
|
* Raw data with a multihash key (the Cid)
|
2016-11-17 20:07:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IPFS_BLOCKS_BLOCK_H__
|
|
|
|
#define __IPFS_BLOCKS_BLOCK_H__
|
|
|
|
|
2016-11-30 16:46:41 +00:00
|
|
|
#include "ipfs/cid/cid.h"
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
struct Block {
|
|
|
|
struct Cid* cid;
|
|
|
|
unsigned char* data;
|
2016-11-30 16:46:41 +00:00
|
|
|
size_t data_length;
|
2016-11-17 20:07:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/***
|
2017-07-20 20:03:49 +00:00
|
|
|
* Create a new block
|
|
|
|
* @returns a new allocated Block struct
|
2016-11-17 20:07:59 +00:00
|
|
|
*/
|
2017-07-27 17:05:41 +00:00
|
|
|
struct Block* ipfs_block_new();
|
2016-12-14 17:07:43 +00:00
|
|
|
|
|
|
|
int ipfs_blocks_block_add_data(const unsigned char* data, size_t data_size, struct Block* block);
|
2016-11-17 20:07:59 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Free resources used by the creation of a block
|
|
|
|
* @param block the block to free
|
|
|
|
* @returns true(1) on success
|
|
|
|
*/
|
2017-07-24 22:58:39 +00:00
|
|
|
int ipfs_block_free(struct Block* block);
|
2016-11-17 20:07:59 +00:00
|
|
|
|
2016-12-14 17:07:43 +00:00
|
|
|
/**
|
|
|
|
* Determine the approximate size of an encoded block
|
|
|
|
* @param block the block to measure
|
|
|
|
* @returns the approximate size needed to encode the protobuf
|
|
|
|
*/
|
|
|
|
size_t ipfs_blocks_block_protobuf_encode_size(const struct Block* block);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encode the Block into protobuf format
|
|
|
|
* @param block the block to encode
|
|
|
|
* @param buffer the buffer to fill
|
|
|
|
* @param max_buffer_size the max size of the buffer
|
|
|
|
* @param bytes_written the number of bytes used
|
|
|
|
* @returns true(1) on success
|
|
|
|
*/
|
|
|
|
int ipfs_blocks_block_protobuf_encode(const struct Block* block, unsigned char* buffer, size_t max_buffer_size, size_t* bytes_written);
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Decode from a protobuf stream into a Block struct
|
|
|
|
* @param buffer the buffer to pull from
|
|
|
|
* @param buffer_length the length of the buffer
|
|
|
|
* @param block the block to fill
|
|
|
|
* @returns true(1) on success
|
|
|
|
*/
|
|
|
|
int ipfs_blocks_block_protobuf_decode(const unsigned char* buffer, const size_t buffer_length, struct Block** block);
|
|
|
|
|
2017-07-24 22:58:39 +00:00
|
|
|
/***
|
|
|
|
* Make a copy of a block
|
|
|
|
* @param original the original
|
|
|
|
* @returns a new Block that is a copy
|
|
|
|
*/
|
|
|
|
struct Block* ipfs_block_copy(struct Block* original);
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
#endif
|