anchor.diff:  -ifdef(TEST).
   
   json_encode_decode_test_() -> [
  -	{"decode event", fun() ->
  -		Expected = #envelope{type = request, channel = "goober chan"},
  -		Out = decode_envelope(mochijson2:encode({struct, [
  -			{<<"mType">>, <<"req">>}, {<<"channel">>, <<"goober chan">>}]})),
  +	{"json_to_envelope, simple success", fun() ->
  +		Expected = #envelope{type = request, channel = <<"goober chan">>},
  +		Out = json_to_envelope({struct, [{<<"type">>, <<"request">>},
  +			{<<"channel">>, <<"goober chan">>}]}),
   		?assertEqual(Expected, Out)
  +	end},
  +
  +	{"json_to_envelope, explosion", fun() ->
  +		Json = <<"\"not valid json\"">>,
  +		?assertError({case_clause, _}, json_to_envelope(Json))
  +	end},
  +
  +	{"envelope_to_json, simple success", fun() ->
  +		Expected = lists:sort([{<<"id">>, <<"an id">>},
  +			{<<"channel">>, <<"goober chan">>}, {<<"type">>, request},
  +			{<<"contents">>, <<"this is a string">>}]),
  +		Input = #envelope{type = request, channel = <<"goober chan">>, 
  +			id = <<"an id">>, contents = <<"this is a string">>},
  +		{struct, Out} = envelope_to_json(Input),
  +		Out0 = lists:sort(Out),
  +		?assertEqual(Expected, Out0)
   	end}
   	].
   -endif.
  
positive.code: -type(message_id() :: 'undefined' | binary()).
  -type(json() :: integer() | float() | binary() | {struct, [{binary(), json()}]} | [json()]).
  -record(envelope, {type :: message_type(), id :: message_id(),
  	channel :: binary(), content :: json()}).
  
  %% ------------------------------------------------------------------
  %% API Function Exports
  
negative.code: %% ------------------------------------------------------------------
  
  service_request(Binary, State) when is_binary(Binary) ->
  	Json = mochijson2:decode(Binary),
  	Rec = json_to_envelope(Json),
  	service_request(Rec, State);
  
  service_request(#envelope{channel = "control"} = Envelope, State) ->
  