Table of Contents

Class SerializationHintsAttribute

Namespace
System.Runtime.Serialization
Assembly
nanoFramework.Serialization.Helper.dll

Provides hints to the binary serializer on how to improve serialization and decrease the size of the serialialized representation.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Property|AttributeTargets.Field, Inherited = true)]
public class SerializationHintsAttribute : Attribute, _Attribute
Inheritance
SerializationHintsAttribute
Implements
Inherited Members
Extension Methods

Constructors

SerializationHintsAttribute()

public SerializationHintsAttribute()

Fields

ArraySize

Specifies the size of an array.

public int ArraySize

Field Value

int

Remarks

If an array's size is fixed and known, it can be stated using the ArraySize option. A value of -1 can be used if the class being serialized only has one array of simple data types and no other fields.

BitPacked

Specifies the number of bits in which the current object is bit-packed.

public int BitPacked

Field Value

int

Remarks

This can be applied only to ordinal types, DateTime and TimeSpan. This indicates how many bits should be kept for an ordinal type. If BitPacked is 0, a data type's default size is applied (for example, 2 bytes for an short and 1 byte for the byte type). Decorating a bool field with BitPacked attribute set to 1, only one bit - which is enough to represent true or false - is kept for the bool value.

Options

Serialization options for the current object.

public SerializationOptions Options

Field Value

SerializationOptions

RangeBias

Specifies the range bias adjustment for a particular serialized value.

public long RangeBias

Field Value

long

Remarks

This can be applied to ordinal types, DateTime and TimeSpan. It can't be applied to bool type objects. With the exception of bool, all ordinal types can use RangeBias. It allows to store a value using fewer bits. Before saving the ordinal value, the range bias value is subtracted from it. For instance, a 16 bit data type has to used to store values that range between 1000 and 1500. The required bits can be decreased from 16 to 6 if the range is known in advance. When RangeBias is set to 1000, the number 1000 is subtracted from the original value before it's serialized.

Scale

Specifies the range bias adjustment for a particular serialized value.

public ulong Scale

Field Value

ulong

Remarks

This can be applied to ordinal types, DateTime and TimeSpan. It can't be applied to bool type objects. When serializing a value, Scale helps save storage bits similar to RangeBias. The value to be serialized is divided by Scale. Defining a Scale of two, the range of values can be cut in half if a field only contains odd or even values. It's also possible to combine RangeBias with Scale. However, the order of operations must be taken into account here. The value will be first subtracted by RangeBias and then divided by Scale.