Codec Operations pattern

A codec operation uses minimal markup to send reply sets comprising flag fields.

In the example in Table 1, svc_expr is used to code particular combinations of sensors into motor actions.

Table 1. Codec operation with no alternatives
Example Description
<mix name="Mix">
	<service name="Expr"
	  provision="expr"/>

	<request name="Right"
	  service="Expr"
	  fields="RIGHT_BRIGHT NO_BUMP">
	  <reply name="Ok"
	    fields="FORWARD RIGHT"/>
	</request>
</mix>
Neither the service nor the operation needs a property if:
  • The request has only one reply set
  • The fields are all flag fields

In the example in Table 2, svc_expr is used to select one of two output sets at random.

Table 2. Codec operation with alternatives
Example Description
<mix name="Mix">
  <service name="Bartender"
    provision="expr"/>
  ...
  <request name="DoYouDrive" 
    service="Bartender" 
    fields="BEER">
    <prop name="expr.src" 
      content-type="text/x-erlang"><![CDATA[
  case rand:uniform() > 0.5 of
    true ->
          "No";
    false ->
  	 "Yes"
  end.
    ]]></prop>
    <reply name="Yes" 
      fields="NONALCOHOLIC"/>
    <reply name="No" 
      fields="ALCOHOLIC"/>
  </request>
</mix>
The service does not need a property.

The expr.src property of the request/reply selects one of the two replies at random.

It is always the last expression of a script that selects the reply set.

In this case there is only one expression, which thus counts as the last expression.

Note: Do not manually type the <![CDATA...]]> delimiters. The Editor automatically renders text content as XML CDATA sections.