anchor.diff:      {record, Fields} = Type:record_struct(Version),
       encode_record(Value, {record, Version, Fields}).
   
  +
  +%%--------------------------------------------------------------------
  +%% @doc
  +%% Encodes given term to ejson with given structure.
  +%% @end
  +%%--------------------------------------------------------------------
  +-spec encode_record(term(), record_struct()) -> ejson() | no_return().
   encode_record(Term, Struct) ->
       encode_record(value, Term, Struct).
   
  -
  +%%--------------------------------------------------------------------
  +%% @doc
  +%% Decodes ejson to term with given structure.
  +%% @end
  +%%--------------------------------------------------------------------
  +-spec decode_record(ejson()) -> term().
   decode_record({Term}) when is_list(Term) ->
       Type = decode_record(proplists:get_value(<<?RECORD_TYPE_MARKER>>, Term), atom),
       Version = decode_record(proplists:get_value(<<?RECORD_VERSION_MARKER>>, Term), integer),
  
positive.code: %%% Internal functions
  %%%===================================================================
  
  encode_record(value, undefined, _) ->
      null;
  encode_record(value, Term, {custom_value, {M, Encoder, _Decoder}}) ->
  
negative.code: %%% API functions
  %%%===================================================================
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Encodes given datastore document to ejson.
  %% @end
  %%--------------------------------------------------------------------
  -spec encode_record(datastore:document()) -> ejson() | no_return().
  encode_record(#document{version = undefined, value = Value}) ->
      Type = element(1, Value),
      encode_record(Value, {record, Type});
  