Skip to content

Commit 8e30a72

Browse files
refactor: optimize CAPI
1 parent 6139379 commit 8e30a72

File tree

6 files changed

+403
-443
lines changed

6 files changed

+403
-443
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
name: Build on Linux X86_64 (GCC)
9696
runs-on: ubuntu-24.04
9797
container:
98-
image: ubuntu:20.04
98+
image: ubuntu:22.04
9999
options: --privileged
100100
steps:
101101
- name: Checkout repository
@@ -147,13 +147,13 @@ jobs:
147147
name: Build on Linux ARM64 (GCC)
148148
runs-on: ubuntu-24.04
149149
container:
150-
image: ubuntu:20.04
150+
image: ubuntu:22.04
151151
options: --privileged
152152
steps:
153153
- name: Checkout repository
154154
uses: actions/checkout@v4
155155

156-
- name: Setup GCC 15
156+
- name: Setup GCC 13
157157
run: |
158158
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
159159
echo "Etc/UTC" > /etc/timezone
@@ -165,32 +165,30 @@ jobs:
165165
apt-get install -y --no-install-recommends gcc-13 g++-13
166166
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100
167167
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100
168-
dpkg --add-architecture arm64
169168
apt-get update -y
170169
apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
171-
apt-get install -y libc6:arm64 libgcc-s1:arm64 libstdc++6:arm64
172170
173171
- name: Install xmake
174172
uses: xmake-io/github-action-setup-xmake@v1
175173

176174
- name: Build BinaryStream Static (Debug)
177175
run: |
178-
xmake f --mode=debug --kind=static --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cxflags="-target aarch64-linux-gnu" --shflags="-target aarch64-linux-gnu -fuse-ld=lld" --root
176+
xmake f --mode=debug --kind=static --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ --ld=aarch64-linux-gnu-g++ --sh=aarch64-linux-gnu-g++ --root
179177
xmake --all --root
180178
181179
- name: Build BinaryStream Shared (Debug)
182180
run: |
183-
xmake f --mode=debug --kind=shared --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cxflags="-target aarch64-linux-gnu" --shflags="-target aarch64-linux-gnu -fuse-ld=lld" --root
181+
xmake f --mode=debug --kind=shared --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ --ld=aarch64-linux-gnu-g++ --sh=aarch64-linux-gnu-g++ --root
184182
xmake --all --root
185183
186184
- name: Build BinaryStream Static (Release)
187185
run: |
188-
xmake f --mode=release --kind=static --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cxflags="-target aarch64-linux-gnu" --shflags="-target aarch64-linux-gnu -fuse-ld=lld" --root
186+
xmake f --mode=release --kind=static --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ --ld=aarch64-linux-gnu-g++ --sh=aarch64-linux-gnu-g++ --root
189187
xmake --all --root
190188
191189
- name: Build BinaryStream Shared (Release)
192190
run: |
193-
xmake f --mode=release --kind=shared --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cxflags="-target aarch64-linux-gnu" --shflags="-target aarch64-linux-gnu -fuse-ld=lld" --root
191+
xmake f --mode=release --kind=shared --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ --ld=aarch64-linux-gnu-g++ --sh=aarch64-linux-gnu-g++ --root
194192
xmake --all --root
195193
196194
- name: Upload Artifact

.github/workflows/release.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
name: Build on Linux X86_64 (GCC)
7171
runs-on: ubuntu-24.04
7272
container:
73-
image: ubuntu:20.04
73+
image: ubuntu:22.04
7474
options: --privileged
7575
steps:
7676
- name: Checkout repository
@@ -122,13 +122,13 @@ jobs:
122122
name: Build on Linux ARM64 (GCC)
123123
runs-on: ubuntu-24.04
124124
container:
125-
image: ubuntu:20.04
125+
image: ubuntu:22.04
126126
options: --privileged
127127
steps:
128128
- name: Checkout repository
129129
uses: actions/checkout@v4
130130

131-
- name: Setup GCC 15
131+
- name: Setup GCC 13
132132
run: |
133133
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
134134
echo "Etc/UTC" > /etc/timezone
@@ -140,32 +140,30 @@ jobs:
140140
apt-get install -y --no-install-recommends gcc-13 g++-13
141141
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100
142142
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100
143-
dpkg --add-architecture arm64
144143
apt-get update -y
145144
apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
146-
apt-get install -y libc6:arm64 libgcc-s1:arm64 libstdc++6:arm64
147145
148146
- name: Install xmake
149147
uses: xmake-io/github-action-setup-xmake@v1
150148

151149
- name: Build BinaryStream Static (Debug)
152150
run: |
153-
xmake f --mode=debug --kind=static --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cxflags="-target aarch64-linux-gnu" --shflags="-target aarch64-linux-gnu -fuse-ld=lld" --root
151+
xmake f --mode=debug --kind=static --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ --ld=aarch64-linux-gnu-g++ --sh=aarch64-linux-gnu-g++ --root
154152
xmake --all --root
155153
156154
- name: Build BinaryStream Shared (Debug)
157155
run: |
158-
xmake f --mode=debug --kind=shared --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cxflags="-target aarch64-linux-gnu" --shflags="-target aarch64-linux-gnu -fuse-ld=lld" --root
156+
xmake f --mode=debug --kind=shared --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ --ld=aarch64-linux-gnu-g++ --sh=aarch64-linux-gnu-g++ --root
159157
xmake --all --root
160158
161159
- name: Build BinaryStream Static (Release)
162160
run: |
163-
xmake f --mode=release --kind=static --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cxflags="-target aarch64-linux-gnu" --shflags="-target aarch64-linux-gnu -fuse-ld=lld" --root
161+
xmake f --mode=release --kind=static --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ --ld=aarch64-linux-gnu-g++ --sh=aarch64-linux-gnu-g++ --root
164162
xmake --all --root
165163
166164
- name: Build BinaryStream Shared (Release)
167165
run: |
168-
xmake f --mode=release --kind=shared --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cxflags="-target aarch64-linux-gnu" --shflags="-target aarch64-linux-gnu -fuse-ld=lld" --root
166+
xmake f --mode=release --kind=shared --arch=arm64 --sdk=/usr/aarch64-linux-gnu --bin=/usr/bin --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ --ld=aarch64-linux-gnu-g++ --sh=aarch64-linux-gnu-g++ --root
169167
xmake --all --root
170168
171169
- name: Upload Artifact

include/binarystream-c/BinaryStream.h

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 91 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,92 @@
1-
// Copyright © 2025 GlacieTeam. All rights reserved.
2-
//
3-
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
4-
// distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5-
//
6-
// SPDX-License-Identifier: MPL-2.0
7-
8-
#pragma once
9-
#include <binarystream-c/Macros.h>
10-
#include <stddef.h>
11-
#include <stdint.h>
12-
13-
#ifdef __cplusplus
14-
extern "C" {
15-
#endif
16-
17-
struct stream_buffer {
18-
uint8_t* data;
19-
size_t size;
20-
};
21-
BSAPI void stream_buffer_destroy(stream_buffer* buffer);
22-
23-
BSAPI void* read_only_binary_stream_create(const uint8_t* data, size_t size, bool copy_data, bool big_endian);
24-
BSAPI void read_only_binary_stream_destroy(void* stream);
25-
26-
BSAPI size_t read_only_binary_stream_size(void* stream);
27-
BSAPI size_t read_only_binary_stream_get_position(void* stream);
28-
BSAPI void read_only_binary_stream_set_position(void* stream, size_t position);
29-
BSAPI void read_only_binary_stream_reset_position(void* stream);
30-
BSAPI bool read_only_binary_stream_overflowed(void* stream);
31-
BSAPI bool read_only_binary_stream_has_data_left(void* stream);
32-
33-
BSAPI stream_buffer read_only_binary_stream_get_left_buffer(void* stream);
34-
35-
BSAPI void read_only_binary_stream_ignore_bytes(void* stream, size_t length);
36-
37-
BSAPI size_t read_only_binary_stream_get_bytes(void* stream, uint8_t* buffer, size_t buffer_size);
38-
BSAPI bool read_only_binary_stream_get_bool(void* stream);
39-
BSAPI uint8_t read_only_binary_stream_get_unsigned_char(void* stream);
40-
BSAPI uint16_t read_only_binary_stream_get_unsigned_short(void* stream);
41-
BSAPI int16_t read_only_binary_stream_get_signed_short(void* stream);
42-
BSAPI uint32_t read_only_binary_stream_get_unsigned_int24(void* stream);
43-
BSAPI uint32_t read_only_binary_stream_get_unsigned_int(void* stream);
44-
BSAPI int32_t read_only_binary_stream_get_signed_int(void* stream);
45-
BSAPI uint64_t read_only_binary_stream_get_unsigned_int64(void* stream);
46-
BSAPI int64_t read_only_binary_stream_get_signed_int64(void* stream);
47-
BSAPI float read_only_binary_stream_get_float(void* stream);
48-
BSAPI double read_only_binary_stream_get_double(void* stream);
49-
BSAPI uint32_t read_only_binary_stream_get_unsigned_varint(void* stream);
50-
BSAPI int32_t read_only_binary_stream_get_varint(void* stream);
51-
BSAPI uint64_t read_only_binary_stream_get_unsigned_varint64(void* stream);
52-
BSAPI int64_t read_only_binary_stream_get_varint64(void* stream);
53-
BSAPI int32_t read_only_binary_stream_get_signed_big_endian_int(void* stream);
54-
55-
BSAPI stream_buffer read_only_binary_stream_get_string(void* stream);
56-
57-
BSAPI size_t read_only_binary_stream_get_raw_bytes(void* stream, uint8_t* buffer, size_t length);
58-
59-
#ifdef __cplusplus
60-
}
1+
// Copyright © 2025 GlacieTeam. All rights reserved.
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
4+
// distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
//
6+
// SPDX-License-Identifier: MPL-2.0
7+
8+
#pragma once
9+
#include <binarystream-c/Macros.h>
10+
#include <stddef.h>
11+
#include <stdint.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
struct stream_buffer {
18+
uint8_t* data;
19+
size_t size;
20+
};
21+
BSAPI void stream_buffer_destroy(stream_buffer* buffer);
22+
23+
// ReadOnlyBinaryStream
24+
BSAPI void* read_only_binary_stream_create(const uint8_t* data, size_t size, bool copy_data, bool big_endian);
25+
BSAPI void read_only_binary_stream_destroy(void* stream);
26+
27+
BSAPI size_t read_only_binary_stream_size(void* stream);
28+
BSAPI size_t read_only_binary_stream_get_position(void* stream);
29+
BSAPI void read_only_binary_stream_set_position(void* stream, size_t position);
30+
BSAPI void read_only_binary_stream_reset_position(void* stream);
31+
BSAPI bool read_only_binary_stream_overflowed(void* stream);
32+
BSAPI bool read_only_binary_stream_has_data_left(void* stream);
33+
34+
BSAPI stream_buffer* read_only_binary_stream_get_left_buffer(void* stream);
35+
36+
BSAPI void read_only_binary_stream_ignore_bytes(void* stream, size_t length);
37+
38+
BSAPI size_t read_only_binary_stream_get_bytes(void* stream, uint8_t* buffer, size_t buffer_size);
39+
BSAPI bool read_only_binary_stream_get_bool(void* stream);
40+
BSAPI uint8_t read_only_binary_stream_get_unsigned_char(void* stream);
41+
BSAPI uint16_t read_only_binary_stream_get_unsigned_short(void* stream);
42+
BSAPI int16_t read_only_binary_stream_get_signed_short(void* stream);
43+
BSAPI uint32_t read_only_binary_stream_get_unsigned_int24(void* stream);
44+
BSAPI uint32_t read_only_binary_stream_get_unsigned_int(void* stream);
45+
BSAPI int32_t read_only_binary_stream_get_signed_int(void* stream);
46+
BSAPI uint64_t read_only_binary_stream_get_unsigned_int64(void* stream);
47+
BSAPI int64_t read_only_binary_stream_get_signed_int64(void* stream);
48+
BSAPI float read_only_binary_stream_get_float(void* stream);
49+
BSAPI double read_only_binary_stream_get_double(void* stream);
50+
BSAPI uint32_t read_only_binary_stream_get_unsigned_varint(void* stream);
51+
BSAPI int32_t read_only_binary_stream_get_varint(void* stream);
52+
BSAPI uint64_t read_only_binary_stream_get_unsigned_varint64(void* stream);
53+
BSAPI int64_t read_only_binary_stream_get_varint64(void* stream);
54+
BSAPI int32_t read_only_binary_stream_get_signed_big_endian_int(void* stream);
55+
56+
BSAPI stream_buffer* read_only_binary_stream_get_string(void* stream);
57+
58+
BSAPI size_t read_only_binary_stream_get_raw_bytes(void* stream, uint8_t* buffer, size_t length);
59+
60+
61+
// BinaryStream
62+
// C++ class BinaryStream : public ReadOnlyBinaryStream
63+
// BinaryStream handle can use functions in ReadOnlyBinaryStream
64+
BSAPI void* binary_stream_create(bool big_endian);
65+
BSAPI void* binary_stream_create_with_buffer(const uint8_t* data, size_t size, bool copy_data, bool big_endian);
66+
BSAPI void binary_stream_destroy(void* stream);
67+
BSAPI void binary_stream_reset(void* stream);
68+
69+
BSAPI void binary_stream_write_bytes(void* stream, const uint8_t* data, size_t size);
70+
BSAPI void binary_stream_write_bool(void* stream, bool value);
71+
BSAPI void binary_stream_write_unsigned_char(void* stream, uint8_t value);
72+
BSAPI void binary_stream_write_unsigned_short(void* stream, uint16_t value);
73+
BSAPI void binary_stream_write_signed_short(void* stream, int16_t value);
74+
BSAPI void binary_stream_write_unsigned_int24(void* stream, uint32_t value);
75+
BSAPI void binary_stream_write_unsigned_int(void* stream, uint32_t value);
76+
BSAPI void binary_stream_write_signed_int(void* stream, int32_t value);
77+
BSAPI void binary_stream_write_unsigned_int64(void* stream, uint64_t value);
78+
BSAPI void binary_stream_write_signed_int64(void* stream, int64_t value);
79+
BSAPI void binary_stream_write_float(void* stream, float value);
80+
BSAPI void binary_stream_write_double(void* stream, double value);
81+
BSAPI void binary_stream_write_unsigned_varint(void* stream, uint32_t value);
82+
BSAPI void binary_stream_write_varint(void* stream, int32_t value);
83+
BSAPI void binary_stream_write_unsigned_varint64(void* stream, uint64_t value);
84+
BSAPI void binary_stream_write_varint64(void* stream, int64_t value);
85+
BSAPI void binary_stream_write_string(void* stream, const char* str, size_t length);
86+
BSAPI void binary_stream_write_signed_big_endian_int(void* stream, int32_t value);
87+
88+
BSAPI stream_buffer* binary_stream_get_buffer(void* stream);
89+
90+
#ifdef __cplusplus
91+
}
6192
#endif

0 commit comments

Comments
 (0)