anchor.diff:              end
       end.
   
  -% -spec value(jsone:json_value(), binary()) -> binary().
  +-spec value(jsone:json_value(), [next()], binary()) -> encode_result().
   value(null, Nexts, Buf)                         -> next(Nexts, <<Buf/binary, "null">>);
   value(false, Nexts, Buf)                        -> next(Nexts, <<Buf/binary, "false">>);
   value(true, Nexts, Buf)                         -> next(Nexts, <<Buf/binary, "true">>);
  
positive.code: -export([encode/1]).
  
  %%--------------------------------------------------------------------------------
  %% Macros
  %%--------------------------------------------------------------------------------
  -define(ERROR(Function, Args), {error, {badarg, [{?MODULE, Function, Args, [{line, ?LINE}]}]}}).
  -define(IS_REDUNDANT_UTF8(B1, B2, FirstBitN), (B1 =:= 0 andalso B2 < (1 bsl (FirstBitN + 1)))).
  -define(HEX(N, I), (binary:at(<<"0123456789abcdef">>, (N bsr (I * 4)) band 2#1111))).
  -define(UNICODE_TO_HEX(Code), ?HEX(Code, 3), ?HEX(Code, 2), ?HEX(Code, 1), ?HEX(Code, 0)).
  
  %%--------------------------------------------------------------------------------
  %% Exported Functions
  %%--------------------------------------------------------------------------------
  %% @doc JSON値をバイナリ形式にエンコードする.
  % -spec encode(jsone:json_value()) -> binary().
  encode(Value) ->
      value(Value, [], <<"">>).
  
  %%--------------------------------------------------------------------------------
  %% Internal Functions
  %%--------------------------------------------------------------------------------
  next([], Buf)             -> {ok, Buf};
  next([Next | Nexts], Buf) ->
      case Next of
  
negative.code:     <<High:10, Low:10>> = <<(Unicode - 16#10000):20>>, % 非効率
      escape_string(Str, Nexts, <<Buf/binary, $\\, $u, ?UNICODE_TO_HEX(High + 16#D800), $\\, $u, ?UNICODE_TO_HEX(Low + 16#DC00)>>).
  
  -spec array(jsone:json_array(), [next()], binary()) -> encode_result().
  array(List, Nexts, Buf) ->
      array_values(List, Nexts, <<Buf/binary, $[>>).
  
  -spec array_values(jsone:json_array(), [next()], binary()) -> encode_result().
  array_values([],       Nexts, Buf) -> next(Nexts, <<Buf/binary, $]>>);
  array_values([X | Xs], Nexts, Buf) -> value(X, [{array_values, Xs} | Nexts], Buf).
  
  -spec object(jsone:json_object(), [next()], binary()) -> encode_result().
  object({Members}, Nexts, Buf) ->
      object_members(Members, Nexts, <<Buf/binary, ${>>).
  
  -spec object_members(jsone:json_object_members(), [next()], binary()) -> encode_result().
  object_members([],                             Nexts, Buf) -> next(Nexts, <<Buf/binary, $}>>);
  object_members([{<<Key/binary>>, Value} | Xs], Nexts, Buf) -> string(Key, [{object_value, Value, Xs} | Nexts], Buf);
  object_members(Arg, Nexts, Buf)                            -> ?ERROR(object_members, [Arg, Nexts, Buf]).
  
  -spec object_value(jsone:json_value(), jsone:json_object_members(), [next()], binary()) -> encode_result().
  object_value(Value, Members, Nexts, Buf) ->
      value(Value, [{object_members, Members} | Nexts], <<Buf/binary, $:>>).
  