Commit d5b18dc7 authored by npzacs's avatar npzacs

mkb: added initialization from memory and access to raw data

parent fed9d7b6
......@@ -88,12 +88,44 @@ MKB *mkb_open(const char *path)
return NULL;
}
MKB *mkb_init(uint8_t *data, int len)
{
MKB *mkb = malloc(sizeof(MKB));
mkb->size = len;
mkb->buf = data;
return mkb;
}
void mkb_close(MKB *mkb)
{
X_FREE(mkb->buf);
X_FREE(mkb);
if (mkb) {
X_FREE(mkb->buf);
X_FREE(mkb);
}
}
const uint8_t *mkb_data(MKB *mkb)
{
return mkb->buf;
}
size_t mkb_data_size(MKB *mkb)
{
size_t pos = 0;
while (pos + 4 <= mkb->size) {
if (!mkb->buf[pos]) {
break;
}
pos += MKINT_BE24(mkb->buf + pos + 1);
}
return pos;
}
uint8_t mkb_type(MKB *mkb)
{
const uint8_t *rec = _record(mkb, 0x10, NULL);
......
......@@ -28,8 +28,12 @@
typedef struct mkb MKB;
AACS_PRIVATE MKB *mkb_open(const char *path); // init MKB
AACS_PRIVATE MKB *mkb_init(uint8_t *data, int len); // init MKB from data
AACS_PRIVATE void mkb_close(MKB *mkb); // free MKB
AACS_PRIVATE const uint8_t *mkb_data(MKB *mkb);
AACS_PRIVATE size_t mkb_data_size(MKB *mkb);
// returns type
AACS_PRIVATE uint8_t mkb_type(MKB *mkb);
// returns version
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment