Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We've implemented an optimized binary format for records and arrays serialization. You can also serialize any object of memory structure easily. It is optimized for speed and used space.</p> <p>It is part of our mORMot Open Source project, works from Delphi 5 up to XE2. You do not have to use the whole ORM / Client-Server services features of the project, just the <code>SynCommons.pas</code> unit.</p> <p>You can then use our <em>SynLZ</em> real-time compression format to make the resulting content even smaller.</p> <p>See <a href="http://blog.synopse.info/post/2011/03/12/TDynArray-and-Record-compare/load/save-using-fast-RTTI" rel="nofollow">this blog article</a> and the associated source code.</p> <p>It has more features than serialization (i.e. sorting, finding, hashing, slicing, reversing...).</p> <p>It can be used with <code>TFileBufferWriter/TFileBufferReader</code> classes to create any custom format, with variable-length encoding of integers, and some other optimizations.</p> <p>For instance, we use this serialization to store the .map file of all symbols into a .mab binary format: it uses some <code>TDynArray</code> instances + <em>SynLZ</em>. For a .map text file of 4.44 MB, it creates a .mab of 378 KB. See <code>TSynMapFile.SaveToStream</code> and other.</p> <p>We use this very same format for persistence of in-memory list of objects (see <code>TSQLRestServerStaticInMemory</code> class in <code>SQLite3Commons.pas</code>). For instance, a 502 KB <code>People.json</code> content is stored into a 92 KB <code>People.data</code> binary file.</p> <p>Just a code snippet:</p> <pre><code>function TSQLRestServerStaticInMemory.SaveToBinary(Stream: TStream): integer; var W: TFileBufferWriter; MS: THeapMemoryStream; IDs: TIntegerDynArray; i, n, f: integer; begin result := 0; if (self=nil) or (Stream=nil) then exit; MS := THeapMemoryStream.Create; W := TFileBufferWriter.Create(MS); try // primitive magic and fields signature for file type identification W.Write(RawUTF8(ClassName)); W.Write(StoredClassProps.SQLTableName); n := Length(StoredClassProps.FieldsName); W.WriteRawUTF8DynArray(StoredClassProps.FieldsName,n); W.Write(pointer(StoredClassProps.FieldType),sizeof(TSQLFieldType)*n); // write IDs SetLength(IDs,Count); with fValue do for i := 0 to Count-1 do IDs[i] := TSQLRecord(List[i]).fID; W.WriteVarUInt32Array(IDs,Count,wkSorted); // efficient ID storage // write content, grouped by field (for better compression) for f := 0 to High(fStoredClassProps.Fields) do with fStoredClassProps.Fields[f]^, fValue do for i := 0 to Count-1 do GetBinary(TSQLRecord(List[i]),W); W.Flush; result := StreamSynLZ(MS,Stream,TSQLRESTSERVERSTATICINMEMORY_MAGIC); finally W.Free; MS.Free; end; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload