@@ -28,9 +28,9 @@ fn parse_ascii_int(b : Bytes) -> Int {
2828}
2929
3030///|
31- /// The value of the first `@moonrpc .Header` whose name equals the ASCII `name`,
31+ /// The value of the first `@header .Header` whose name equals the ASCII `name`,
3232/// or `None`.
33- fn h2_ header_value(headers : Array [@moonrpc .Header ], name : String ) -> Bytes? {
33+ fn h2_ header_value(headers : Array [@header .Header ], name : String ) -> Bytes? {
3434 let want = ascii_bytes(name)
3535 for h in headers {
3636 if h.name == want {
@@ -102,8 +102,8 @@ pub fn RpcServer::to_h2(self : RpcServer) -> @moonrpc.H2Server {
102102/// across every call on the channel.
103103pub struct RpcChannel {
104104 engine : @moonrpc.H2Server
105- encoder : @moonrpc. HpackEncoder
106- decoder : @moonrpc. HpackDecoder
105+ encoder : @hpack. Encoder
106+ decoder : @hpack. Decoder
107107 authority : String
108108 mut next_stream_id : Int
109109}
@@ -119,8 +119,8 @@ pub fn RpcChannel::connect(
119119 let engine = server.to_h2()
120120 let ch = {
121121 engine,
122- encoder: @moonrpc. HpackEncoder ::new(),
123- decoder: @moonrpc. HpackDecoder ::new(),
122+ encoder: @hpack. Encoder ::new(),
123+ decoder: @hpack. Decoder ::new(),
124124 authority,
125125 next_stream_id: 1,
126126 }
@@ -346,17 +346,14 @@ pub fn RpcChannel::call_bidi_streaming(
346346///|
347347/// Split a run of concatenated gRPC length-prefixed messages into their payloads,
348348/// returning the complete messages and any trailing partial-message octets that
349- /// have not yet arrived in full. Like `decode_all_messages ` but surfaces the
349+ /// have not yet arrived in full. Like `@moonrpc.split_messages ` but surfaces the
350350/// remainder so a streaming caller can carry it across DATA frames.
351351fn drain_messages(body : Bytes ) -> (Array [Bytes ], Bytes ) {
352352 let out : Array [Bytes ] = []
353353 let n = body.length()
354354 let mut off = 0
355355 while n - off >= 5 {
356- let len = (body[off + 1].to_int() << 24) |
357- (body[off + 2].to_int() << 16) |
358- (body[off + 3].to_int() << 8) |
359- body[off + 4].to_int()
356+ let len = @moonrpc.message_len(body[:], at=off).unwrap()
360357 if n - off < 5 + len {
361358 break
362359 }
@@ -379,12 +376,12 @@ fn RpcChannel::open(
379376 let sid = self.next_stream_id
380377 self.next_stream_id = self.next_stream_id + 2
381378 let block = self.encoder.encode([
382- { name: b ":method", value: b "POST ", } ,
383- { name: b ":scheme", value: b "http", } ,
384- { name: b ":path", value: ascii_bytes( path), } ,
385- { name: b ":authority", value: ascii_bytes( self.authority), } ,
386- { name: b "content-type", value: b "application/grpc", } ,
387- { name: b "te", value: b "trailers", } ,
379+ @header. Header ::of( ":method", "POST ") ,
380+ @header. Header ::of( ":scheme", "http") ,
381+ @header. Header ::of( ":path", path),
382+ @header. Header ::of( ":authority", self.authority),
383+ @header. Header ::of( "content-type", "application/grpc") ,
384+ @header. Header ::of( "te", "trailers") ,
388385 ])
389386 let frames = self.engine.feed(
390387 Headers (
@@ -441,27 +438,5 @@ fn RpcChannel::collect_reply(
441438 _ => ()
442439 }
443440 }
444- (status_code, decode_all_messages(body.to_bytes()))
445- }
446-
447- ///|
448- /// Split a run of concatenated gRPC length-prefixed messages into their payloads,
449- /// stopping at the first truncated frame. Each message is a 1-byte compression flag
450- /// plus a 4-byte big-endian length plus that many payload octets.
451- fn decode_all_messages(body : Bytes ) -> Array [Bytes ] {
452- let out : Array [Bytes ] = []
453- let n = body.length()
454- let mut off = 0
455- while n - off >= 5 {
456- let len = (body[off + 1].to_int() << 24) |
457- (body[off + 2].to_int() << 16) |
458- (body[off + 3].to_int() << 8) |
459- body[off + 4].to_int()
460- if n - off < 5 + len {
461- break
462- }
463- out.push(body[off + 5:off + 5 + len].to_owned())
464- off = off + 5 + len
465- }
466- out
441+ (status_code, @moonrpc.split_messages(body.to_bytes()))
467442}
0 commit comments