aboutsummaryrefslogtreecommitdiff
path: root/src/stream.cpp
blob: 9dfe5fc6bcdba22deebb378aa852d2e7488f0889 (plain) (blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "salticidae/config.h"
#ifdef SALTICIDAE_CBINDINGS
#include "salticidae/stream.h"

extern "C" {

uint256_t *uint256_new() { return new uint256_t(); }
uint256_t *uint256_new_from_bytes(const uint8_t *arr) {
    return new uint256_t(arr);
}
void uint256_free(const uint256_t *self) { delete self; }

bool uint256_is_null(const uint256_t *self) { return self->is_null(); }
bool uint256_is_eq(const uint256_t *a, const uint256_t *b) {
    return *a == *b;
}

void uint256_serialize(const uint256_t *self, datastream_t *s) {
    self->serialize(*s);
}

void uint256_unserialize(uint256_t *self, datastream_t *s) {
    self->unserialize(*s);
}

datastream_t *datastream_new() { return new datastream_t(); }
datastream_t *datastream_new_from_bytes(const uint8_t *begin, const uint8_t *end) {
    return new datastream_t(begin, end);
}
void datastream_free(const datastream_t *self) { delete self; }

void datastream_assign_by_copy(datastream_t *dst, const datastream_t *src) {
    *dst = *src;
}

void datastream_assign_by_move(datastream_t *dst, datastream_t *_moved_src) {
    *dst = std::move(*_moved_src);
    delete _moved_src;
}

uint8_t *datastream_data(datastream_t *self) { return self->data(); }

void datastream_clear(datastream_t *self) { self->clear(); }

size_t datastream_size(const datastream_t *self) { return self->size(); }

void datastream_put_u8(datastream_t *self, uint8_t val) { *self << val; }
void datastream_put_u16(datastream_t *self, uint16_t val) { *self << val; }
void datastream_put_u32(datastream_t *self, uint32_t val) { *self << val; }
void datastream_put_u64(datastream_t *self, uint64_t val) { *self << val; }

void datastream_put_i8(datastream_t *self, int8_t val) { *self << val; }
void datastream_put_i16(datastream_t *self, int16_t val) { *self << val; }
void datastream_put_i32(datastream_t *self, int32_t val) { *self << val; }
void datastream_put_i64(datastream_t *self, int64_t val) { *self << val; }

void datastream_put_data(datastream_t *self,
                        const uint8_t *begin, const uint8_t *end) {
    self->put_data(begin, end);
}

uint8_t datastream_get_u8(datastream_t *self) { uint8_t val; *self >> val; return val; }
uint16_t datastream_get_u16(datastream_t *self) { uint16_t val; *self >> val; return val; }
uint32_t datastream_get_u32(datastream_t *self) { uint32_t val; *self >> val; return val; }
uint64_t datastream_get_u64(datastream_t *self) { uint64_t val; *self >> val; return val; }

int8_t datastream_get_i8(datastream_t *self) { int8_t val; *self >> val; return val; }
int16_t datastream_get_i16(datastream_t *self) { int16_t val; *self >> val; return val; }
int32_t datastream_get_i32(datastream_t *self) { int32_t val; *self >> val; return val; }
int64_t datastream_get_i64(datastream_t *self) { int64_t val; *self >> val; return val; }

const uint8_t *datastream_get_data_inplace(datastream_t *self, size_t len) {
    return self->get_data_inplace(len);
}

uint256_t *datastream_get_hash(const datastream_t *self) {
    return new uint256_t(self->get_hash());
}

bytearray_t *datastream_to_bytearray(datastream_t *_moved_self) {
    auto res = new bytearray_t(std::move(*_moved_self));
    delete _moved_self;
    return res;
}

}

#endif