core: Add blob + data stream abstraction

A blob is a piece of data of variable length that belongs in a blob list
while a data stream is a buffer used to move data between blobs among
other things.

Signed-off-by: Chloe M. <chloe@mirocom.org>
This commit is contained in:
2026-04-30 09:50:12 -04:00
parent 433ab624ad
commit 0f31d51743
4 changed files with 158 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
/*
* 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"
/*
* Represents a single blob of data
*
* @data: Buffer containing blob data
* @length: Length of blob
* @next: Next blob
*/
struct blob {
void *data;
size_t length;
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);
#endif /* !BLOBCHAIN_BLOB_H */
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause
*/
#ifndef BLOBCHAIN_STREAM_H
#define BLOBCHAIN_STREAM_H 1
#include <stddef.h>
/*
* Represents a data stream
*
* @data: Data buffer
* @length: Number of bytes in data buffer
*/
struct data_stream {
void *data;
size_t length;
};
#endif /* !BLOBCHAIN_STREAM_H */