Skip to content

Commit b6a5e7a

Browse files
committed
fix
Signed-off-by: Shikugawa <Shikugawa@gmail.com>
1 parent 26f916a commit b6a5e7a

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/dispatcher.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use crate::hostcalls;
1616
use crate::traits::*;
1717
use crate::types::*;
18+
use core::panic;
1819
use hashbrown::HashMap;
1920
use std::cell::{Cell, RefCell};
2021

@@ -416,6 +417,7 @@ impl Dispatcher {
416417
}
417418
} else {
418419
// TODO(shikugawa): Try to check grpc stream tokens here
420+
panic!("invalid token_id")
419421
}
420422
}
421423

@@ -436,6 +438,7 @@ impl Dispatcher {
436438
}
437439
} else {
438440
// TODO(shikugawa): Try to check grpc stream tokens here
441+
panic!("invalid token_id")
439442
}
440443
}
441444
}

src/hostcalls.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ pub fn dispatch_http_call(
654654
extern "C" {
655655
fn proxy_grpc_call(
656656
upstream_data: *const u8,
657-
upstream_size: usize, // TODO(shikugawa): remove grpc_service after next ABI released.
657+
upstream_size: usize,
658658
service_name_data: *const u8,
659659
service_name_size: usize,
660660
method_name_data: *const u8,
@@ -663,7 +663,7 @@ extern "C" {
663663
initial_metadata_size: usize,
664664
message_data_data: *const u8,
665665
message_data_size: usize,
666-
timeout_milliseconds: u32,
666+
timeout: u32,
667667
return_callout_id: *mut u32,
668668
) -> Status;
669669
}
@@ -672,12 +672,12 @@ pub fn dispatch_grpc_call(
672672
upstream_name: &str,
673673
service_name: &str,
674674
method_name: &str,
675-
initial_metadata: Vec<(&str, &str)>,
675+
initial_metadata: Vec<(&str, &[u8])>,
676676
message: Option<&[u8]>,
677677
timeout: Duration,
678678
) -> Result<u32, Status> {
679679
let mut return_callout_id = 0;
680-
let serialized_initial_metadata = utils::serialize_map(initial_metadata);
680+
let serialized_initial_metadata = utils::serialize_bytes_value_map(initial_metadata);
681681
unsafe {
682682
match proxy_grpc_call(
683683
upstream_name.as_ptr(),
@@ -836,6 +836,26 @@ mod utils {
836836
bytes
837837
}
838838

839+
pub(super) fn serialize_bytes_value_map(map: Vec<(&str, &[u8])>) -> Bytes {
840+
let mut size: usize = 4;
841+
for (name, value) in &map {
842+
size += name.len() + value.len() + 10;
843+
}
844+
let mut bytes: Bytes = Vec::with_capacity(size);
845+
bytes.extend_from_slice(&map.len().to_le_bytes());
846+
for (name, value) in &map {
847+
bytes.extend_from_slice(&name.len().to_le_bytes());
848+
bytes.extend_from_slice(&value.len().to_le_bytes());
849+
}
850+
for (name, value) in &map {
851+
bytes.extend_from_slice(&name.as_bytes());
852+
bytes.push(0);
853+
bytes.extend_from_slice(&value);
854+
bytes.push(0);
855+
}
856+
bytes
857+
}
858+
839859
pub(super) fn deserialize_map(bytes: &[u8]) -> Vec<(String, String)> {
840860
let mut map = Vec::new();
841861
if bytes.is_empty() {

src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub trait Context {
9595
upstream_name: &str,
9696
service_name: &str,
9797
method_name: &str,
98-
initial_metadata: Vec<(&str, &str)>,
98+
initial_metadata: Vec<(&str, &[u8])>,
9999
message: Option<&[u8]>,
100100
timeout: Duration,
101101
) -> Result<u32, Status> {

0 commit comments

Comments
 (0)