[#SER_PARAMS]
= SER&lowbar;PARAMS
:mrdocs:

Formatter methods can retrieve parameters attached to a stream using the SER&lowbar;PARAMS(type) macro as long as the stream is created directly or indirectly with a parameter of that type&period; This permits making serialization depend on run&hyphen;time context in a type&hyphen;safe way&period;

== Synopsis

Declared in `&lt;serialize&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
#define SER&lowbar;PARAMS(type)

----

== Description

Example use&colon; struct BarParameter &lcub; bool fancy&semi; &period;&period;&period; &rcub;&semi; struct Bar &lcub; &period;&period;&period; &rcub;&semi; struct FooFormatter &lcub; FORMATTER&lowbar;METHODS(Bar, obj) &lcub; auto&amp; param &equals; SER&lowbar;PARAMS(BarParameter)&semi; if (param&period;fancy) &lcub; READWRITE(VARINT(obj&period;value))&semi; &rcub; else &lcub; READWRITE(obj&period;value)&semi; &rcub; &rcub; &rcub;&semi; which would then be invoked as READWRITE(BarParameter&lcub;&period;&period;&period;&rcub;(Using&lt;FooFormatter&gt;(obj&period;foo)))

parameter(obj) can be invoked anywhere in the call stack&semi; it is passed down recursively into all serialization code, until another serialization parameter overrides it&period;

Parameters will be implicitly converted where appropriate&period; This means that &quot;parent&quot; serialization code can use a parameter that derives from, or is convertible to, a &quot;child&quot; formatter&apos;s parameter type&period;

Compilation will fail in any context where serialization is invoked but no parameter of a type convertible to BarParameter is provided&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *type*
| The parameter type to retrieve from the stream&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
