Skip to content

Commit 2bce7b9

Browse files
committed
Stop using "our" Bytes type.
It's a simple alias to Vec<u8>, so it doesn't provide any value, and it conflicts with a popular Bytes type from the bytes crate. This is a non-breaking change, since we retain the public alias. Signed-off-by: Piotr Sikora <[email protected]>
1 parent 6d88ed5 commit 2bce7b9

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

src/hostcalls.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn get_buffer(
8585
buffer_type: BufferType,
8686
start: usize,
8787
max_size: usize,
88-
) -> Result<Option<Bytes>, Status> {
88+
) -> Result<Option<Vec<u8>>, Status> {
8989
let mut return_data: *mut u8 = null_mut();
9090
let mut return_size: usize = 0;
9191
unsafe {
@@ -163,7 +163,7 @@ pub fn get_map(map_type: MapType) -> Result<Vec<(String, String)>, Status> {
163163
}
164164
}
165165

166-
pub fn get_map_bytes(map_type: MapType) -> Result<Vec<(String, Bytes)>, Status> {
166+
pub fn get_map_bytes(map_type: MapType) -> Result<Vec<(String, Vec<u8>)>, Status> {
167167
unsafe {
168168
let mut return_data: *mut u8 = null_mut();
169169
let mut return_size: usize = 0;
@@ -250,7 +250,7 @@ pub fn get_map_value(map_type: MapType, key: &str) -> Result<Option<String>, Sta
250250
}
251251
}
252252

253-
pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result<Option<Bytes>, Status> {
253+
pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result<Option<Vec<u8>>, Status> {
254254
let mut return_data: *mut u8 = null_mut();
255255
let mut return_size: usize = 0;
256256
unsafe {
@@ -393,7 +393,7 @@ extern "C" {
393393
) -> Status;
394394
}
395395

396-
pub fn get_property(path: Vec<&str>) -> Result<Option<Bytes>, Status> {
396+
pub fn get_property(path: Vec<&str>) -> Result<Option<Vec<u8>>, Status> {
397397
let serialized_path = utils::serialize_property_path(path);
398398
let mut return_data: *mut u8 = null_mut();
399399
let mut return_size: usize = 0;
@@ -457,7 +457,7 @@ extern "C" {
457457
) -> Status;
458458
}
459459

460-
pub fn get_shared_data(key: &str) -> Result<(Option<Bytes>, Option<u32>), Status> {
460+
pub fn get_shared_data(key: &str) -> Result<(Option<Vec<u8>>, Option<u32>), Status> {
461461
let mut return_data: *mut u8 = null_mut();
462462
let mut return_size: usize = 0;
463463
let mut return_cas: u32 = 0;
@@ -568,7 +568,7 @@ extern "C" {
568568
) -> Status;
569569
}
570570

571-
pub fn dequeue_shared_queue(queue_id: u32) -> Result<Option<Bytes>, Status> {
571+
pub fn dequeue_shared_queue(queue_id: u32) -> Result<Option<Vec<u8>>, Status> {
572572
let mut return_data: *mut u8 = null_mut();
573573
let mut return_size: usize = 0;
574574
unsafe {
@@ -1029,7 +1029,7 @@ extern "C" {
10291029
pub fn call_foreign_function(
10301030
function_name: &str,
10311031
arguments: Option<&[u8]>,
1032-
) -> Result<Option<Bytes>, Status> {
1032+
) -> Result<Option<Vec<u8>>, Status> {
10331033
let mut return_data: *mut u8 = null_mut();
10341034
let mut return_size: usize = 0;
10351035
unsafe {
@@ -1139,18 +1139,17 @@ pub fn increment_metric(metric_id: u32, offset: i64) -> Result<(), Status> {
11391139
}
11401140

11411141
mod utils {
1142-
use crate::types::Bytes;
11431142
use std::convert::TryFrom;
11441143

1145-
pub(super) fn serialize_property_path(path: Vec<&str>) -> Bytes {
1144+
pub(super) fn serialize_property_path(path: Vec<&str>) -> Vec<u8> {
11461145
if path.is_empty() {
11471146
return Vec::new();
11481147
}
11491148
let mut size: usize = 0;
11501149
for part in &path {
11511150
size += part.len() + 1;
11521151
}
1153-
let mut bytes: Bytes = Vec::with_capacity(size);
1152+
let mut bytes = Vec::with_capacity(size);
11541153
for part in &path {
11551154
bytes.extend_from_slice(part.as_bytes());
11561155
bytes.push(0);
@@ -1159,12 +1158,12 @@ mod utils {
11591158
bytes
11601159
}
11611160

1162-
pub(super) fn serialize_map(map: Vec<(&str, &str)>) -> Bytes {
1161+
pub(super) fn serialize_map(map: Vec<(&str, &str)>) -> Vec<u8> {
11631162
let mut size: usize = 4;
11641163
for (name, value) in &map {
11651164
size += name.len() + value.len() + 10;
11661165
}
1167-
let mut bytes: Bytes = Vec::with_capacity(size);
1166+
let mut bytes = Vec::with_capacity(size);
11681167
bytes.extend_from_slice(&map.len().to_le_bytes());
11691168
for (name, value) in &map {
11701169
bytes.extend_from_slice(&name.len().to_le_bytes());
@@ -1179,12 +1178,12 @@ mod utils {
11791178
bytes
11801179
}
11811180

1182-
pub(super) fn serialize_map_bytes(map: Vec<(&str, &[u8])>) -> Bytes {
1181+
pub(super) fn serialize_map_bytes(map: Vec<(&str, &[u8])>) -> Vec<u8> {
11831182
let mut size: usize = 4;
11841183
for (name, value) in &map {
11851184
size += name.len() + value.len() + 10;
11861185
}
1187-
let mut bytes: Bytes = Vec::with_capacity(size);
1186+
let mut bytes = Vec::with_capacity(size);
11881187
bytes.extend_from_slice(&map.len().to_le_bytes());
11891188
for (name, value) in &map {
11901189
bytes.extend_from_slice(&name.len().to_le_bytes());
@@ -1223,7 +1222,7 @@ mod utils {
12231222
map
12241223
}
12251224

1226-
pub(super) fn deserialize_map_bytes(bytes: &[u8]) -> Vec<(String, Bytes)> {
1225+
pub(super) fn deserialize_map_bytes(bytes: &[u8]) -> Vec<(String, Vec<u8>)> {
12271226
let mut map = Vec::new();
12281227
if bytes.is_empty() {
12291228
return map;

src/traits.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ pub trait Context {
2121
hostcalls::get_current_time().unwrap()
2222
}
2323

24-
fn get_property(&self, path: Vec<&str>) -> Option<Bytes> {
24+
fn get_property(&self, path: Vec<&str>) -> Option<Vec<u8>> {
2525
hostcalls::get_property(path).unwrap()
2626
}
2727

2828
fn set_property(&self, path: Vec<&str>, value: Option<&[u8]>) {
2929
hostcalls::set_property(path, value).unwrap()
3030
}
3131

32-
fn get_shared_data(&self, key: &str) -> (Option<Bytes>, Option<u32>) {
32+
fn get_shared_data(&self, key: &str) -> (Option<Vec<u8>>, Option<u32>) {
3333
hostcalls::get_shared_data(key).unwrap()
3434
}
3535

@@ -50,7 +50,7 @@ pub trait Context {
5050
hostcalls::resolve_shared_queue(vm_id, name).unwrap()
5151
}
5252

53-
fn dequeue_shared_queue(&self, queue_id: u32) -> Result<Option<Bytes>, Status> {
53+
fn dequeue_shared_queue(&self, queue_id: u32) -> Result<Option<Vec<u8>>, Status> {
5454
hostcalls::dequeue_shared_queue(queue_id)
5555
}
5656

@@ -82,35 +82,35 @@ pub trait Context {
8282
hostcalls::get_map(MapType::HttpCallResponseHeaders).unwrap()
8383
}
8484

85-
fn get_http_call_response_headers_bytes(&self) -> Vec<(String, Bytes)> {
85+
fn get_http_call_response_headers_bytes(&self) -> Vec<(String, Vec<u8>)> {
8686
hostcalls::get_map_bytes(MapType::HttpCallResponseHeaders).unwrap()
8787
}
8888

8989
fn get_http_call_response_header(&self, name: &str) -> Option<String> {
9090
hostcalls::get_map_value(MapType::HttpCallResponseHeaders, name).unwrap()
9191
}
9292

93-
fn get_http_call_response_header_bytes(&self, name: &str) -> Option<Bytes> {
93+
fn get_http_call_response_header_bytes(&self, name: &str) -> Option<Vec<u8>> {
9494
hostcalls::get_map_value_bytes(MapType::HttpCallResponseHeaders, name).unwrap()
9595
}
9696

97-
fn get_http_call_response_body(&self, start: usize, max_size: usize) -> Option<Bytes> {
97+
fn get_http_call_response_body(&self, start: usize, max_size: usize) -> Option<Vec<u8>> {
9898
hostcalls::get_buffer(BufferType::HttpCallResponseBody, start, max_size).unwrap()
9999
}
100100

101101
fn get_http_call_response_trailers(&self) -> Vec<(String, String)> {
102102
hostcalls::get_map(MapType::HttpCallResponseTrailers).unwrap()
103103
}
104104

105-
fn get_http_call_response_trailers_bytes(&self) -> Vec<(String, Bytes)> {
105+
fn get_http_call_response_trailers_bytes(&self) -> Vec<(String, Vec<u8>)> {
106106
hostcalls::get_map_bytes(MapType::HttpCallResponseTrailers).unwrap()
107107
}
108108

109109
fn get_http_call_response_trailer(&self, name: &str) -> Option<String> {
110110
hostcalls::get_map_value(MapType::HttpCallResponseTrailers, name).unwrap()
111111
}
112112

113-
fn get_http_call_response_trailer_bytes(&self, name: &str) -> Option<Bytes> {
113+
fn get_http_call_response_trailer_bytes(&self, name: &str) -> Option<Vec<u8>> {
114114
hostcalls::get_map_value_bytes(MapType::HttpCallResponseTrailers, name).unwrap()
115115
}
116116

@@ -135,7 +135,7 @@ pub trait Context {
135135

136136
fn on_grpc_call_response(&mut self, _token_id: u32, _status_code: u32, _response_size: usize) {}
137137

138-
fn get_grpc_call_response_body(&self, start: usize, max_size: usize) -> Option<Bytes> {
138+
fn get_grpc_call_response_body(&self, start: usize, max_size: usize) -> Option<Vec<u8>> {
139139
hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, start, max_size).unwrap()
140140
}
141141

@@ -155,11 +155,11 @@ pub trait Context {
155155

156156
fn on_grpc_stream_initial_metadata(&mut self, _token_id: u32, _num_elements: u32) {}
157157

158-
fn get_grpc_stream_initial_metadata(&self) -> Vec<(String, Bytes)> {
158+
fn get_grpc_stream_initial_metadata(&self) -> Vec<(String, Vec<u8>)> {
159159
hostcalls::get_map_bytes(MapType::GrpcReceiveInitialMetadata).unwrap()
160160
}
161161

162-
fn get_grpc_stream_initial_metadata_value(&self, name: &str) -> Option<Bytes> {
162+
fn get_grpc_stream_initial_metadata_value(&self, name: &str) -> Option<Vec<u8>> {
163163
hostcalls::get_map_value_bytes(MapType::GrpcReceiveInitialMetadata, name).unwrap()
164164
}
165165

@@ -169,17 +169,17 @@ pub trait Context {
169169

170170
fn on_grpc_stream_message(&mut self, _token_id: u32, _message_size: usize) {}
171171

172-
fn get_grpc_stream_message(&mut self, start: usize, max_size: usize) -> Option<Bytes> {
172+
fn get_grpc_stream_message(&mut self, start: usize, max_size: usize) -> Option<Vec<u8>> {
173173
hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, start, max_size).unwrap()
174174
}
175175

176176
fn on_grpc_stream_trailing_metadata(&mut self, _token_id: u32, _num_elements: u32) {}
177177

178-
fn get_grpc_stream_trailing_metadata(&self) -> Vec<(String, Bytes)> {
178+
fn get_grpc_stream_trailing_metadata(&self) -> Vec<(String, Vec<u8>)> {
179179
hostcalls::get_map_bytes(MapType::GrpcReceiveTrailingMetadata).unwrap()
180180
}
181181

182-
fn get_grpc_stream_trailing_metadata_value(&self, name: &str) -> Option<Bytes> {
182+
fn get_grpc_stream_trailing_metadata_value(&self, name: &str) -> Option<Vec<u8>> {
183183
hostcalls::get_map_value_bytes(MapType::GrpcReceiveTrailingMetadata, name).unwrap()
184184
}
185185

@@ -201,7 +201,7 @@ pub trait Context {
201201
&self,
202202
function_name: &str,
203203
arguments: Option<&[u8]>,
204-
) -> Result<Option<Bytes>, Status> {
204+
) -> Result<Option<Vec<u8>>, Status> {
205205
hostcalls::call_foreign_function(function_name, arguments)
206206
}
207207

@@ -219,15 +219,15 @@ pub trait RootContext: Context {
219219
true
220220
}
221221

222-
fn get_vm_configuration(&self) -> Option<Bytes> {
222+
fn get_vm_configuration(&self) -> Option<Vec<u8>> {
223223
hostcalls::get_buffer(BufferType::VmConfiguration, 0, usize::MAX).unwrap()
224224
}
225225

226226
fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool {
227227
true
228228
}
229229

230-
fn get_plugin_configuration(&self) -> Option<Bytes> {
230+
fn get_plugin_configuration(&self) -> Option<Vec<u8>> {
231231
hostcalls::get_buffer(BufferType::PluginConfiguration, 0, usize::MAX).unwrap()
232232
}
233233

@@ -263,7 +263,7 @@ pub trait StreamContext: Context {
263263
Action::Continue
264264
}
265265

266-
fn get_downstream_data(&self, start: usize, max_size: usize) -> Option<Bytes> {
266+
fn get_downstream_data(&self, start: usize, max_size: usize) -> Option<Vec<u8>> {
267267
hostcalls::get_buffer(BufferType::DownstreamData, start, max_size).unwrap()
268268
}
269269

@@ -285,7 +285,7 @@ pub trait StreamContext: Context {
285285
Action::Continue
286286
}
287287

288-
fn get_upstream_data(&self, start: usize, max_size: usize) -> Option<Bytes> {
288+
fn get_upstream_data(&self, start: usize, max_size: usize) -> Option<Vec<u8>> {
289289
hostcalls::get_buffer(BufferType::UpstreamData, start, max_size).unwrap()
290290
}
291291

@@ -315,7 +315,7 @@ pub trait HttpContext: Context {
315315
hostcalls::get_map(MapType::HttpRequestHeaders).unwrap()
316316
}
317317

318-
fn get_http_request_headers_bytes(&self) -> Vec<(String, Bytes)> {
318+
fn get_http_request_headers_bytes(&self) -> Vec<(String, Vec<u8>)> {
319319
hostcalls::get_map_bytes(MapType::HttpRequestHeaders).unwrap()
320320
}
321321

@@ -331,7 +331,7 @@ pub trait HttpContext: Context {
331331
hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap()
332332
}
333333

334-
fn get_http_request_header_bytes(&self, name: &str) -> Option<Bytes> {
334+
fn get_http_request_header_bytes(&self, name: &str) -> Option<Vec<u8>> {
335335
hostcalls::get_map_value_bytes(MapType::HttpRequestHeaders, name).unwrap()
336336
}
337337

@@ -355,7 +355,7 @@ pub trait HttpContext: Context {
355355
Action::Continue
356356
}
357357

358-
fn get_http_request_body(&self, start: usize, max_size: usize) -> Option<Bytes> {
358+
fn get_http_request_body(&self, start: usize, max_size: usize) -> Option<Vec<u8>> {
359359
hostcalls::get_buffer(BufferType::HttpRequestBody, start, max_size).unwrap()
360360
}
361361

@@ -371,7 +371,7 @@ pub trait HttpContext: Context {
371371
hostcalls::get_map(MapType::HttpRequestTrailers).unwrap()
372372
}
373373

374-
fn get_http_request_trailers_bytes(&self) -> Vec<(String, Bytes)> {
374+
fn get_http_request_trailers_bytes(&self) -> Vec<(String, Vec<u8>)> {
375375
hostcalls::get_map_bytes(MapType::HttpRequestTrailers).unwrap()
376376
}
377377

@@ -387,7 +387,7 @@ pub trait HttpContext: Context {
387387
hostcalls::get_map_value(MapType::HttpRequestTrailers, name).unwrap()
388388
}
389389

390-
fn get_http_request_trailer_bytes(&self, name: &str) -> Option<Bytes> {
390+
fn get_http_request_trailer_bytes(&self, name: &str) -> Option<Vec<u8>> {
391391
hostcalls::get_map_value_bytes(MapType::HttpRequestTrailers, name).unwrap()
392392
}
393393

@@ -423,7 +423,7 @@ pub trait HttpContext: Context {
423423
hostcalls::get_map(MapType::HttpResponseHeaders).unwrap()
424424
}
425425

426-
fn get_http_response_headers_bytes(&self) -> Vec<(String, Bytes)> {
426+
fn get_http_response_headers_bytes(&self) -> Vec<(String, Vec<u8>)> {
427427
hostcalls::get_map_bytes(MapType::HttpResponseHeaders).unwrap()
428428
}
429429

@@ -439,7 +439,7 @@ pub trait HttpContext: Context {
439439
hostcalls::get_map_value(MapType::HttpResponseHeaders, name).unwrap()
440440
}
441441

442-
fn get_http_response_header_bytes(&self, name: &str) -> Option<Bytes> {
442+
fn get_http_response_header_bytes(&self, name: &str) -> Option<Vec<u8>> {
443443
hostcalls::get_map_value_bytes(MapType::HttpResponseHeaders, name).unwrap()
444444
}
445445

@@ -463,7 +463,7 @@ pub trait HttpContext: Context {
463463
Action::Continue
464464
}
465465

466-
fn get_http_response_body(&self, start: usize, max_size: usize) -> Option<Bytes> {
466+
fn get_http_response_body(&self, start: usize, max_size: usize) -> Option<Vec<u8>> {
467467
hostcalls::get_buffer(BufferType::HttpResponseBody, start, max_size).unwrap()
468468
}
469469

@@ -479,7 +479,7 @@ pub trait HttpContext: Context {
479479
hostcalls::get_map(MapType::HttpResponseTrailers).unwrap()
480480
}
481481

482-
fn get_http_response_trailers_bytes(&self) -> Vec<(String, Bytes)> {
482+
fn get_http_response_trailers_bytes(&self) -> Vec<(String, Vec<u8>)> {
483483
hostcalls::get_map_bytes(MapType::HttpResponseTrailers).unwrap()
484484
}
485485

@@ -495,7 +495,7 @@ pub trait HttpContext: Context {
495495
hostcalls::get_map_value(MapType::HttpResponseTrailers, name).unwrap()
496496
}
497497

498-
fn get_http_response_trailer_bytes(&self, name: &str) -> Option<Bytes> {
498+
fn get_http_response_trailer_bytes(&self, name: &str) -> Option<Vec<u8>> {
499499
hostcalls::get_map_value_bytes(MapType::HttpResponseTrailers, name).unwrap()
500500
}
501501

0 commit comments

Comments
 (0)