BinarySerialize
BinarySerialize[expr]
gives a binary representation of any expression expr as a ByteArray object.
Details and Options
- BinarySerialize has the following options:
-
Method Automatic details of serialization methods to use PerformanceGoal Automatic aspects of performance to try to optimize - Possible settings for PerformanceGoal include:
-
"Speed" optimize for serialization and deserialization speed "Size" optimize for smallness of serialized output Automatic automatically pick serialization strategy - Possible settings for Method include:
-
{typespec1enc1,…} specify encodings for particular types Automatic pick encodings automatically based on data - Possible forms for the typespeci include:
-
"PackedArrayIntegerType" integer packed arrays "PackedArrayRealType" real-valued packed arrays "PackedArrayComplexType" complex-valued packed arrays - Possible settings for "PackedArrayIntegerType" include "Integer8", "Integer16", "Integer32" and "Integer64" (64-bit systems only).
- Possible settings for "PackedArrayRealType" include "Real32" and "Real64".
- Possible settings for "PackedArrayComplexType" include "Complex64" and "Complex128".
- The default for the enci encoding specifications is Automatic, in which case BinarySerialize will use a type that fits the data it is given.
- BinarySerialize uses the WXF format.
- BinaryDeserialize is the inverse of BinarySerialize.
Examples
open allclose allBasic Examples (2)
Scope (7)
Apply BinarySerialize to symbolic expressions:
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 using machine floats, trading precision for a smaller output:
PerformanceGoal (1)
Serialize a Dataset:
Serialize the same Dataset with PerformanceGoal set to "Size":
Applications (1)
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:
Text
Wolfram Research (2017), BinarySerialize, Wolfram Language function, https://reference.wolfram.com/language/ref/BinarySerialize.html (updated 2018).
CMS
Wolfram Language. 2017. "BinarySerialize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2018. https://reference.wolfram.com/language/ref/BinarySerialize.html.
APA
Wolfram Language. (2017). BinarySerialize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BinarySerialize.html