aboutsummaryrefslogtreecommitdiff
path: root/include/ms.h
blob: 35ff76273d1d006cc33b73fd4143ac0a09c12942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// ms.h --- Memory Span                                                -*- C -*-
//
// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
//
// SPDX-License-Identifier: MIT
//
// This file is part of COSMOS Codebase.
//
// Commentary:
//
// Code:

#ifndef INCLUDED_COSMOS_MS_H
#define INCLUDED_COSMOS_MS_H

#include "mv.h"

struct ms {
  u8 *beg;
  u8 *end;
};

#define MS_NULL ((struct ms) {0})
#define MS( v) ((struct ms) {{ &(v), ((void *) &(v)) + sizeof (v)     }})
#define MS0(v) ((struct ms) {{ &(v), ((void *) &(v)) + sizeof (v) - 1 }})

struct ms ms_from (void *beg, void *end);
struct ms ms_from_mb (struct mb);

/*         */        usz ms_sz (struct ms);
static inline struct mv  ms_mv (struct ms ms) { return mv_from (ms.beg, ms.end); }

static inline int ms_is_null (struct ms ms) { return mv_is_null (ms_mv (ms)); }

// TODO(cmmm): rethink api
void  ms_push_left_u8 (struct ms *, u8 val);
void *ms_push_left_mv (struct ms *, struct mv);
void *ms_push_left    (struct ms *, const void *buf, usz sz);

#endif // INCLUDED_COSMOS_MS_H

// ms.h ends here