BinarySerialize

BinarySerialize[expr]

gives a binary representation of any expression expr as a ByteArray object.

Details and Options

Examples

open allclose all

Basic Examples  (2)

Serialize an expression:

Serialize a graphic:

Convert the serialized form back to an expression:

Scope  (7)

Apply BinarySerialize to symbolic expressions:

Serialize an image:

Note that the size of the serialized form roughly equals the byte count of the expression:

BinarySerialize efficiently stores machine integers:

BinarySerialize efficiently stores machine reals:

Compare with an arbitrary-precision real:

BinarySerialize efficiently stores strings:

BinarySerialize supports ByteArray:

BinarySerialize supports packed arrays:

Options  (4)

Method  (3)

Create a packed array of integer values:

By default, BinarySerialize uses the smallest integer type that fits the data:

Serialize the packed array using a bigger integer type:

Create a packed array of real values:

Serialize the array:

Serialize the array using machine floats, trading precision for a smaller output:

Create a packed array of complex values:

Serialize the array:

Serialize the array using lower precision:

PerformanceGoal  (1)

Serialize a Dataset:

Serialize the same Dataset with PerformanceGoal set to "Size":

Both forms represent the same expression:

Applications  (1)

Serialize a trained neural network:

Create a new file:

Open an output binary stream:

Write the serialized expression to the file:

Read the data from the file:

Plot the prediction of the net as a function of the input:

Properties & Relations  (4)

Using PerformanceGoal->"Speed" is faster but produces larger outputs:

Using PerformanceGoal->"Size" is slower but produces smaller outputs:

BinarySerialize encodes strings as UTF-8:

BinaryDeserialize is the inverse of BinarySerialize:

DumpSave stores definitions attached to a symbol in a file:

Using Get will return Null but restore the value of f:

BinarySerialize only stores the input expression, which can be restored by BinaryDeserialize:

Possible Issues  (2)

From small expressions, PerformanceGoal->"Size" may not produce smaller outputs:

The Method parameter "PackedArrayIntegerType" must be chosen consistently with the data:

These values require 32-bit integers:

A setting of Automatic will always use a size that fits the data:

Introduced in 2017
 (11.1)
 |
Updated in 2018
 (11.3)