Files
blobchain/inc/blobchain/blob.h
T
2026-04-30 21:28:09 -04:00

81 lines
1.4 KiB
C

/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause
*/
#ifndef BLOBCHAIN_BLOB_H
#define BLOBCHAIN_BLOB_H 1
#include <stdint.h>
#include <stddef.h>
#include "blobchain/stream.h"
#include "blobchain/common.h"
/*
* Represents a single blob of data
*
* @data: Buffer containing blob data
* @length: Length of blob
* @hash: Hash of file contents
* @next: Next blob
*/
struct blob {
void *data;
size_t length;
uint8_t hash[SHA256_N_BYTES];
struct blob *next;
};
/*
* Represents a list of data blobs
*
* @head: List head
* @tail: List tail
* @count: Number of blobs present
*/
struct blob_list {
struct blob *head;
struct blob *tail;
size_t count;
};
/*
* Allocate memory for a new blob descriptor
*
* @stmp: Stream pointer to copy data from [NULLable]
*/
struct blob *blob_allocate(struct data_stream *stmp);
/*
* Add a blob to a list
*
* @lp: Blob list pointer
* @blob: Blob to add
*
* Returns zero on success
*/
int blob_list_append(struct blob_list *lp, struct blob *blob);
/*
* Initialize a list of blobs
*
* @lp: Bloblist pointer
*/
int blob_list_init(struct blob_list *lp);
/*
* Destroy a blob list
*
* @lp: Bloblist to destroy
*/
void blob_list_destroy(struct blob_list *lp);
/*
* Dump a blob list for debugging purposes
*
* @lp: Blob list to dump
*/
void blob_list_dump(struct blob_list *lp);
#endif /* !BLOBCHAIN_BLOB_H */