MORMOT的数据序列
MORMOT的数据序列
mormot服务器回复客户端通过Ctxt.OutContent属性。
此属性的类型是:SockString。 // property OutContent: SockString read fOutContent write fOutContent ;
继续跟代码,发现SockString是RawByteString类型。
type
{$ifdef UNICODE}
/// define the fastest Unicode string type of the compiler
SynUnicode = UnicodeString;
/// define a raw 8-bit storage string type, used for data buffer management
SockString = type RawByteString;
{$else}
/// define the fastest 16-bit Unicode string type of the compiler
SynUnicode = WideString;
{$ifdef HASCODEPAGE} // FPC may expect a CP, e.g. to compare two string constants
SockString = type RawByteString;
{$else}
/// define a 8-bit raw storage string type, used for data buffer management
SockString = type AnsiString;
{$endif}
{$endif}
继续跟代码,发现RawByteString是AnsiString类型。从下面的代码可以看出,
RawByteString是跨平台的,针对不同的平台有不同的编译开关。这也是为什么要封装一个RawByteString类型。
{$IFDEF NEXTGEN}
UTF8String = type _AnsiString();
RawByteString = type _AnsiString($ffff);
{$NODEFINE UTF8String}
{$NODEFINE RawByteString}
{$ELSEIF Defined(LINUX64) or Defined(OSX64)}
UTF8String = type AnsiString();
RawByteString = type AnsiString($ffff);
{$NODEFINE UTF8String}
{$NODEFINE RawByteString}
{$ELSE}
UTF8String = type AnsiString();
RawByteString = type AnsiString($ffff);
{$ENDIF}
mormot在SynCommons.pas单元定义了一些RawByteString和其它数据类型相互转换的公共函数,一起来看看。
stream和RawByteString相互转换函数:
function StreamToRawByteString(aStream: TStream): RawByteString;
var current, size: Int64;
begin
result := '';
if aStream=nil then
exit;
current := aStream.Position;
if (current=0) and aStream.InheritsFrom(TRawByteStringStream) then begin
result := TRawByteStringStream(aStream).DataString; // fast COW
exit;
end;
size := aStream.Size-current;
if (size=0) or (size>maxInt) then
exit;
SetLength(result,size);
aStream.Read(pointer(result)^,size);
aStream.Position := current;
end;
function RawByteStringToStream(const aString: RawByteString): TStream;
begin
result := TRawByteStringStream.Create(aString);
end;
bytes和RawByteString相互转换函数:
procedure BytesToRawByteString(const bytes: TBytes; out buf: RawByteString);
begin
SetString(buf,PAnsiChar(pointer(bytes)),Length(bytes));
end;
procedure RawByteStringToBytes(const buf: RawByteString; out bytes: TBytes);
var L: Integer;
begin
L := Length(buf);
if L<>0 then begin
SetLength(bytes,L);
MoveFast(pointer(buf)^,pointer(bytes)^,L);
end;
end;
RawByteString和Variant相互转换函数:
procedure RawByteStringToVariant(const Data: RawByteString; var Value: variant);
begin
with TVarData(Value) do begin
{$ifndef FPC}if VType and VTYPE_STATIC<>0 then{$endif}
VarClear(Value);
if Data='' then
VType := varNull else begin
VType := varString;
VAny := nil; // avoid GPF below when assigning a string variable to VAny
RawByteString(VAny) := Data;
end;
end;
end;
procedure VariantToRawByteString(const Value: variant; var Dest: RawByteString);
begin
case TVarData(Value).VType of
varEmpty, varNull:
Dest := '';
varString:
Dest := RawByteString(TVarData(Value).VAny);
else // not from RawByteStringToVariant() -> conversion to string
Dest := {$ifdef UNICODE}RawByteString{$else}string{$endif}(Value);
end;
end;
stream,ansistring,variant基本上代表了常用的数据格式。
MORMOT的数据序列的更多相关文章
- 常用sql语句总结(二)(更新数据,序列,创建数据表,约束,注释)
常用sql语句总结(二)(更新数据,序列,创建数据表,约束,注释) 一. 增 INSERT INTO 数据表(字段,字段,-) VALUES(值,值-); INSERT INTO emp(empno, ...
- 论DELPHI三层的数据序列格式的变化
论DELPHI三层的数据序列格式的变化 要窥三层的数据序列格式,我们可以通过观察DELPHI官方的客户端内存表. 早先流行的是TClientDataSet,它的Data和Delta属性的数据类型都是: ...
- msgpack的数据序列和还原
msgpack的数据序列和还原 msgpack不仅可以序列一些常规的数据类型的数据,比如:string.datetime.integer...... 还能序列olevariant.stream 这就非 ...
- ARIMA模型——本质上是error和t-?时刻数据差分的线性模型!!!如果数据序列是非平稳的,并存在一定的增长或下降趋势,则需要对数据进行差分处理!ARIMA(p,d,q)称为差分自回归移动平均模型,AR是自回归, p为自回归项; MA为移动平均,q为移动平均项数,d为时间序列成为平稳时所做的差分次数
https://www.cnblogs.com/bradleon/p/6827109.html 文章里写得非常好,需详细看.尤其是arima的举例! 可以看到:ARIMA本质上是error和t-?时刻 ...
- DATASNAP数据序列之FIREDAC的TFDJSONDataSets
DATASNAP数据序列之FIREDAC的TFDJSONDataSets DELPHI XE5开始增加了新的数据引擎——FIREDAC,它是跨平台的数据引擎,WINDOWS.LINUX.MAC.APP ...
- 优秀的数据序列和还原类----TSimpleMsgPack
优秀的数据序列和还原类----TSimpleMsgPack TSimpleMsgPack是D10天地弦的作品. 优点:至简,就一个单元文件实现,不需要引用其他单元. 缺点:不是标准的MSGPACK实现 ...
- cross socket和msgpack的数据序列和还原
cross socket和msgpack的数据序列和还原 procedure TForm1.Button1Click(Sender: TObject); begin var pack: TSimple ...
- python之数据序列转换并同时计算数据
问题 你需要在数据序列上执行聚集函数(比如 sum() , min() , max() ), 但是首先你需要先转换或者过滤数据 解决方案 一个非常优雅的方式去结合数据计算与转换就是使用一个生成器表达式 ...
- 【网络编程】TCPIP_3_地址族与数据序列
目录 前言 3. 地址族与数据序列 3.1 分配给套接字的 IP 地址与端口号 3.2 参数 IP 地址 3.2.1 IPV4 地址的结构体 3.2.2 地址族(Address Family) 3.2 ...
随机推荐
- linux如何查看端口被哪个进程占用?
参考:https://jingyan.baidu.com/article/546ae1853947b71149f28cb7.html 1.lsof -i:端口号 2.netstat -tunlp|gr ...
- Java中包的介绍
包的介绍: 未命名包 命名包 可以避免类名重复 为了更好地组织类,Java 提供了包机制,用于区别类名的命名空间. 包的作用 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用. 2. ...
- TinyHttpd代码解析
十一假期,闲来无事.看了几个C语言开源代码.http://www.cnblogs.com/TinyHttpd 这里本来想解析一下TinyHttpd的代码,但是在网上一搜,发现前辈们已经做的很好了.这里 ...
- 无效GRANT语句导致主从同步断开
最近遇到一个主从同步断开的案例,是由于在执行GRANT语句时,授权对象给错了,也就可以理解为无效的GRANT语句,我们收到slave库同步断开的报警信息,然后去找问题,发现binlog有报错,报错提示 ...
- tomcat错误信息解决方案【严重:StandardServer.await: create[8005]】
错误信息: 严重: StandardServer.await: create[8005]: java.net.BindException: Address already in use: JVM ...
- java基础学习总结——GUI编程(二)
一.事件监听
- intelliJ 打包jar的多种方式
这里总结出用IntelliJ IDEA打包jar包的多种方式,以后的项目打包Jar包可以参考如下形式: 用IDEA自带的打包形式 用Maven插件maven-shade-plugin打包 用Maven ...
- 样式加载不出来,浏览器控制台报错:Resource interpreted as Stylesheet but transferred with MIME type text/html
写登录的时候出现的问题,样式时好时坏,浏览器控制台看到的信息是: Uncaught SyntaxError: Unexpected token <Resource interpreted as ...
- php调用python脚本
主要参考两篇文章 PHP中的换行详解 利用PHP调试Python Python小窥 - 写给Python的入门者 这两篇文章结合起来进行测试,主要过程如下 cd /var/www/html mkdir ...
- html (第四本书第1~3章参考)
前三章都不会的话 呵呵……