| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | namespace IceRpc.Protobuf; |
| | | 4 | | |
| | | 5 | | /// <summary>Default implementation of <see cref="IProtobufFeature" />.</summary> |
| | | 6 | | public sealed class ProtobufFeature : IProtobufFeature |
| | | 7 | | { |
| | | 8 | | /// <summary>Gets a <see cref="IProtobufFeature" /> with default values for all properties.</summary> |
| | 43 | 9 | | public static IProtobufFeature Default { get; } = new DefaultProtobufFeature(); |
| | | 10 | | |
| | | 11 | | /// <summary>Gets the maximum length of an encoded Protobuf message, in bytes.</summary> |
| | | 12 | | /// <value>The maximum length of a Protobuf message. Defaults to <c>1</c> MB.</value> |
| | 0 | 13 | | public int MaxMessageLength { get; } |
| | | 14 | | |
| | | 15 | | /// <inheritdoc/> |
| | 0 | 16 | | public ProtobufEncodeOptions? EncodeOptions { get; } |
| | | 17 | | |
| | | 18 | | /// <summary>Constructs a Protobuf feature.</summary> |
| | | 19 | | /// <param name="maxMessageLength">The maximum message length. Use <c>-1</c> to get the default value.</param> |
| | | 20 | | /// <param name="encodeOptions">The encode options.</param> |
| | | 21 | | /// <param name="defaultFeature">A feature that provides default values for all parameters. <see langword="null" /> |
| | | 22 | | /// is equivalent to <see cref="Default" />.</param> |
| | 0 | 23 | | public ProtobufFeature( |
| | 0 | 24 | | int maxMessageLength = -1, |
| | 0 | 25 | | ProtobufEncodeOptions? encodeOptions = null, |
| | 0 | 26 | | IProtobufFeature? defaultFeature = null) |
| | 0 | 27 | | { |
| | 0 | 28 | | defaultFeature ??= Default; |
| | 0 | 29 | | MaxMessageLength = maxMessageLength >= 0 ? maxMessageLength : defaultFeature.MaxMessageLength; |
| | 0 | 30 | | EncodeOptions = encodeOptions ?? defaultFeature.EncodeOptions; |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | private class DefaultProtobufFeature : IProtobufFeature |
| | | 34 | | { |
| | 42 | 35 | | public int MaxMessageLength => 1024 * 1024; |
| | | 36 | | |
| | 19 | 37 | | public ProtobufEncodeOptions? EncodeOptions => null; |
| | | 38 | | } |
| | | 39 | | } |