作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 erlang 的新手,正在学习 erlang-mysql-driver .任何人都可以帮助我理解为什么在解析函数“get_lcb”中的二进制文件时这里的字节序很少吗?
以下是mysql_conn.erl中的代码
%%--------------------------------------------------------------------
%% Function: get_query_response(LogFun, RecvPid)
%% LogFun = undefined | function() with arity 3
%% RecvPid = pid(), mysql_recv process
%% Version = integer(), Representing MySQL version used
%% Descrip.: Wait for frames until we have a complete query response.
%% Returns : {data, #mysql_result}
%% {updated, #mysql_result}
%% {error, #mysql_result}
%% FieldInfo = list() of term()
%% Rows = list() of [string()]
%% AffectedRows = int()
%% Reason = term()
%%--------------------------------------------------------------------
get_query_response(LogFun, RecvPid, Version) ->
case do_recv(LogFun, RecvPid, undefined) of
{ok, Packet, _} ->
{Fieldcount, Rest} = get_lcb(Packet),
case Fieldcount of
0 ->
%% No Tabular data
<<AffectedRows:8, Rest2/binary>> = Rest,
io:format("Rest2=~p~n", [Rest2]),
{InsertId, _} = get_lcb(Rest2),
io:format("InsertId=~p~n", [InsertId]),
{updated, #mysql_result{affectedrows=AffectedRows, insertid=InsertId}};
255 ->
<<_Code:16/little, Message/binary>> = Rest,
{error, #mysql_result{error=Message}};
_ ->
%% Tabular data received
case get_fields(LogFun, RecvPid, [], Version) of
{ok, Fields} ->
case get_rows(Fields, LogFun, RecvPid, []) of
{ok, Rows} ->
{data, #mysql_result{fieldinfo=Fields,
rows=Rows}};
{error, Reason} ->
{error, #mysql_result{error=Reason}}
end;
{error, Reason} ->
{error, #mysql_result{error=Reason}}
end
end;
{error, Reason} ->
{error, #mysql_result{error=Reason}}
end.
get_lcb(<<251:8, Rest/binary>>) ->
{null, Rest};
get_lcb(<<252:8, Value:16/little, Rest/binary>>) ->
io:format("Value=~p~n",[Value]),
io:format("Rest=~p~n",[Rest]),
{Value, Rest};
get_lcb(<<253:8, Value:24/little, Rest/binary>>) ->
{Value, Rest};
get_lcb(<<254:8, Value:32/little, Rest/binary>>) ->
{Value, Rest};
get_lcb(<<Value:8, Rest/binary>>) when Value < 251 ->
{Value, Rest};
get_lcb(<<255:8, Rest/binary>>) ->
{255, Rest}.
%%--------------------------------------------------------------------
%% Function: do_recv(LogFun, RecvPid, SeqNum)
%% LogFun = undefined | function() with arity 3
%% RecvPid = pid(), mysql_recv process
%% SeqNum = undefined | integer()
%% Descrip.: Wait for a frame decoded and sent to us by RecvPid.
%% Either wait for a specific frame if SeqNum is an integer,
%% or just any frame if SeqNum is undefined.
%% Returns : {ok, Packet, Num} |
%% {error, Reason}
%% Reason = term()
%%
%% Note : Only to be used externally by the 'mysql_auth' module.
%%--------------------------------------------------------------------
do_recv(LogFun, RecvPid, SeqNum) when is_function(LogFun);
LogFun == undefined,
SeqNum == undefined ->
receive
{mysql_recv, RecvPid, data, Packet, Num} ->
{ok, Packet, Num};
{mysql_recv, RecvPid, closed, _E} ->
{error, "mysql_recv: socket was closed"}
end;
do_recv(LogFun, RecvPid, SeqNum) when is_function(LogFun);
LogFun == undefined,
is_integer(SeqNum) ->
ResponseNum = SeqNum + 1,
receive
{mysql_recv, RecvPid, data, Packet, ResponseNum} ->
{ok, Packet, ResponseNum};
{mysql_recv, RecvPid, closed, _E} ->
{error, "mysql_recv: socket was closed"}
end.
最佳答案
我想你的意思是这些行:Value:16/little
、Value:24/little
等等...?好吧,这是因为 MySQL 服务器将始终使用小端值填充响应数据包的这些部分 - 但默认情况下,Erlang 机器将以 CPU 原生的任何字节序运行。
关于mysql - erlang-mysql-driver 源代码,为什么小字节序来获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12259970/
序 大家好呀,我是summo,这次来写写我在上班空闲(摸鱼)的时候做的一个小网站的事。去年阿里云不是推出了个活动嘛,2核2G的云服务器一年只要99块钱,懂行的人应该知道这个价格在业界已经是非常良心了
我尝试根据给定的级别顺序(BFS 顺序)构造 BST。我知道这是可能的,但我不知道我该怎么写。问题是我必须使用 BFS 序列。所以,我不能在这里使用递归,我必须迭代地编写我的程序......我发现这有
我是一名优秀的程序员,十分优秀!