anchor.diff:  %% @hidden
   code_change(_Old, State, _Extra) ->
   	{ok, State}.
  -
   
   %% @private
   encode_request(Database, Request) ->
  
positive.code: 	         end,
  	{ok, Id} = make_request(Socket, ConnState#conn_state.database, UpdReq), %TODO cursor?
  	inet:setopts(Socket, [{active, once}]),
  	true = ets:insert_new(Ets, {Id, From}),
  	{noreply, State};
  handle_call({request, Request}, _, State = #state{socket = Socket, conn_state = ConnState}) -> % ordinary requests
  	{ok, _} = make_request(Socket, ConnState#conn_state.database, Request),
  	{reply, ok, State};
  handle_call({stop, _}, _From, State) -> % stop request
  
negative.code: 	when is_record(Request, insert); is_record(Request, update); is_record(Request, delete) -> % write unsafe requests
  	{ok, _} = make_request(Socket, ConnState#conn_state.database, Request),
  	{reply, ok, State};
  handle_call(Request, From, State = #state{socket = Socket, conn_state = ConnState#conn_state{write_mode = SafeMode}, ets = Ets})
  	when is_record(Request, insert); is_record(Request, update); is_record(Request, delete) -> % write safe requests
  	Params = case SafeMode of safe -> {}; {safe, Param} -> Param end,
  
  	{ok, _} = make_request(Socket, ConnState#conn_state.database, Request), % ordinary write request
  
  	RespFun = fun({0, [Ack | _]}) ->
  		case bson:lookup(err, Ack, undefined) of
  			undefined -> gen_server:reply(From, ok);
  			String ->
  				case bson:at(code, Ack) of
  					10058 -> gen_server:reply(From, {error, {not_master, 10058}});
  					Code -> gen_server:reply(From, {error, {write_failure, Code, String}})
  				end
  		end
  	end,
  	{ok, Id} = make_request(Socket, ConnState#conn_state.database, #'query'{ % check-write read request
  		batchsize = -1,
  		collection = '$cmd',
  		selector = bson:append({getlasterror, 1}, Params)
  	}),
  	true = ets:insert_new(Ets, {Id, RespFun}),  % save function, which will be called on response
  	{reply, ok, State};
  handle_call(Request, From, State = #state{socket = Socket, conn_state = ConnState, ets = Ets, conn_state = CS}) % read requests
  	when is_record(Request, 'query'); is_record(Request, getmore) ->
  