|
| 1 | +// |
| 2 | +// Copyright (c) .NET Foundation and Contributors |
| 3 | +// Portions Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +// See LICENSE file in the project root for full license information. |
| 5 | +// |
| 6 | + |
| 7 | +namespace System.Runtime.Serialization |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Provides hints to the binary serializer on how to improve serialization and decrease the size of the serialialized representation. |
| 11 | + /// </summary> |
| 12 | + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Class, Inherited = true)] |
| 13 | + public class SerializationHintsAttribute : Attribute |
| 14 | + { |
| 15 | + // |
| 16 | + // Keep in sync with Microsoft.SPOT.Debugger.SerializationHintsAttribute!!!! |
| 17 | + // |
| 18 | + |
| 19 | +#pragma warning disable S1104 // intended use in .NET nanoFramework for native usage |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Serialization options for the current object. |
| 23 | + /// </summary> |
| 24 | + public SerializationOptions Options; |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// Specifies the size of an array. |
| 28 | + /// </summary> |
| 29 | + /// <remarks> |
| 30 | + /// If an array's size is fixed and known, it can be stated using the <see cref="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. |
| 31 | + /// </remarks> |
| 32 | + //// -1 == extend to the end of the stream. |
| 33 | + public int ArraySize; |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Specifies the number of bits in which the current object is bit-packed. |
| 37 | + /// </summary> |
| 38 | + /// <remarks> |
| 39 | + /// This can be applied only to ordinal types, <see cref="DateTime"/> and <see cref="TimeSpan"/>. |
| 40 | + /// This indicates how many bits should be kept for an ordinal type. If <see cref="BitPacked"/> is 0, a data type's default size is applied (for example, 2 bytes for an <see cref="short"/> and 1 byte for the <see cref="byte"/> type). |
| 41 | + /// Decorating a <see cref="bool"/> field with <see cref="BitPacked"/> attribute set to 1, only one bit - which is enough to represent true or false - is kept for the <see cref="bool"/> value. |
| 42 | + /// </remarks> |
| 43 | + //// bits count |
| 44 | + public int BitPacked; |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Specifies the range bias adjustment for a particular serialized value. |
| 48 | + /// </summary> |
| 49 | + /// <remarks> |
| 50 | + /// This can be applied to ordinal types, <see cref="DateTime"/> and <see cref="TimeSpan"/>. |
| 51 | + /// It can't be applied to <see cref="bool"/> type objects. |
| 52 | + /// With the exception of <see cref="bool"/>, all ordinal types can use <see cref="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 <see cref="RangeBias"/> is set to 1000, the number 1000 is subtracted from the original value before it's serialized. |
| 53 | + /// </remarks> |
| 54 | + public long RangeBias; |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Specifies the range bias adjustment for a particular serialized value. |
| 58 | + /// </summary> |
| 59 | + /// <remarks> |
| 60 | + /// This can be applied to ordinal types, <see cref="DateTime"/> and <see cref="TimeSpan"/>. |
| 61 | + /// It can't be applied to <see cref="bool"/> type objects. |
| 62 | + /// When serializing a value, <see cref="Scale"/> helps save storage bits similar to <see cref="RangeBias"/>. The value to be serialized is divided by <see cref="Scale"/>. Defining a <see cref="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 <see cref="RangeBias"/> with <see cref="Scale"/>. However, the order of operations must be taken into account here. The value will be first subtracted by <see cref="RangeBias"/> and then divided by <see cref="Scale"/>. |
| 63 | + /// </remarks> |
| 64 | + //// this will be ticks for DateTime objects |
| 65 | + public ulong Scale; |
| 66 | + |
| 67 | +#pragma warning restore S1104 // Fields should not have public accessibility |
| 68 | + |
| 69 | + } |
| 70 | +} |
0 commit comments