diff options
author | Determinant <[email protected]> | 2019-06-03 17:30:01 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-06-03 17:30:01 -0400 |
commit | 9f294eb2e0ae0bed8120fc34fd9782f2f0a9ac74 (patch) | |
tree | d5005c9888874bd2b169fcd51418a3fab36fe631 /src/stream.cpp | |
parent | 9ec5a371f5c05fda8ddeac3470be6fc5c67d44e9 (diff) |
WIP: C bindings
Diffstat (limited to 'src/stream.cpp')
-rw-r--r-- | src/stream.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/stream.cpp b/src/stream.cpp new file mode 100644 index 0000000..8846414 --- /dev/null +++ b/src/stream.cpp @@ -0,0 +1,69 @@ +#include "salticidae/stream.h" + +using namespace salticidae; + +#ifdef __cplusplus + +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); +} + +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(); } +datastream_t *datastream_new_from_bytes(const uint8_t *begin, const uint8_t *end) { + return new DataStream(begin, end); +} + +void datastream_assign_by_copy(datastream_t *dst, const datastream_t *src) { + *dst = *src; +} + +void datastream_assign_by_move(datastream_t *dst, datastream_t *src) { + *dst = std::move(*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_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_data(datastream_t *self, + uint8_t *begin, uint8_t *end) { + self->put_data(begin, end); +} + +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()); +} + +} + +#endif |