pub fn serialized_size<T: Serialize>(
value: &T,
version: EncodingVersion,
) -> Result<usize, SerError>Expand description
Phase 380 W3 — the EXACT serialized size of THIS message.
Two questions get asked about size and they are not the same one:
| question | asked by | this module |
|---|---|---|
| how large can this TYPE ever be? | build-time buffer sizing | max_serialized_size |
| how large is THIS message? | a publisher before publishing; a drop report | serialized_size |
The second is the only honest answer for an unbounded type, where the first
is None — a String field has no maximum, but the string in hand has a
length. It is what lets a drop report name the number that would have worked
instead of saying “raise the knob”.
Exact by construction: it runs the REAL writer with its stores disabled
(CdrWriter::measuring), so the count comes from the same code that emits
the bytes. A second walk of the schema could not see the actual string
lengths and sequence counts, and would be a second implementation to keep in
step besides.
Includes the encapsulation header, matching max_serialized_size, so the
two are directly comparable — which is the whole point at a call site
deciding whether a message fits.