anchor.diff:  %%% Internal functions
   %%%===================================================================
   
  +%%--------------------------------------------------------------------
  +%% @doc
  +%% Encodes given term to ejson with given structure. Given term can be either
  +%% encoded as json key or value. This distinction is required since JSON disallows keys with types other then string.
  +%% @end
  +%%--------------------------------------------------------------------
  +-spec encode_record(key | value, term(), record_struct()) -> ejson() | no_return().
   encode_record(value, undefined, _) ->
       null;
   encode_record(value, Term, {custom_value, {M, Encoder, _Decoder}}) ->
  
positive.code: %%% API functions
  %%%===================================================================
  
  encode_record(#document{version = undefined, value = Value}) ->
      Type = element(1, Value),
      encode_record(Value, {record, Type});
  
negative.code:     error({invalid_term_structure, Context, Term, Type}).
  
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Decodes ejson to term with given structure.
  %% @end
  %%--------------------------------------------------------------------
  -spec decode_record(ejson(), record_struct()) -> term().
  decode_record(null, _) ->
      undefined;
  decode_record(Term, {custom_value, {M, _Encoder, Decoder}}) ->
  