serialize(message:to:partial:)
Serialize a single size-delimited message to the given stream. Delimited format allows a single file or stream to contain multiple messages, whereas normally writing multiple non-delimited messages to the same stream would cause them to be merged. A delimited message is a varint encoding the message size followed by a message of exactly that size.
static func serialize(message: any Message, to stream: OutputStream, partial: Bool = false) throws
Parameters
- message
The message to be written.
- to
The
OutputStream
to write the message to. The stream is is assumed to be ready to be written to.- partial
If
false
(the default), this method will checkisInitialized
before encoding to verify that all required fields are present. If any are missing, this method throwsBinaryDelimited/Error/missingRequiredFields
.
Throws
Error
if encoding fails or some writing errors occur; or the underlying OutputStream.streamError
for a stream error.