| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using IceRpc.Slice; |
| | | 4 | | |
| | | 5 | | namespace IceRpc.Features; |
| | | 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> |
| | 199 | 11 | | public static ISliceFeature Default { get; } = new DefaultSliceFeature(); |
| | | 12 | | |
| | | 13 | | /// <inheritdoc/> |
| | 1 | 14 | | public ISliceProxy? BaseProxy { get; } |
| | | 15 | | |
| | | 16 | | /// <inheritdoc/> |
| | 0 | 17 | | public SliceEncodeOptions? EncodeOptions { get; } |
| | | 18 | | |
| | | 19 | | /// <inheritdoc/> |
| | 1 | 20 | | public int MaxCollectionAllocation { get; } |
| | | 21 | | |
| | | 22 | | /// <summary>Gets the maximum size of a Slice payload segment, in bytes. A Slice payload segment corresponds to the |
| | | 23 | | /// encoded arguments of an operation, the encoded return values of an operation, or a portion of a stream of |
| | | 24 | | /// variable-size elements.</summary> |
| | | 25 | | /// <value>The maximum segment size. Defaults to <c>1</c> MB.</value> |
| | 1 | 26 | | public int MaxSegmentSize { get; } |
| | | 27 | | |
| | | 28 | | /// <summary>Constructs a Slice feature.</summary> |
| | | 29 | | /// <param name="encodeOptions">The encode options.</param> |
| | | 30 | | /// <param name="maxCollectionAllocation">The maximum collection allocation. Use <c>-1</c> to get the default value: |
| | | 31 | | /// 8 times <paramref name="maxSegmentSize" /> if set, otherwise the value provided by <paramref |
| | | 32 | | /// name="defaultFeature" />.</param> |
| | | 33 | | /// <param name="maxSegmentSize">The maximum segment size. Use <c>-1</c> to get the default value.</param> |
| | | 34 | | /// <param name="baseProxy">The base proxy, used when decoding service addresses into proxies.</param> |
| | | 35 | | /// <param name="defaultFeature">A feature that provides default values for all parameters. <see langword="null" /> |
| | | 36 | | /// is equivalent to <see cref="Default" />.</param> |
| | 1 | 37 | | public SliceFeature( |
| | 1 | 38 | | SliceEncodeOptions? encodeOptions = null, |
| | 1 | 39 | | int maxCollectionAllocation = -1, |
| | 1 | 40 | | int maxSegmentSize = -1, |
| | 1 | 41 | | ISliceProxy? baseProxy = null, |
| | 1 | 42 | | ISliceFeature? defaultFeature = null) |
| | 1 | 43 | | { |
| | 1 | 44 | | defaultFeature ??= Default; |
| | | 45 | | |
| | 1 | 46 | | EncodeOptions = encodeOptions ?? defaultFeature.EncodeOptions; |
| | | 47 | | |
| | 1 | 48 | | MaxCollectionAllocation = maxCollectionAllocation >= 0 ? maxCollectionAllocation : |
| | 1 | 49 | | (maxSegmentSize >= 0 ? 8 * maxSegmentSize : defaultFeature.MaxCollectionAllocation); |
| | | 50 | | |
| | 1 | 51 | | MaxSegmentSize = maxSegmentSize >= 0 ? maxSegmentSize : defaultFeature.MaxSegmentSize; |
| | | 52 | | |
| | 1 | 53 | | BaseProxy = baseProxy ?? defaultFeature.BaseProxy; |
| | 1 | 54 | | } |
| | | 55 | | |
| | | 56 | | private class DefaultSliceFeature : ISliceFeature |
| | | 57 | | { |
| | 143 | 58 | | public ISliceProxy? BaseProxy => null; |
| | | 59 | | |
| | 1 | 60 | | public SliceEncodeOptions? EncodeOptions => null; |
| | | 61 | | |
| | 162 | 62 | | public int MaxCollectionAllocation => 8 * MaxSegmentSize; |
| | | 63 | | |
| | 348 | 64 | | public int MaxSegmentSize => 1024 * 1024; |
| | | 65 | | } |
| | | 66 | | } |