c-ipfs/include/ipfs/unixfs/unixfs.h

96 lines
2.2 KiB
C
Raw Normal View History

2016-12-19 19:19:43 +00:00
/***
* A unix-like file system over IPFS blocks
*/
#pragma once
/**
* The protobuf info:
* message Data {
* enum DataType {
* Raw = 0;
* Directory = 1;
* File = 2;
* Metadata = 3;
* Symlink = 4;
* }
*
* required DataType Type = 1;
* optional bytes Data = 2;
* optional uint64 filesize = 3;
* repeated uint64 blocksizes = 4;
* }
*
* message Metadata {
* optional string MimeType = 1;
* }
*/
enum UnixFSDataType {
UNIXFS_RAW,
UNIXFS_DIRECTORY,
UNIXFS_FILE,
UNIXFS_METADATA,
UNIXFS_SYMLINK
};
struct UnixFSBlockSizeNode {
size_t block_size;
struct UnixFSBlockSizeNode* next;
};
struct UnixFS {
enum UnixFSDataType data_type;
size_t bytes_size; // the size of the bytes array
2016-12-19 22:21:21 +00:00
unsigned char* bytes; // an array of bytes
2016-12-19 19:19:43 +00:00
size_t file_size; // the file size
struct UnixFSBlockSizeNode* block_size_head; // a linked list of block sizes
};
struct UnixFSMetaData {
char* mime_type;
};
/**
* Allocate memory for a new UnixFS struct
* @param obj the pointer to the new object
* @returns true(1) on success
*/
int ipfs_unixfs_new(struct UnixFS** obj);
/***
* Free the resources used by a UnixFS struct
* @param obj the struct to free
* @returns true(1)
*/
int ipfs_unixfs_free(struct UnixFS* obj);
/**
* Protobuf functions
*/
/**
* Calculate the max size of the protobuf before encoding
* @param obj what will be encoded
* @returns the size of the buffer necessary to encode the object
*/
size_t ipfs_unixfs_protobuf_encode_size(struct UnixFS* obj);
/***
* Encode a UnixFS object into protobuf format
* @param incoming the incoming object
* @param outgoing where the bytes will be placed
* @param max_buffer_size the size of the outgoing buffer
* @param bytes_written how many bytes were written in the buffer
* @returns true(1) on success
*/
2016-12-19 22:21:21 +00:00
int ipfs_unixfs_protobuf_encode(const struct UnixFS* incoming, unsigned char* outgoing, size_t max_buffer_size, size_t* bytes_written);
2016-12-19 19:19:43 +00:00
/***
* Decodes a protobuf array of bytes into a UnixFS object
* @param incoming the array of bytes
* @param incoming_size the length of the array
* @param outgoing the UnixFS object
*/
int ipfs_unixfs_protobuf_decode(unsigned char* incoming, size_t incoming_size, struct UnixFS** outgoing);