mormot2.binary.serial.pas
mormot2.binary.serial.pas
unit mormot2.binary.serial; /// <author>cxg 2023-2-22</author> {$IFDEF fpc} {$MODE DELPHI}{$H+} {$ENDIF} interface uses mormot.core.base, mormot.core.data, SysUtils; type { TSerial } TSerial = class class function marshal<T>(const aRec: T): TBytes; class function marshal2<T>(const aRec: T): RawByteString; class function marshalbase64<T>(const aRec: T): RawUtf8; class function unmarshal<T>(const aBin: TBytes): T; class function unmarshal2<T>(const aBin: RawByteString): T; class function unmarshalbase64<T>(const aBin: PAnsiChar; const aLen: Integer): T; end; implementation { TSerial } class function TSerial.marshal2<T>(const aRec: T): RawByteString; begin result := mormot.core.data.RecordSave(aRec, TypeInfo(T)); end; class function TSerial.marshal<T>(const aRec: T): TBytes; begin result := mormot.core.data.RecordSaveBytes(aRec, TypeInfo(T)); end; class function TSerial.marshalbase64<T>(const aRec: T): RawUtf8; begin result := mormot.core.data.RecordSaveBase64(aRec, TypeInfo(T)); end; class function TSerial.unmarshal2<T>(const aBin: RawByteString): T; begin mormot.core.data.RecordLoad(result, aBin, TypeInfo(T)); end; class function TSerial.unmarshal<T>(const aBin: TBytes): T; var raw: RawByteString; len: Integer; begin len := Length(aBin); SetLength(raw, len); Move(aBin[0], PRawByteString(raw)^, len); mormot.core.data.RecordLoad(result, raw, TypeInfo(T)); end; class function TSerial.unmarshalbase64<T>(const aBin: PAnsiChar; const aLen: Integer): T; begin mormot.core.data.RecordLoadBase64(aBin, aLen, Result, TypeInfo(T)); end; end.
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/17143151.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2022-02-22 brookframework
2022-02-22 ubuntu安装delphi需要的开发包