Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1 | (* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | *) |
| 19 | |
| 20 | unit Thrift.Configuration; |
| 21 | |
| 22 | interface |
| 23 | |
| 24 | uses |
| 25 | SysUtils, Generics.Collections, Generics.Defaults; |
| 26 | |
| 27 | const |
| 28 | DEFAULT_RECURSION_LIMIT = 64; |
| 29 | DEFAULT_MAX_MESSAGE_SIZE = 100 * 1024 * 1024; // 100 MB |
| 30 | DEFAULT_MAX_FRAME_SIZE = 16384000; // this value is used consistently across all Thrift libraries |
| 31 | |
| 32 | DEFAULT_THRIFT_TIMEOUT = 5 * 1000; // ms |
| 33 | |
| 34 | type |
| 35 | IThriftConfiguration = interface |
| 36 | ['{ADD75449-1A67-4B78-9B75-502A1E338CFC}'] |
| 37 | function GetRecursionLimit : Cardinal; |
| 38 | procedure SetRecursionLimit( const value : Cardinal); |
| 39 | function GetMaxFrameSize : Cardinal; |
| 40 | procedure SetMaxFrameSize( const value : Cardinal); |
| 41 | function GetMaxMessageSize : Cardinal; |
| 42 | procedure SetMaxMessageSize( const value : Cardinal); |
| 43 | |
| 44 | property RecursionLimit : Cardinal read GetRecursionLimit write SetRecursionLimit; |
| 45 | property MaxFrameSize : Cardinal read GetMaxFrameSize write SetMaxFrameSize; |
| 46 | property MaxMessageSize : Cardinal read GetMaxMessageSize write SetMaxMessageSize; |
| 47 | end; |
| 48 | |
| 49 | |
| 50 | TThriftConfigurationImpl = class( TInterfacedObject, IThriftConfiguration) |
| 51 | strict protected |
| 52 | FRecursionLimit : Cardinal; |
| 53 | FMaxFrameSize : Cardinal; |
| 54 | FMaxMessageSize : Cardinal; |
| 55 | |
| 56 | // IThriftConfiguration |
| 57 | function GetRecursionLimit : Cardinal; |
| 58 | procedure SetRecursionLimit( const value : Cardinal); |
| 59 | function GetMaxFrameSize : Cardinal; |
| 60 | procedure SetMaxFrameSize( const value : Cardinal); |
| 61 | function GetMaxMessageSize : Cardinal; |
| 62 | procedure SetMaxMessageSize( const value : Cardinal); |
| 63 | |
| 64 | public |
| 65 | constructor Create; |
| 66 | end; |
| 67 | |
| 68 | |
| 69 | implementation |
| 70 | |
| 71 | |
| 72 | { TThriftConfigurationImpl } |
| 73 | |
| 74 | |
| 75 | constructor TThriftConfigurationImpl.Create; |
| 76 | begin |
| 77 | inherited Create; |
| 78 | |
| 79 | FRecursionLimit := DEFAULT_RECURSION_LIMIT; |
| 80 | FMaxFrameSize := DEFAULT_MAX_FRAME_SIZE; |
| 81 | FMaxMessageSize := DEFAULT_MAX_MESSAGE_SIZE; |
| 82 | end; |
| 83 | |
| 84 | |
| 85 | function TThriftConfigurationImpl.GetRecursionLimit: Cardinal; |
| 86 | begin |
| 87 | result := FRecursionLimit; |
| 88 | end; |
| 89 | |
| 90 | |
| 91 | procedure TThriftConfigurationImpl.SetRecursionLimit(const value: Cardinal); |
| 92 | begin |
| 93 | FRecursionLimit := value; |
| 94 | end; |
| 95 | |
| 96 | |
| 97 | function TThriftConfigurationImpl.GetMaxFrameSize: Cardinal; |
| 98 | begin |
| 99 | result := FMaxFrameSize; |
| 100 | end; |
| 101 | |
| 102 | |
| 103 | procedure TThriftConfigurationImpl.SetMaxFrameSize(const value: Cardinal); |
| 104 | begin |
| 105 | FMaxFrameSize := value; |
| 106 | end; |
| 107 | |
| 108 | |
| 109 | function TThriftConfigurationImpl.GetMaxMessageSize: Cardinal; |
| 110 | begin |
| 111 | result := FMaxMessageSize; |
| 112 | end; |
| 113 | |
| 114 | |
| 115 | procedure TThriftConfigurationImpl.SetMaxMessageSize(const value: Cardinal); |
| 116 | begin |
| 117 | FMaxMessageSize := value; |
| 118 | end; |
| 119 | |
| 120 | |
| 121 | end. |