| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using ZeroC.Slice; |
| | | 4 | | |
| | | 5 | | namespace IceRpc.Slice; |
| | | 6 | | |
| | | 7 | | /// <summary>Default implementation of <see cref="ISliceFeature" />.</summary> |
| | | 8 | | public sealed class SliceFeature : ISliceFeature |
| | | 9 | | { |
| | | 10 | | /// <summary>Gets a <see cref="ISliceFeature" /> with default values for all properties.</summary> |
| | 369 | 11 | | public static ISliceFeature Default { get; } = new DefaultSliceFeature(); |
| | | 12 | | |
| | | 13 | | /// <inheritdoc/> |
| | 1 | 14 | | public IActivator? Activator { get; } |
| | | 15 | | |
| | | 16 | | /// <inheritdoc/> |
| | 1 | 17 | | public IProxy? BaseProxy { get; } |
| | | 18 | | |
| | | 19 | | /// <inheritdoc/> |
| | 0 | 20 | | public SliceEncodeOptions? EncodeOptions { get; } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc/> |
| | 1 | 23 | | public int MaxCollectionAllocation { get; } |
| | | 24 | | |
| | | 25 | | /// <summary>Gets the maximum depth when decoding a class recursively.</summary> |
| | | 26 | | /// <value>The maximum depth. Defaults to <c>100</c>.</value> |
| | 1 | 27 | | public int MaxDepth { get; } |
| | | 28 | | |
| | | 29 | | /// <summary>Gets the maximum size of a Slice payload segment, in bytes. A Slice payload segment corresponds to the |
| | | 30 | | /// encoded arguments of an operation, the encoded return values of an operation, or a portion of a stream of |
| | | 31 | | /// variable-size elements.</summary> |
| | | 32 | | /// <value>The maximum segment size. Defaults to <c>1</c> MB.</value> |
| | 1 | 33 | | public int MaxSegmentSize { get; } |
| | | 34 | | |
| | | 35 | | /// <summary>Constructs a Slice feature.</summary> |
| | | 36 | | /// <param name="activator">The activator.</param> |
| | | 37 | | /// <param name="encodeOptions">The encode options.</param> |
| | | 38 | | /// <param name="maxCollectionAllocation">The maximum collection allocation. Use <c>-1</c> to get the default value: |
| | | 39 | | /// 8 times <paramref name="maxSegmentSize" /> if set, otherwise the value provided by <paramref |
| | | 40 | | /// name="defaultFeature" />.</param> |
| | | 41 | | /// <param name="maxDepth">The maximum depth. Use <c>-1</c> to get the default value.</param> |
| | | 42 | | /// <param name="maxSegmentSize">The maximum segment size. Use <c>-1</c> to get the default value.</param> |
| | | 43 | | /// <param name="baseProxy">The base proxy, used when decoding service addresses into proxies.</param> |
| | | 44 | | /// <param name="defaultFeature">A feature that provides default values for all parameters. <see langword="null" /> |
| | | 45 | | /// is equivalent to <see cref="Default" />.</param> |
| | 1 | 46 | | public SliceFeature( |
| | 1 | 47 | | IActivator? activator = null, |
| | 1 | 48 | | SliceEncodeOptions? encodeOptions = null, |
| | 1 | 49 | | int maxCollectionAllocation = -1, |
| | 1 | 50 | | int maxDepth = -1, |
| | 1 | 51 | | int maxSegmentSize = -1, |
| | 1 | 52 | | IProxy? baseProxy = null, |
| | 1 | 53 | | ISliceFeature? defaultFeature = null) |
| | 1 | 54 | | { |
| | 1 | 55 | | defaultFeature ??= Default; |
| | | 56 | | |
| | 1 | 57 | | Activator = activator ?? defaultFeature.Activator; |
| | 1 | 58 | | EncodeOptions = encodeOptions ?? defaultFeature.EncodeOptions; |
| | | 59 | | |
| | 1 | 60 | | MaxCollectionAllocation = maxCollectionAllocation >= 0 ? maxCollectionAllocation : |
| | 1 | 61 | | (maxSegmentSize >= 0 ? 8 * maxSegmentSize : defaultFeature.MaxCollectionAllocation); |
| | | 62 | | |
| | 1 | 63 | | MaxDepth = maxDepth >= 0 ? maxDepth : defaultFeature.MaxDepth; |
| | | 64 | | |
| | 1 | 65 | | MaxSegmentSize = maxSegmentSize >= 0 ? maxSegmentSize : defaultFeature.MaxSegmentSize; |
| | | 66 | | |
| | 1 | 67 | | BaseProxy = baseProxy ?? defaultFeature.BaseProxy; |
| | 1 | 68 | | } |
| | | 69 | | |
| | | 70 | | private class DefaultSliceFeature : ISliceFeature |
| | | 71 | | { |
| | 208 | 72 | | public IActivator? Activator => null; |
| | | 73 | | |
| | 213 | 74 | | public IProxy? BaseProxy => null; |
| | | 75 | | |
| | 1 | 76 | | public SliceEncodeOptions? EncodeOptions => null; |
| | | 77 | | |
| | 232 | 78 | | public int MaxCollectionAllocation => 8 * MaxSegmentSize; |
| | | 79 | | |
| | 219 | 80 | | public int MaxDepth => 100; |
| | | 81 | | |
| | 575 | 82 | | public int MaxSegmentSize => 1024 * 1024; |
| | | 83 | | } |
| | | 84 | | } |