TsgcWebTransportStream › Methods › ReceiveData

ReceiveData Method

Pushes inbound application bytes into the stream, raising OnData. The transport calls this; applications handle the event instead.

Syntax

procedure ReceiveData(const aData: TBytes);

Parameters

NameTypeDescription
aDataconst TBytesRaw application bytes, passed to OnData unchanged. The caller must have stripped the WebTransport stream header first: nothing here parses or validates the bytes.

Remarks

This is a transport integration point. ReceiveData is the inbound mirror of WriteData: it raises OnData with the bytes you give it, and does nothing else. No header parsing, no buffering, no validation. Application code should handle OnData rather than call this.

It expects application bytes only. The name says "receive", but the method does not read from anywhere. It is a push: the transport, having read a QUIC stream and worked out which WebTransport stream the bytes belong to, hands them over here. Passing a raw QUIC read that still has its 0x54 or 0x41 header on the front delivers that header to your handler as if it were payload.

The HTTP/3 client and server call it on two paths, both after the demultiplexer has resolved the stream id:

There is no closed check, so ReceiveData raises OnData even on a stream that has been closed. An empty array raises OnData with an empty array; the library's own callers avoid that by testing the length first.

Calling it yourself from application code synthesises inbound data: the handler runs, but nothing came from the network. Useful for exercising a handler in a test, misleading anywhere else.

This member is currently available in the Delphi/C++Builder implementation only. The .NET class has an equivalent internal ReceiveData, which application code cannot call.

Example


// What a custom QUIC transport does once it knows which stream the bytes
// belong to. This mirrors the library's own routing in the HTTP/3 client
// and server; applications handle OnData instead.
function TMyTransport.RouteStreamData(aStreamId: Int64;
  const aData: TBytes): Boolean;
var
  oStream: TsgcWebTransportStream;
begin
  Result := False;
  if (aStreamId < 0) or (Length(aData) = 0) then
    Exit;

  // Known stream id: the header arrived earlier, so these bytes are raw
  // application data. Deliver them without parsing anything.
  oStream := FWebTransportSessions.FindStreamById(aStreamId);
  if Assigned(oStream) then
  begin
    oStream.ReceiveData(aData);   // raises OnData
    Result := True;
  end;
  // Unknown stream id: the bytes still carry the 0x54/0x41 + SessionId
  // header, so they must be parsed and routed through AddIncomingStream,
  // NOT pushed here.
end;

Back to Methods