# flare.grpc.client_stream

> A module of flare_mlake's API.

``flare.grpc.client_stream`` -- server-side client-streaming + bidi.

A client-streaming call carries *many* request LPM frames and a
*single* response message; a bidi call carries many request frames and
*many* response frames. Both map onto one HTTP/2 stream:

* Request HEADERS + N request LPM frames, then the client half-closes.
* Response HEADERS + (client-streaming) one LPM frame / (bidi) N LPM
  frames + trailing HEADERS carrying ``grpc-status``.

The flare H2 reactor assembles the whole request body (all N frames)
before dispatch, so these adapters decode every request frame into a
list and hand it to the handler at once.

ponytail: request ingress is buffered (the reactor half-close boundary
is the whole assembled body), so a handler cannot react to request
frame k before frame k+1 arrives. True incremental request ingress
(surface each frame as it lands) needs a partial-body dispatch hook in
the reactor; the buffered decode here is the in-language ceiling and
covers the common request-aggregation shape. Bidi responses *are*
incremental (each reply ships as its own DATA frame via the K1
streaming path).

## Structs

### `GrpcClientStreamingService`

```mojo
struct GrpcClientStreamingService[H: GrpcClientStreaming & Copyable & Deinitable]
```

Adapt a :class:`GrpcClientStreaming` handler into a :trait:`Handler` for the unified H2 reactor. One H2 stream = one client-streaming call; the reply is a single buffered LPM frame.

Implements: `Copyable`, `Handler`, `Movable`

Fields:

- `handler: H`

#### `BodyType`

```mojo
comptime BodyType = InlineBody
```

The ``Body`` impl this handler authors its response with.

Defaults to :struct:`InlineBody` so plain handlers that return
``Response`` conform without declaring it. Override in a handler that
returns a typed ``ResponseImpl[SomeBody]``.

#### `serve`

```mojo
def serve(self, req: Request) -> Response
```

### `GrpcBidiService`

```mojo
struct GrpcBidiService[H: GrpcBidiStreaming & Copyable & Deinitable]
```

Adapt a :class:`GrpcBidiStreaming` handler into a :trait:`Handler`. Responses stream incrementally via the K1 body-stream path (one DATA frame per reply message).

Implements: `Copyable`, `Handler`, `Movable`

Fields:

- `handler: H`

#### `BodyType`

```mojo
comptime BodyType = InlineBody
```

The ``Body`` impl this handler authors its response with.

Defaults to :struct:`InlineBody` so plain handlers that return
``Response`` conform without declaring it. Override in a handler that
returns a typed ``ResponseImpl[SomeBody]``.

#### `serve`

```mojo
def serve(self, req: Request) -> Response
```

## Traits

### `GrpcClientStreaming`

```mojo
undefined
```

Client-streaming gRPC handler.

Receives the ordered list of decoded request messages (all frames
the client sent before half-close) and returns a single
:class:`GrpcUnaryReply` (one response message + status).

Implements: `Movable`

#### `serve_client_streaming`

```mojo
def serve_client_streaming(mut self, ctx: GrpcCallContext, messages: List[List[UInt8]]) -> GrpcUnaryReply
```

### `GrpcBidiStreaming`

```mojo
undefined
```

Bidirectional-streaming gRPC handler.

Receives the ordered list of decoded request messages and returns a
:class:`GrpcServerStreamReply` (ordered response messages + status).
Responses ship incrementally, one DATA frame per message.

Implements: `Movable`

#### `serve_bidi`

```mojo
def serve_bidi(mut self, ctx: GrpcCallContext, messages: List[List[UInt8]]) -> GrpcServerStreamReply
```

## Functions

### `decode_request_messages`

```mojo
def decode_request_messages(request_data: Span[UInt8], encoding: String = "", max_decompressed_bytes: Int = Int(16777216)) -> List[List[UInt8]]
```

Decode every back-to-back LPM frame into its own payload list.

Unlike :func:`flare.grpc.server.stitch_request_data` (which
concatenates all payloads into one contiguous buffer for the unary
shape), this preserves message boundaries so a client-streaming /
bidi handler sees the ordered list of request messages. Compressed
frames are decompressed per the call's ``grpc-encoding``.
