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 ...
随机推荐
- ApiCloud利用NVTabBar模块快速搭建起APP的框架
废话不说,直接上代码 模块地址:https://docs.apicloud.com/Client-API/Nav-Menu/NVTabBar 代码实例: <!doctype html> & ...
- (转载)mysql:“Access denied for user 'root'@'localhost'”
原文地址:http://www.linuxidc.com/Linux/2007-05/4338.htm # /etc/init.d/mysql stop# mysqld_safe --user=mys ...
- wpf image 指定Stretch="None" 不拉伸的时候,仍然拉伸的解决办法
I think TI82 is right on this issue. The image become bigger than you expect because its dpi doesn't ...
- 入门NodeJS
入门NodeJS https://www.cnblogs.com/dotnetcrazy/p/10118756.html NodeJS 1.环境配置 之前讲ES6的时候有提过一部分Node的知识,简单 ...
- 如何快速的打开当前文件夹的dos命令窗口
一.常规方法: 1.使用 “window + R” 组合键,输入cmd回车.如下图所示: 2.如果你要定位到指定的文件夹,那么需要用cd等命令来处理.如下图所示: 二.快速方法: 按住“shift”键 ...
- Codeforces 623B Array GCD
Array GCD 最后的序列里肯定有a[1], a[1]-1, a[1]+1, a[n], a[n]-1, a[n]+1中的一个,枚举质因子, dp去check #include<bits/s ...
- 027 Spark的优化总结
1.四个部分
- java学习之租车系统
背景:有三种类型的车供给用户来租用 要求:控制台用户交互界面,根据用户需求输出租车价格,结果如下: 创建租车类主要设计过程: 创建租车类 创建Car父类,包含四种属性成员,重写构造方法 创建三种 ...
- MySQL数据库引擎详解
作为Java程序员,MySQL数据库大家平时应该都没少使用吧,对MySQL数据库的引擎应该也有所了解,这篇文章就让我详细的说说MySQL数据库的Innodb和MyIASM两种引擎以及其索引结构.也来巩 ...
- [教程] Spring+Mybatis环境配置多数据源
一.简要概述 在做项目的时候遇到需要从两个数据源获取数据,项目使用的Spring + Mybatis环境,看到网上有一些关于多数据源的配置,自己也整理学习一下,然后自动切换实现从不同的数据源获取数据功 ...