Binary expression tree serialization for expression trees and Bonsai trees.
Binary expression tree serialization (directly from
System.Linq.Expressions.Expression or via prior Bonsai conversion to
Alternative approaches have been considered to reduce checkpoint storage size and hence reduce I/O size, including expression tree templates. These suffer from still having pretty big reflection contexts around, though the size of the expression's serialized form tends to be smaller in raw bytes (saving balancing tokens such as
}, but also textual encoding of numeric values, and extra tokens such as
" in JSON).
To use this serializer, include
System.Linq.Expressions.Bonsai.Serialization.Binary and instantiate
ExpressionSerializer by giving it a serializer for objects (e.g. originating from
ConstantExpression.Value) and an expression tree factory used for deserialization purposes:
var serializer = new ExpressionSerializer(new BinaryObjectSerializer(), ExpressionFactory.Instance);
Note: The code can be compiled with or without the
USE_SLIMsymbol defined. This enables the library to be used with
Expressionas well as
ExpressionSlim. The OSS port of the code only includes a build with
USE_SLIMenabled at the moment; different project build flavors could be added back, or two class library projects could be made, referencing the same source files but only differing in
USE_SLIM. Note that more
#if USE_SLIMshould be added to support different namespaces for different build flavors.