leo_rpc_protocol

leo_rpc_protocol handles requested data with the protocol.

References

Description

leo_rpc_protocol handles requested data with the protocol

Function Index

handle_call/3 Receive data from client(s) after that convert from param to binary.
init/1 Initialize the protocol.
param_to_binary/3 Convert from param to binary.
result_to_binary/1 Convert from result-value to binary.
start_link/0 Start leo_rpc’s server.
start_link/1 Start leo_rpc’s server.
stop/0 Stop leo_rpc’s server.

Function Details

handle_call/3

handle_call(Socket, Data, State) -> {reply, binary()} | {close, State}

  • Socket = gen_tcp:socket()
  • Data = binary()
  • State = any()

Receive data from client(s) after that convert from param to binary

dat-format:
<< "*",
   $ModMethodBin/binary,    "/r/n",
   $ParamsLenBin:8/integer, $BodyLen:32/integer, "/r/n",
   $Param_1_Bin_Len/binary, "/r/n", "T"|"B", $Param_1_Bin/binary, "/r/n",
   ...
   $Param_N_Bin_Len/binary, "/r/n", "T"|"B", $Param_N_Bin/binary, "/r/n",
   "/r/n" >>

init/1

init(X1::term()) -> {ok, null}

Initialize the protocol

param_to_binary/3

param_to_binary(Mod, Method, Args) -> binary()

  • Mod = module()
  • Method = atom()
  • Args = [any()]

Convert from param to binary

Format:
<< "*",
   $ModMethodBin/binary,    "/r/n",
   $ParamsLenBin:8/integer, $BodyLen:32/integer, "/r/n",
   $Param_1_Bin_Len/binary, "/r/n", "T"|"B", $Param_1_Bin/binary, "/r/n",
   ...
   $Param_N_Bin_Len/binary, "/r/n", "T"|"B", $Param_N_Bin/binary, "/r/n",
   "/r/n" >>

result_to_binary/1

result_to_binary(Term) -> binary()

  • Term = any()

Convert from result-value to binary

Format:
<< "*",
   $OriginalDataTypeBin/binary, ResultBodyLen/integer, "/r/n",
   $BodyBin_1_Len/integer,      "/r/n",
   $BodyBin_1/binary,           "/r/n",
   ...
   $BodyBin_N_Len/integer,      "/r/n",
   $BodyBin_N/binary,           "/r/n",
   "/r/n"
   >>

stop/0

stop() -> ok | {error, any()}

Stop leo_rpc’s server