Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [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 | {$SCOPEDENUMS ON} |
| 21 | |
| 22 | unit Thrift.Protocol; |
| 23 | |
| 24 | interface |
| 25 | |
| 26 | uses |
| 27 | Classes, |
| 28 | SysUtils, |
| 29 | Contnrs, |
Jens Geyer | 606f1ef | 2018-04-09 23:09:41 +0200 | [diff] [blame] | 30 | Thrift.Exception, |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 31 | Thrift.Stream, |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame] | 32 | Thrift.Utils, |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 33 | Thrift.Collections, |
| 34 | Thrift.Transport; |
| 35 | |
| 36 | type |
| 37 | |
| 38 | TType = ( |
| 39 | Stop = 0, |
| 40 | Void = 1, |
| 41 | Bool_ = 2, |
| 42 | Byte_ = 3, |
| 43 | Double_ = 4, |
| 44 | I16 = 6, |
| 45 | I32 = 8, |
| 46 | I64 = 10, |
| 47 | String_ = 11, |
| 48 | Struct = 12, |
| 49 | Map = 13, |
| 50 | Set_ = 14, |
| 51 | List = 15 |
| 52 | ); |
| 53 | |
| 54 | TMessageType = ( |
| 55 | Call = 1, |
| 56 | Reply = 2, |
| 57 | Exception = 3, |
| 58 | Oneway = 4 |
| 59 | ); |
| 60 | |
Jens Geyer | f0e6331 | 2015-03-01 18:47:49 +0100 | [diff] [blame] | 61 | const |
| 62 | VALID_TTYPES = [ |
| 63 | TType.Stop, TType.Void, |
| 64 | TType.Bool_, TType.Byte_, TType.Double_, TType.I16, TType.I32, TType.I64, TType.String_, |
| 65 | TType.Struct, TType.Map, TType.Set_, TType.List |
| 66 | ]; |
| 67 | |
| 68 | VALID_MESSAGETYPES = [Low(TMessageType)..High(TMessageType)]; |
| 69 | |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 70 | const |
| 71 | DEFAULT_RECURSION_LIMIT = 64; |
| 72 | |
Jens Geyer | f0e6331 | 2015-03-01 18:47:49 +0100 | [diff] [blame] | 73 | type |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 74 | IProtocol = interface; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 75 | |
| 76 | TThriftMessage = record |
| 77 | Name: string; |
| 78 | Type_: TMessageType; |
| 79 | SeqID: Integer; |
| 80 | end; |
| 81 | |
| 82 | TThriftStruct = record |
| 83 | Name: string; |
| 84 | end; |
| 85 | |
| 86 | TThriftField = record |
| 87 | Name: string; |
| 88 | Type_: TType; |
| 89 | Id: SmallInt; |
| 90 | end; |
| 91 | |
| 92 | TThriftList = record |
| 93 | ElementType: TType; |
| 94 | Count: Integer; |
| 95 | end; |
| 96 | |
| 97 | TThriftMap = record |
| 98 | KeyType: TType; |
| 99 | ValueType: TType; |
| 100 | Count: Integer; |
| 101 | end; |
| 102 | |
| 103 | TThriftSet = record |
| 104 | ElementType: TType; |
| 105 | Count: Integer; |
| 106 | end; |
| 107 | |
| 108 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 109 | IProtocolFactory = interface |
| 110 | ['{7CD64A10-4E9F-4E99-93BF-708A31F4A67B}'] |
| 111 | function GetProtocol( const trans: ITransport): IProtocol; |
| 112 | end; |
| 113 | |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 114 | TProtocolException = class abstract( TException) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 115 | public |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 116 | type TExceptionType = ( |
| 117 | UNKNOWN = 0, |
| 118 | INVALID_DATA = 1, |
| 119 | NEGATIVE_SIZE = 2, |
| 120 | SIZE_LIMIT = 3, |
| 121 | BAD_VERSION = 4, |
| 122 | NOT_IMPLEMENTED = 5, |
| 123 | DEPTH_LIMIT = 6 |
| 124 | ); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 125 | strict protected |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 126 | constructor HiddenCreate(const Msg: string); |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 127 | class function GetType: TExceptionType; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 128 | public |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 129 | // purposefully hide inherited constructor |
| 130 | class function Create(const Msg: string): TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)'; |
| 131 | class function Create: TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)'; |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 132 | class function Create( aType: TExceptionType): TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)'; |
| 133 | class function Create( aType: TExceptionType; const msg: string): TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)'; |
| 134 | property Type_: TExceptionType read GetType; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 135 | end; |
| 136 | |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 137 | // Needed to remove deprecation warning |
| 138 | TProtocolExceptionSpecialized = class abstract (TProtocolException) |
| 139 | public |
| 140 | constructor Create(const Msg: string); |
| 141 | end; |
| 142 | |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 143 | TProtocolExceptionUnknown = class (TProtocolExceptionSpecialized) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 144 | strict protected |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 145 | class function GetType: TProtocolException.TExceptionType; override; |
| 146 | end; |
| 147 | |
| 148 | TProtocolExceptionInvalidData = class (TProtocolExceptionSpecialized) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 149 | strict protected |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 150 | class function GetType: TProtocolException.TExceptionType; override; |
| 151 | end; |
| 152 | |
| 153 | TProtocolExceptionNegativeSize = class (TProtocolExceptionSpecialized) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 154 | strict protected |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 155 | class function GetType: TProtocolException.TExceptionType; override; |
| 156 | end; |
| 157 | |
| 158 | TProtocolExceptionSizeLimit = class (TProtocolExceptionSpecialized) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 159 | strict protected |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 160 | class function GetType: TProtocolException.TExceptionType; override; |
| 161 | end; |
| 162 | |
| 163 | TProtocolExceptionBadVersion = class (TProtocolExceptionSpecialized) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 164 | strict protected |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 165 | class function GetType: TProtocolException.TExceptionType; override; |
| 166 | end; |
| 167 | |
| 168 | TProtocolExceptionNotImplemented = class (TProtocolExceptionSpecialized) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 169 | strict protected |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 170 | class function GetType: TProtocolException.TExceptionType; override; |
| 171 | end; |
| 172 | |
| 173 | TProtocolExceptionDepthLimit = class (TProtocolExceptionSpecialized) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 174 | strict protected |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 175 | class function GetType: TProtocolException.TExceptionType; override; |
| 176 | end; |
| 177 | |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 178 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 179 | |
| 180 | TProtocolUtil = class |
| 181 | public |
| 182 | class procedure Skip( prot: IProtocol; type_: TType); |
| 183 | end; |
| 184 | |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 185 | IProtocolRecursionTracker = interface |
| 186 | ['{29CA033F-BB56-49B1-9EE3-31B1E82FC7A5}'] |
| 187 | // no members yet |
| 188 | end; |
| 189 | |
| 190 | TProtocolRecursionTrackerImpl = class abstract( TInterfacedObject, IProtocolRecursionTracker) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 191 | strict protected |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 192 | FProtocol : IProtocol; |
| 193 | public |
| 194 | constructor Create( prot : IProtocol); |
| 195 | destructor Destroy; override; |
| 196 | end; |
| 197 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 198 | IProtocol = interface |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 199 | ['{602A7FFB-0D9E-4CD8-8D7F-E5076660588A}'] |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 200 | function GetTransport: ITransport; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 201 | procedure WriteMessageBegin( const msg: TThriftMessage); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 202 | procedure WriteMessageEnd; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 203 | procedure WriteStructBegin( const struc: TThriftStruct); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 204 | procedure WriteStructEnd; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 205 | procedure WriteFieldBegin( const field: TThriftField); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 206 | procedure WriteFieldEnd; |
| 207 | procedure WriteFieldStop; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 208 | procedure WriteMapBegin( const map: TThriftMap); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 209 | procedure WriteMapEnd; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 210 | procedure WriteListBegin( const list: TThriftList); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 211 | procedure WriteListEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 212 | procedure WriteSetBegin( const set_: TThriftSet ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 213 | procedure WriteSetEnd(); |
| 214 | procedure WriteBool( b: Boolean); |
| 215 | procedure WriteByte( b: ShortInt); |
| 216 | procedure WriteI16( i16: SmallInt); |
| 217 | procedure WriteI32( i32: Integer); |
| 218 | procedure WriteI64( const i64: Int64); |
| 219 | procedure WriteDouble( const d: Double); |
| 220 | procedure WriteString( const s: string ); |
| 221 | procedure WriteAnsiString( const s: AnsiString); |
| 222 | procedure WriteBinary( const b: TBytes); |
| 223 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 224 | function ReadMessageBegin: TThriftMessage; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 225 | procedure ReadMessageEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 226 | function ReadStructBegin: TThriftStruct; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 227 | procedure ReadStructEnd; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 228 | function ReadFieldBegin: TThriftField; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 229 | procedure ReadFieldEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 230 | function ReadMapBegin: TThriftMap; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 231 | procedure ReadMapEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 232 | function ReadListBegin: TThriftList; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 233 | procedure ReadListEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 234 | function ReadSetBegin: TThriftSet; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 235 | procedure ReadSetEnd(); |
| 236 | function ReadBool: Boolean; |
| 237 | function ReadByte: ShortInt; |
| 238 | function ReadI16: SmallInt; |
| 239 | function ReadI32: Integer; |
| 240 | function ReadI64: Int64; |
| 241 | function ReadDouble:Double; |
| 242 | function ReadBinary: TBytes; |
| 243 | function ReadString: string; |
| 244 | function ReadAnsiString: AnsiString; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 245 | |
| 246 | procedure SetRecursionLimit( value : Integer); |
| 247 | function GetRecursionLimit : Integer; |
| 248 | function NextRecursionLevel : IProtocolRecursionTracker; |
| 249 | procedure IncrementRecursionDepth; |
| 250 | procedure DecrementRecursionDepth; |
| 251 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 252 | property Transport: ITransport read GetTransport; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 253 | property RecursionLimit : Integer read GetRecursionLimit write SetRecursionLimit; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 254 | end; |
| 255 | |
| 256 | TProtocolImpl = class abstract( TInterfacedObject, IProtocol) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 257 | strict protected |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 258 | FTrans : ITransport; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 259 | FRecursionLimit : Integer; |
| 260 | FRecursionDepth : Integer; |
| 261 | |
| 262 | procedure SetRecursionLimit( value : Integer); |
| 263 | function GetRecursionLimit : Integer; |
| 264 | function NextRecursionLevel : IProtocolRecursionTracker; |
| 265 | procedure IncrementRecursionDepth; |
| 266 | procedure DecrementRecursionDepth; |
| 267 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 268 | function GetTransport: ITransport; |
| 269 | public |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 270 | procedure WriteMessageBegin( const msg: TThriftMessage); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 271 | procedure WriteMessageEnd; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 272 | procedure WriteStructBegin( const struc: TThriftStruct); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 273 | procedure WriteStructEnd; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 274 | procedure WriteFieldBegin( const field: TThriftField); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 275 | procedure WriteFieldEnd; virtual; abstract; |
| 276 | procedure WriteFieldStop; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 277 | procedure WriteMapBegin( const map: TThriftMap); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 278 | procedure WriteMapEnd; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 279 | procedure WriteListBegin( const list: TThriftList); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 280 | procedure WriteListEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 281 | procedure WriteSetBegin( const set_: TThriftSet ); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 282 | procedure WriteSetEnd(); virtual; abstract; |
| 283 | procedure WriteBool( b: Boolean); virtual; abstract; |
| 284 | procedure WriteByte( b: ShortInt); virtual; abstract; |
| 285 | procedure WriteI16( i16: SmallInt); virtual; abstract; |
| 286 | procedure WriteI32( i32: Integer); virtual; abstract; |
| 287 | procedure WriteI64( const i64: Int64); virtual; abstract; |
| 288 | procedure WriteDouble( const d: Double); virtual; abstract; |
| 289 | procedure WriteString( const s: string ); virtual; |
| 290 | procedure WriteAnsiString( const s: AnsiString); virtual; |
| 291 | procedure WriteBinary( const b: TBytes); virtual; abstract; |
| 292 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 293 | function ReadMessageBegin: TThriftMessage; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 294 | procedure ReadMessageEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 295 | function ReadStructBegin: TThriftStruct; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 296 | procedure ReadStructEnd; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 297 | function ReadFieldBegin: TThriftField; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 298 | procedure ReadFieldEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 299 | function ReadMapBegin: TThriftMap; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 300 | procedure ReadMapEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 301 | function ReadListBegin: TThriftList; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 302 | procedure ReadListEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 303 | function ReadSetBegin: TThriftSet; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 304 | procedure ReadSetEnd(); virtual; abstract; |
| 305 | function ReadBool: Boolean; virtual; abstract; |
| 306 | function ReadByte: ShortInt; virtual; abstract; |
| 307 | function ReadI16: SmallInt; virtual; abstract; |
| 308 | function ReadI32: Integer; virtual; abstract; |
| 309 | function ReadI64: Int64; virtual; abstract; |
| 310 | function ReadDouble:Double; virtual; abstract; |
| 311 | function ReadBinary: TBytes; virtual; abstract; |
| 312 | function ReadString: string; virtual; |
| 313 | function ReadAnsiString: AnsiString; virtual; |
| 314 | |
| 315 | property Transport: ITransport read GetTransport; |
| 316 | |
| 317 | constructor Create( trans: ITransport ); |
| 318 | end; |
| 319 | |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame] | 320 | IBase = interface( ISupportsToString) |
| 321 | ['{AFF6CECA-5200-4540-950E-9B89E0C1C00C}'] |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 322 | procedure Read( const iprot: IProtocol); |
| 323 | procedure Write( const iprot: IProtocol); |
| 324 | end; |
| 325 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 326 | |
| 327 | TBinaryProtocolImpl = class( TProtocolImpl ) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 328 | strict protected |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 329 | const |
| 330 | VERSION_MASK : Cardinal = $ffff0000; |
| 331 | VERSION_1 : Cardinal = $80010000; |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 332 | strict protected |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 333 | FStrictRead : Boolean; |
| 334 | FStrictWrite : Boolean; |
| 335 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 336 | strict private |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 337 | function ReadAll( const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer ): Integer; inline; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 338 | function ReadStringBody( size: Integer): string; |
| 339 | |
| 340 | public |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 341 | type |
| 342 | TFactory = class( TInterfacedObject, IProtocolFactory) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 343 | strict protected |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 344 | FStrictRead : Boolean; |
| 345 | FStrictWrite : Boolean; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 346 | function GetProtocol( const trans: ITransport): IProtocol; |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 347 | public |
| 348 | constructor Create( const aStrictRead : Boolean = FALSE; const aStrictWrite: Boolean = TRUE); reintroduce; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 349 | end; |
| 350 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 351 | constructor Create( const trans: ITransport; strictRead: Boolean = FALSE; strictWrite: Boolean = TRUE); reintroduce; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 352 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 353 | procedure WriteMessageBegin( const msg: TThriftMessage); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 354 | procedure WriteMessageEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 355 | procedure WriteStructBegin( const struc: TThriftStruct); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 356 | procedure WriteStructEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 357 | procedure WriteFieldBegin( const field: TThriftField); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 358 | procedure WriteFieldEnd; override; |
| 359 | procedure WriteFieldStop; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 360 | procedure WriteMapBegin( const map: TThriftMap); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 361 | procedure WriteMapEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 362 | procedure WriteListBegin( const list: TThriftList); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 363 | procedure WriteListEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 364 | procedure WriteSetBegin( const set_: TThriftSet ); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 365 | procedure WriteSetEnd(); override; |
| 366 | procedure WriteBool( b: Boolean); override; |
| 367 | procedure WriteByte( b: ShortInt); override; |
| 368 | procedure WriteI16( i16: SmallInt); override; |
| 369 | procedure WriteI32( i32: Integer); override; |
| 370 | procedure WriteI64( const i64: Int64); override; |
| 371 | procedure WriteDouble( const d: Double); override; |
| 372 | procedure WriteBinary( const b: TBytes); override; |
| 373 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 374 | function ReadMessageBegin: TThriftMessage; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 375 | procedure ReadMessageEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 376 | function ReadStructBegin: TThriftStruct; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 377 | procedure ReadStructEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 378 | function ReadFieldBegin: TThriftField; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 379 | procedure ReadFieldEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 380 | function ReadMapBegin: TThriftMap; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 381 | procedure ReadMapEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 382 | function ReadListBegin: TThriftList; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 383 | procedure ReadListEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 384 | function ReadSetBegin: TThriftSet; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 385 | procedure ReadSetEnd(); override; |
| 386 | function ReadBool: Boolean; override; |
| 387 | function ReadByte: ShortInt; override; |
| 388 | function ReadI16: SmallInt; override; |
| 389 | function ReadI32: Integer; override; |
| 390 | function ReadI64: Int64; override; |
| 391 | function ReadDouble:Double; override; |
| 392 | function ReadBinary: TBytes; override; |
| 393 | |
| 394 | end; |
| 395 | |
| 396 | |
| 397 | { TProtocolDecorator forwards all requests to an enclosed TProtocol instance, |
| 398 | providing a way to author concise concrete decorator subclasses. The decorator |
| 399 | does not (and should not) modify the behaviour of the enclosed TProtocol |
| 400 | |
| 401 | See p.175 of Design Patterns (by Gamma et al.) |
| 402 | } |
| 403 | TProtocolDecorator = class( TProtocolImpl) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 404 | strict private |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 405 | FWrappedProtocol : IProtocol; |
| 406 | |
| 407 | public |
| 408 | // Encloses the specified protocol. |
| 409 | // All operations will be forward to the given protocol. Must be non-null. |
| 410 | constructor Create( const aProtocol : IProtocol); |
| 411 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 412 | procedure WriteMessageBegin( const msg: TThriftMessage); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 413 | procedure WriteMessageEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 414 | procedure WriteStructBegin( const struc: TThriftStruct); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 415 | procedure WriteStructEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 416 | procedure WriteFieldBegin( const field: TThriftField); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 417 | procedure WriteFieldEnd; override; |
| 418 | procedure WriteFieldStop; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 419 | procedure WriteMapBegin( const map: TThriftMap); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 420 | procedure WriteMapEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 421 | procedure WriteListBegin( const list: TThriftList); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 422 | procedure WriteListEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 423 | procedure WriteSetBegin( const set_: TThriftSet ); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 424 | procedure WriteSetEnd(); override; |
| 425 | procedure WriteBool( b: Boolean); override; |
| 426 | procedure WriteByte( b: ShortInt); override; |
| 427 | procedure WriteI16( i16: SmallInt); override; |
| 428 | procedure WriteI32( i32: Integer); override; |
| 429 | procedure WriteI64( const i64: Int64); override; |
| 430 | procedure WriteDouble( const d: Double); override; |
| 431 | procedure WriteString( const s: string ); override; |
| 432 | procedure WriteAnsiString( const s: AnsiString); override; |
| 433 | procedure WriteBinary( const b: TBytes); override; |
| 434 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 435 | function ReadMessageBegin: TThriftMessage; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 436 | procedure ReadMessageEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 437 | function ReadStructBegin: TThriftStruct; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 438 | procedure ReadStructEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 439 | function ReadFieldBegin: TThriftField; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 440 | procedure ReadFieldEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 441 | function ReadMapBegin: TThriftMap; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 442 | procedure ReadMapEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 443 | function ReadListBegin: TThriftList; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 444 | procedure ReadListEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 445 | function ReadSetBegin: TThriftSet; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 446 | procedure ReadSetEnd(); override; |
| 447 | function ReadBool: Boolean; override; |
| 448 | function ReadByte: ShortInt; override; |
| 449 | function ReadI16: SmallInt; override; |
| 450 | function ReadI32: Integer; override; |
| 451 | function ReadI64: Int64; override; |
| 452 | function ReadDouble:Double; override; |
| 453 | function ReadBinary: TBytes; override; |
| 454 | function ReadString: string; override; |
| 455 | function ReadAnsiString: AnsiString; override; |
| 456 | end; |
| 457 | |
| 458 | |
| 459 | type |
| 460 | IRequestEvents = interface |
Jens Geyer | 0164040 | 2013-09-25 21:12:21 +0200 | [diff] [blame] | 461 | ['{F926A26A-5B00-4560-86FA-2CAE3BA73DAF}'] |
| 462 | // Called before reading arguments. |
| 463 | procedure PreRead; |
| 464 | // Called between reading arguments and calling the handler. |
| 465 | procedure PostRead; |
| 466 | // Called between calling the handler and writing the response. |
| 467 | procedure PreWrite; |
| 468 | // Called after writing the response. |
| 469 | procedure PostWrite; |
| 470 | // Called when an oneway (async) function call completes successfully. |
| 471 | procedure OnewayComplete; |
| 472 | // Called if the handler throws an undeclared exception. |
| 473 | procedure UnhandledError( const e : Exception); |
| 474 | // Called when a client has finished request-handling to clean up |
| 475 | procedure CleanupContext; |
| 476 | end; |
| 477 | |
| 478 | |
| 479 | IProcessorEvents = interface |
| 480 | ['{A8661119-657C-447D-93C5-512E36162A45}'] |
| 481 | // Called when a client is about to call the processor. |
| 482 | procedure Processing( const transport : ITransport); |
| 483 | // Called on any service function invocation |
| 484 | function CreateRequestContext( const aFunctionName : string) : IRequestEvents; |
| 485 | // Called when a client has finished request-handling to clean up |
| 486 | procedure CleanupContext; |
| 487 | end; |
| 488 | |
| 489 | |
| 490 | IProcessor = interface |
| 491 | ['{7BAE92A5-46DA-4F13-B6EA-0EABE233EE5F}'] |
Jens Geyer | d430bbd | 2013-09-26 23:37:54 +0200 | [diff] [blame] | 492 | function Process( const iprot :IProtocol; const oprot: IProtocol; const events : IProcessorEvents = nil): Boolean; |
Jens Geyer | 0164040 | 2013-09-25 21:12:21 +0200 | [diff] [blame] | 493 | end; |
| 494 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 495 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 496 | procedure Init( var rec : TThriftMessage; const AName: string = ''; const AMessageType: TMessageType = Low(TMessageType); const ASeqID: Integer = 0); overload; inline; |
| 497 | procedure Init( var rec : TThriftStruct; const AName: string = ''); overload; inline; |
| 498 | procedure Init( var rec : TThriftField; const AName: string = ''; const AType: TType = Low(TType); const AID: SmallInt = 0); overload; inline; |
| 499 | procedure Init( var rec : TThriftMap; const AKeyType: TType = Low(TType); const AValueType: TType = Low(TType); const ACount: Integer = 0); overload; inline; |
| 500 | procedure Init( var rec : TThriftSet; const AElementType: TType = Low(TType); const ACount: Integer = 0); overload; inline; |
| 501 | procedure Init( var rec : TThriftList; const AElementType: TType = Low(TType); const ACount: Integer = 0); overload; inline; |
| 502 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 503 | |
| 504 | implementation |
| 505 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 506 | function ConvertInt64ToDouble( const n: Int64): Double; inline; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 507 | begin |
| 508 | ASSERT( SizeOf(n) = SizeOf(Result)); |
| 509 | System.Move( n, Result, SizeOf(Result)); |
| 510 | end; |
| 511 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 512 | function ConvertDoubleToInt64( const d: Double): Int64; inline; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 513 | begin |
| 514 | ASSERT( SizeOf(d) = SizeOf(Result)); |
| 515 | System.Move( d, Result, SizeOf(Result)); |
| 516 | end; |
| 517 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 518 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 519 | |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 520 | { TProtocolRecursionTrackerImpl } |
| 521 | |
| 522 | constructor TProtocolRecursionTrackerImpl.Create( prot : IProtocol); |
| 523 | begin |
| 524 | inherited Create; |
| 525 | |
| 526 | // storing the pointer *after* the (successful) increment is important here |
| 527 | prot.IncrementRecursionDepth; |
| 528 | FProtocol := prot; |
| 529 | end; |
| 530 | |
| 531 | destructor TProtocolRecursionTrackerImpl.Destroy; |
| 532 | begin |
| 533 | try |
| 534 | // we have to release the reference iff the pointer has been stored |
| 535 | if FProtocol <> nil then begin |
| 536 | FProtocol.DecrementRecursionDepth; |
| 537 | FProtocol := nil; |
| 538 | end; |
| 539 | finally |
| 540 | inherited Destroy; |
| 541 | end; |
| 542 | end; |
| 543 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 544 | { TProtocolImpl } |
| 545 | |
| 546 | constructor TProtocolImpl.Create(trans: ITransport); |
| 547 | begin |
| 548 | inherited Create; |
| 549 | FTrans := trans; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 550 | FRecursionLimit := DEFAULT_RECURSION_LIMIT; |
| 551 | FRecursionDepth := 0; |
| 552 | end; |
| 553 | |
| 554 | procedure TProtocolImpl.SetRecursionLimit( value : Integer); |
| 555 | begin |
| 556 | FRecursionLimit := value; |
| 557 | end; |
| 558 | |
| 559 | function TProtocolImpl.GetRecursionLimit : Integer; |
| 560 | begin |
| 561 | result := FRecursionLimit; |
| 562 | end; |
| 563 | |
| 564 | function TProtocolImpl.NextRecursionLevel : IProtocolRecursionTracker; |
| 565 | begin |
| 566 | result := TProtocolRecursionTrackerImpl.Create(Self); |
| 567 | end; |
| 568 | |
| 569 | procedure TProtocolImpl.IncrementRecursionDepth; |
| 570 | begin |
| 571 | if FRecursionDepth < FRecursionLimit |
| 572 | then Inc(FRecursionDepth) |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 573 | else raise TProtocolExceptionDepthLimit.Create('Depth limit exceeded'); |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 574 | end; |
| 575 | |
| 576 | procedure TProtocolImpl.DecrementRecursionDepth; |
| 577 | begin |
| 578 | Dec(FRecursionDepth) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 579 | end; |
| 580 | |
| 581 | function TProtocolImpl.GetTransport: ITransport; |
| 582 | begin |
| 583 | Result := FTrans; |
| 584 | end; |
| 585 | |
| 586 | function TProtocolImpl.ReadAnsiString: AnsiString; |
| 587 | var |
| 588 | b : TBytes; |
| 589 | len : Integer; |
| 590 | begin |
| 591 | Result := ''; |
| 592 | b := ReadBinary; |
| 593 | len := Length( b ); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 594 | if len > 0 then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 595 | SetLength( Result, len); |
| 596 | System.Move( b[0], Pointer(Result)^, len ); |
| 597 | end; |
| 598 | end; |
| 599 | |
| 600 | function TProtocolImpl.ReadString: string; |
| 601 | begin |
| 602 | Result := TEncoding.UTF8.GetString( ReadBinary ); |
| 603 | end; |
| 604 | |
| 605 | procedure TProtocolImpl.WriteAnsiString(const s: AnsiString); |
| 606 | var |
| 607 | b : TBytes; |
| 608 | len : Integer; |
| 609 | begin |
| 610 | len := Length(s); |
| 611 | SetLength( b, len); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 612 | if len > 0 then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 613 | System.Move( Pointer(s)^, b[0], len ); |
| 614 | end; |
| 615 | WriteBinary( b ); |
| 616 | end; |
| 617 | |
| 618 | procedure TProtocolImpl.WriteString(const s: string); |
| 619 | var |
| 620 | b : TBytes; |
| 621 | begin |
| 622 | b := TEncoding.UTF8.GetBytes(s); |
| 623 | WriteBinary( b ); |
| 624 | end; |
| 625 | |
| 626 | { TProtocolUtil } |
| 627 | |
| 628 | class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 629 | var field : TThriftField; |
| 630 | map : TThriftMap; |
| 631 | set_ : TThriftSet; |
| 632 | list : TThriftList; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 633 | i : Integer; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 634 | tracker : IProtocolRecursionTracker; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 635 | begin |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 636 | tracker := prot.NextRecursionLevel; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 637 | case type_ of |
| 638 | // simple types |
| 639 | TType.Bool_ : prot.ReadBool(); |
| 640 | TType.Byte_ : prot.ReadByte(); |
| 641 | TType.I16 : prot.ReadI16(); |
| 642 | TType.I32 : prot.ReadI32(); |
| 643 | TType.I64 : prot.ReadI64(); |
| 644 | TType.Double_ : prot.ReadDouble(); |
| 645 | TType.String_ : prot.ReadBinary();// Don't try to decode the string, just skip it. |
| 646 | |
| 647 | // structured types |
| 648 | TType.Struct : begin |
| 649 | prot.ReadStructBegin(); |
| 650 | while TRUE do begin |
| 651 | field := prot.ReadFieldBegin(); |
| 652 | if (field.Type_ = TType.Stop) then Break; |
| 653 | Skip(prot, field.Type_); |
| 654 | prot.ReadFieldEnd(); |
| 655 | end; |
| 656 | prot.ReadStructEnd(); |
| 657 | end; |
| 658 | |
| 659 | TType.Map : begin |
| 660 | map := prot.ReadMapBegin(); |
| 661 | for i := 0 to map.Count-1 do begin |
| 662 | Skip(prot, map.KeyType); |
| 663 | Skip(prot, map.ValueType); |
| 664 | end; |
| 665 | prot.ReadMapEnd(); |
| 666 | end; |
| 667 | |
| 668 | TType.Set_ : begin |
| 669 | set_ := prot.ReadSetBegin(); |
| 670 | for i := 0 to set_.Count-1 |
| 671 | do Skip( prot, set_.ElementType); |
| 672 | prot.ReadSetEnd(); |
| 673 | end; |
| 674 | |
| 675 | TType.List : begin |
| 676 | list := prot.ReadListBegin(); |
| 677 | for i := 0 to list.Count-1 |
| 678 | do Skip( prot, list.ElementType); |
| 679 | prot.ReadListEnd(); |
| 680 | end; |
| 681 | |
| 682 | else |
Jens Geyer | 5f723cd | 2017-01-10 21:57:48 +0100 | [diff] [blame] | 683 | raise TProtocolExceptionInvalidData.Create('Unexpected type '+IntToStr(Ord(type_))); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 684 | end; |
| 685 | end; |
| 686 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 687 | |
| 688 | { TBinaryProtocolImpl } |
| 689 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 690 | constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead, strictWrite: Boolean); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 691 | begin |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 692 | inherited Create( trans); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 693 | FStrictRead := strictRead; |
| 694 | FStrictWrite := strictWrite; |
| 695 | end; |
| 696 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 697 | function TBinaryProtocolImpl.ReadAll( const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer ): Integer; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 698 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 699 | Result := FTrans.ReadAll( pBuf, buflen, off, len ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 700 | end; |
| 701 | |
| 702 | function TBinaryProtocolImpl.ReadBinary: TBytes; |
| 703 | var |
| 704 | size : Integer; |
| 705 | buf : TBytes; |
| 706 | begin |
| 707 | size := ReadI32; |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 708 | SetLength( buf, size); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 709 | FTrans.ReadAll( buf, 0, size); |
| 710 | Result := buf; |
| 711 | end; |
| 712 | |
| 713 | function TBinaryProtocolImpl.ReadBool: Boolean; |
| 714 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 715 | Result := (ReadByte = 1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 716 | end; |
| 717 | |
| 718 | function TBinaryProtocolImpl.ReadByte: ShortInt; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 719 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 720 | ReadAll( @result, SizeOf(result), 0, 1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 721 | end; |
| 722 | |
| 723 | function TBinaryProtocolImpl.ReadDouble: Double; |
| 724 | begin |
| 725 | Result := ConvertInt64ToDouble( ReadI64 ) |
| 726 | end; |
| 727 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 728 | function TBinaryProtocolImpl.ReadFieldBegin: TThriftField; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 729 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 730 | Init( result, '', TType( ReadByte), 0); |
| 731 | if ( result.Type_ <> TType.Stop ) then begin |
| 732 | result.Id := ReadI16; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 733 | end; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 734 | end; |
| 735 | |
| 736 | procedure TBinaryProtocolImpl.ReadFieldEnd; |
| 737 | begin |
| 738 | |
| 739 | end; |
| 740 | |
| 741 | function TBinaryProtocolImpl.ReadI16: SmallInt; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 742 | var i16in : packed array[0..1] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 743 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 744 | ReadAll( @i16in, Sizeof(i16in), 0, 2); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 745 | Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF)); |
| 746 | end; |
| 747 | |
| 748 | function TBinaryProtocolImpl.ReadI32: Integer; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 749 | var i32in : packed array[0..3] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 750 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 751 | ReadAll( @i32in, SizeOf(i32in), 0, 4); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 752 | |
| 753 | Result := Integer( |
| 754 | ((i32in[0] and $FF) shl 24) or |
| 755 | ((i32in[1] and $FF) shl 16) or |
| 756 | ((i32in[2] and $FF) shl 8) or |
| 757 | (i32in[3] and $FF)); |
| 758 | |
| 759 | end; |
| 760 | |
| 761 | function TBinaryProtocolImpl.ReadI64: Int64; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 762 | var i64in : packed array[0..7] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 763 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 764 | ReadAll( @i64in, SizeOf(i64in), 0, 8); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 765 | Result := |
| 766 | (Int64( i64in[0] and $FF) shl 56) or |
| 767 | (Int64( i64in[1] and $FF) shl 48) or |
| 768 | (Int64( i64in[2] and $FF) shl 40) or |
| 769 | (Int64( i64in[3] and $FF) shl 32) or |
| 770 | (Int64( i64in[4] and $FF) shl 24) or |
| 771 | (Int64( i64in[5] and $FF) shl 16) or |
| 772 | (Int64( i64in[6] and $FF) shl 8) or |
| 773 | (Int64( i64in[7] and $FF)); |
| 774 | end; |
| 775 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 776 | function TBinaryProtocolImpl.ReadListBegin: TThriftList; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 777 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 778 | result.ElementType := TType(ReadByte); |
| 779 | result.Count := ReadI32; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 780 | end; |
| 781 | |
| 782 | procedure TBinaryProtocolImpl.ReadListEnd; |
| 783 | begin |
| 784 | |
| 785 | end; |
| 786 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 787 | function TBinaryProtocolImpl.ReadMapBegin: TThriftMap; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 788 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 789 | result.KeyType := TType(ReadByte); |
| 790 | result.ValueType := TType(ReadByte); |
| 791 | result.Count := ReadI32; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 792 | end; |
| 793 | |
| 794 | procedure TBinaryProtocolImpl.ReadMapEnd; |
| 795 | begin |
| 796 | |
| 797 | end; |
| 798 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 799 | function TBinaryProtocolImpl.ReadMessageBegin: TThriftMessage; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 800 | var |
| 801 | size : Integer; |
| 802 | version : Integer; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 803 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 804 | Init( result); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 805 | size := ReadI32; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 806 | if (size < 0) then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 807 | version := size and Integer( VERSION_MASK); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 808 | if ( version <> Integer( VERSION_1)) then begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 809 | raise TProtocolExceptionBadVersion.Create('Bad version in ReadMessageBegin: ' + IntToStr(version) ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 810 | end; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 811 | result.Type_ := TMessageType( size and $000000ff); |
| 812 | result.Name := ReadString; |
| 813 | result.SeqID := ReadI32; |
| 814 | end |
| 815 | else begin |
| 816 | if FStrictRead then begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 817 | raise TProtocolExceptionBadVersion.Create('Missing version in readMessageBegin, old client?' ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 818 | end; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 819 | result.Name := ReadStringBody( size ); |
| 820 | result.Type_ := TMessageType( ReadByte ); |
| 821 | result.SeqID := ReadI32; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 822 | end; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 823 | end; |
| 824 | |
| 825 | procedure TBinaryProtocolImpl.ReadMessageEnd; |
| 826 | begin |
| 827 | inherited; |
| 828 | |
| 829 | end; |
| 830 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 831 | function TBinaryProtocolImpl.ReadSetBegin: TThriftSet; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 832 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 833 | result.ElementType := TType(ReadByte); |
| 834 | result.Count := ReadI32; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 835 | end; |
| 836 | |
| 837 | procedure TBinaryProtocolImpl.ReadSetEnd; |
| 838 | begin |
| 839 | |
| 840 | end; |
| 841 | |
| 842 | function TBinaryProtocolImpl.ReadStringBody( size: Integer): string; |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 843 | var buf : TBytes; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 844 | begin |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 845 | SetLength( buf, size); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 846 | FTrans.ReadAll( buf, 0, size ); |
| 847 | Result := TEncoding.UTF8.GetString( buf); |
| 848 | end; |
| 849 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 850 | function TBinaryProtocolImpl.ReadStructBegin: TThriftStruct; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 851 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 852 | Init( Result); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 853 | end; |
| 854 | |
| 855 | procedure TBinaryProtocolImpl.ReadStructEnd; |
| 856 | begin |
| 857 | inherited; |
| 858 | |
| 859 | end; |
| 860 | |
| 861 | procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes); |
| 862 | var iLen : Integer; |
| 863 | begin |
| 864 | iLen := Length(b); |
| 865 | WriteI32( iLen); |
| 866 | if iLen > 0 then FTrans.Write(b, 0, iLen); |
| 867 | end; |
| 868 | |
| 869 | procedure TBinaryProtocolImpl.WriteBool(b: Boolean); |
| 870 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 871 | if b then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 872 | WriteByte( 1 ); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 873 | end else begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 874 | WriteByte( 0 ); |
| 875 | end; |
| 876 | end; |
| 877 | |
| 878 | procedure TBinaryProtocolImpl.WriteByte(b: ShortInt); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 879 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 880 | FTrans.Write( @b, 0, 1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 881 | end; |
| 882 | |
| 883 | procedure TBinaryProtocolImpl.WriteDouble( const d: Double); |
| 884 | begin |
| 885 | WriteI64(ConvertDoubleToInt64(d)); |
| 886 | end; |
| 887 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 888 | procedure TBinaryProtocolImpl.WriteFieldBegin( const field: TThriftField); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 889 | begin |
| 890 | WriteByte(ShortInt(field.Type_)); |
| 891 | WriteI16(field.ID); |
| 892 | end; |
| 893 | |
| 894 | procedure TBinaryProtocolImpl.WriteFieldEnd; |
| 895 | begin |
| 896 | |
| 897 | end; |
| 898 | |
| 899 | procedure TBinaryProtocolImpl.WriteFieldStop; |
| 900 | begin |
| 901 | WriteByte(ShortInt(TType.Stop)); |
| 902 | end; |
| 903 | |
| 904 | procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 905 | var i16out : packed array[0..1] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 906 | begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 907 | i16out[0] := Byte($FF and (i16 shr 8)); |
| 908 | i16out[1] := Byte($FF and i16); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 909 | FTrans.Write( @i16out, 0, 2); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 910 | end; |
| 911 | |
| 912 | procedure TBinaryProtocolImpl.WriteI32(i32: Integer); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 913 | var i32out : packed array[0..3] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 914 | begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 915 | i32out[0] := Byte($FF and (i32 shr 24)); |
| 916 | i32out[1] := Byte($FF and (i32 shr 16)); |
| 917 | i32out[2] := Byte($FF and (i32 shr 8)); |
| 918 | i32out[3] := Byte($FF and i32); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 919 | FTrans.Write( @i32out, 0, 4); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 920 | end; |
| 921 | |
| 922 | procedure TBinaryProtocolImpl.WriteI64( const i64: Int64); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 923 | var i64out : packed array[0..7] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 924 | begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 925 | i64out[0] := Byte($FF and (i64 shr 56)); |
| 926 | i64out[1] := Byte($FF and (i64 shr 48)); |
| 927 | i64out[2] := Byte($FF and (i64 shr 40)); |
| 928 | i64out[3] := Byte($FF and (i64 shr 32)); |
| 929 | i64out[4] := Byte($FF and (i64 shr 24)); |
| 930 | i64out[5] := Byte($FF and (i64 shr 16)); |
| 931 | i64out[6] := Byte($FF and (i64 shr 8)); |
| 932 | i64out[7] := Byte($FF and i64); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 933 | FTrans.Write( @i64out, 0, 8); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 934 | end; |
| 935 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 936 | procedure TBinaryProtocolImpl.WriteListBegin( const list: TThriftList); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 937 | begin |
| 938 | WriteByte(ShortInt(list.ElementType)); |
| 939 | WriteI32(list.Count); |
| 940 | end; |
| 941 | |
| 942 | procedure TBinaryProtocolImpl.WriteListEnd; |
| 943 | begin |
| 944 | |
| 945 | end; |
| 946 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 947 | procedure TBinaryProtocolImpl.WriteMapBegin( const map: TThriftMap); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 948 | begin |
| 949 | WriteByte(ShortInt(map.KeyType)); |
| 950 | WriteByte(ShortInt(map.ValueType)); |
| 951 | WriteI32(map.Count); |
| 952 | end; |
| 953 | |
| 954 | procedure TBinaryProtocolImpl.WriteMapEnd; |
| 955 | begin |
| 956 | |
| 957 | end; |
| 958 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 959 | procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: TThriftMessage); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 960 | var version : Cardinal; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 961 | begin |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 962 | if FStrictWrite then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 963 | version := VERSION_1 or Cardinal( msg.Type_); |
| 964 | WriteI32( Integer( version) ); |
| 965 | WriteString( msg.Name); |
| 966 | WriteI32( msg.SeqID); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 967 | end else begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 968 | WriteString( msg.Name); |
| 969 | WriteByte(ShortInt( msg.Type_)); |
| 970 | WriteI32( msg.SeqID); |
| 971 | end; |
| 972 | end; |
| 973 | |
| 974 | procedure TBinaryProtocolImpl.WriteMessageEnd; |
| 975 | begin |
| 976 | |
| 977 | end; |
| 978 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 979 | procedure TBinaryProtocolImpl.WriteSetBegin( const set_: TThriftSet); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 980 | begin |
| 981 | WriteByte(ShortInt(set_.ElementType)); |
| 982 | WriteI32(set_.Count); |
| 983 | end; |
| 984 | |
| 985 | procedure TBinaryProtocolImpl.WriteSetEnd; |
| 986 | begin |
| 987 | |
| 988 | end; |
| 989 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 990 | procedure TBinaryProtocolImpl.WriteStructBegin( const struc: TThriftStruct); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 991 | begin |
| 992 | |
| 993 | end; |
| 994 | |
| 995 | procedure TBinaryProtocolImpl.WriteStructEnd; |
| 996 | begin |
| 997 | |
| 998 | end; |
| 999 | |
| 1000 | { TProtocolException } |
| 1001 | |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1002 | constructor TProtocolException.HiddenCreate(const Msg: string); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1003 | begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1004 | inherited Create(Msg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1005 | end; |
| 1006 | |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1007 | class function TProtocolException.Create(const Msg: string): TProtocolException; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1008 | begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1009 | Result := TProtocolExceptionUnknown.Create(Msg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1010 | end; |
| 1011 | |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1012 | class function TProtocolException.Create: TProtocolException; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1013 | begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1014 | Result := TProtocolExceptionUnknown.Create(''); |
| 1015 | end; |
| 1016 | |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1017 | class function TProtocolException.Create(aType: TExceptionType): TProtocolException; |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1018 | begin |
| 1019 | {$WARN SYMBOL_DEPRECATED OFF} |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1020 | Result := Create(aType, ''); |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1021 | {$WARN SYMBOL_DEPRECATED DEFAULT} |
| 1022 | end; |
| 1023 | |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1024 | class function TProtocolException.Create(aType: TExceptionType; const msg: string): TProtocolException; |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1025 | begin |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1026 | case aType of |
| 1027 | TExceptionType.INVALID_DATA: Result := TProtocolExceptionInvalidData.Create(msg); |
| 1028 | TExceptionType.NEGATIVE_SIZE: Result := TProtocolExceptionNegativeSize.Create(msg); |
| 1029 | TExceptionType.SIZE_LIMIT: Result := TProtocolExceptionSizeLimit.Create(msg); |
| 1030 | TExceptionType.BAD_VERSION: Result := TProtocolExceptionBadVersion.Create(msg); |
| 1031 | TExceptionType.NOT_IMPLEMENTED: Result := TProtocolExceptionNotImplemented.Create(msg); |
| 1032 | TExceptionType.DEPTH_LIMIT: Result := TProtocolExceptionDepthLimit.Create(msg); |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1033 | else |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1034 | ASSERT( TExceptionType.UNKNOWN = aType); |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1035 | Result := TProtocolExceptionUnknown.Create(msg); |
| 1036 | end; |
| 1037 | end; |
| 1038 | |
| 1039 | { TProtocolExceptionSpecialized } |
| 1040 | |
| 1041 | constructor TProtocolExceptionSpecialized.Create(const Msg: string); |
| 1042 | begin |
| 1043 | inherited HiddenCreate(Msg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1044 | end; |
| 1045 | |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1046 | { specialized TProtocolExceptions } |
| 1047 | |
| 1048 | class function TProtocolExceptionUnknown.GetType: TProtocolException.TExceptionType; |
| 1049 | begin |
| 1050 | result := TExceptionType.UNKNOWN; |
| 1051 | end; |
| 1052 | |
| 1053 | class function TProtocolExceptionInvalidData.GetType: TProtocolException.TExceptionType; |
| 1054 | begin |
| 1055 | result := TExceptionType.INVALID_DATA; |
| 1056 | end; |
| 1057 | |
| 1058 | class function TProtocolExceptionNegativeSize.GetType: TProtocolException.TExceptionType; |
| 1059 | begin |
| 1060 | result := TExceptionType.NEGATIVE_SIZE; |
| 1061 | end; |
| 1062 | |
| 1063 | class function TProtocolExceptionSizeLimit.GetType: TProtocolException.TExceptionType; |
| 1064 | begin |
| 1065 | result := TExceptionType.SIZE_LIMIT; |
| 1066 | end; |
| 1067 | |
| 1068 | class function TProtocolExceptionBadVersion.GetType: TProtocolException.TExceptionType; |
| 1069 | begin |
| 1070 | result := TExceptionType.BAD_VERSION; |
| 1071 | end; |
| 1072 | |
| 1073 | class function TProtocolExceptionNotImplemented.GetType: TProtocolException.TExceptionType; |
| 1074 | begin |
| 1075 | result := TExceptionType.NOT_IMPLEMENTED; |
| 1076 | end; |
| 1077 | |
| 1078 | class function TProtocolExceptionDepthLimit.GetType: TProtocolException.TExceptionType; |
| 1079 | begin |
| 1080 | result := TExceptionType.DEPTH_LIMIT; |
| 1081 | end; |
| 1082 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1083 | { TBinaryProtocolImpl.TFactory } |
| 1084 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame^] | 1085 | constructor TBinaryProtocolImpl.TFactory.Create( const aStrictRead, aStrictWrite: Boolean); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1086 | begin |
| 1087 | inherited Create; |
| 1088 | FStrictRead := AStrictRead; |
| 1089 | FStrictWrite := AStrictWrite; |
| 1090 | end; |
| 1091 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1092 | function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol; |
| 1093 | begin |
| 1094 | Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite); |
| 1095 | end; |
| 1096 | |
| 1097 | |
| 1098 | { TProtocolDecorator } |
| 1099 | |
| 1100 | constructor TProtocolDecorator.Create( const aProtocol : IProtocol); |
| 1101 | begin |
| 1102 | ASSERT( aProtocol <> nil); |
| 1103 | inherited Create( aProtocol.Transport); |
| 1104 | FWrappedProtocol := aProtocol; |
| 1105 | end; |
| 1106 | |
| 1107 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1108 | procedure TProtocolDecorator.WriteMessageBegin( const msg: TThriftMessage); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1109 | begin |
| 1110 | FWrappedProtocol.WriteMessageBegin( msg); |
| 1111 | end; |
| 1112 | |
| 1113 | |
| 1114 | procedure TProtocolDecorator.WriteMessageEnd; |
| 1115 | begin |
| 1116 | FWrappedProtocol.WriteMessageEnd; |
| 1117 | end; |
| 1118 | |
| 1119 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1120 | procedure TProtocolDecorator.WriteStructBegin( const struc: TThriftStruct); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1121 | begin |
| 1122 | FWrappedProtocol.WriteStructBegin( struc); |
| 1123 | end; |
| 1124 | |
| 1125 | |
| 1126 | procedure TProtocolDecorator.WriteStructEnd; |
| 1127 | begin |
| 1128 | FWrappedProtocol.WriteStructEnd; |
| 1129 | end; |
| 1130 | |
| 1131 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1132 | procedure TProtocolDecorator.WriteFieldBegin( const field: TThriftField); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1133 | begin |
| 1134 | FWrappedProtocol.WriteFieldBegin( field); |
| 1135 | end; |
| 1136 | |
| 1137 | |
| 1138 | procedure TProtocolDecorator.WriteFieldEnd; |
| 1139 | begin |
| 1140 | FWrappedProtocol.WriteFieldEnd; |
| 1141 | end; |
| 1142 | |
| 1143 | |
| 1144 | procedure TProtocolDecorator.WriteFieldStop; |
| 1145 | begin |
| 1146 | FWrappedProtocol.WriteFieldStop; |
| 1147 | end; |
| 1148 | |
| 1149 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1150 | procedure TProtocolDecorator.WriteMapBegin( const map: TThriftMap); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1151 | begin |
| 1152 | FWrappedProtocol.WriteMapBegin( map); |
| 1153 | end; |
| 1154 | |
| 1155 | |
| 1156 | procedure TProtocolDecorator.WriteMapEnd; |
| 1157 | begin |
| 1158 | FWrappedProtocol.WriteMapEnd; |
| 1159 | end; |
| 1160 | |
| 1161 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1162 | procedure TProtocolDecorator.WriteListBegin( const list: TThriftList); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1163 | begin |
| 1164 | FWrappedProtocol.WriteListBegin( list); |
| 1165 | end; |
| 1166 | |
| 1167 | |
| 1168 | procedure TProtocolDecorator.WriteListEnd(); |
| 1169 | begin |
| 1170 | FWrappedProtocol.WriteListEnd(); |
| 1171 | end; |
| 1172 | |
| 1173 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1174 | procedure TProtocolDecorator.WriteSetBegin( const set_: TThriftSet ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1175 | begin |
| 1176 | FWrappedProtocol.WriteSetBegin( set_); |
| 1177 | end; |
| 1178 | |
| 1179 | |
| 1180 | procedure TProtocolDecorator.WriteSetEnd(); |
| 1181 | begin |
| 1182 | FWrappedProtocol.WriteSetEnd(); |
| 1183 | end; |
| 1184 | |
| 1185 | |
| 1186 | procedure TProtocolDecorator.WriteBool( b: Boolean); |
| 1187 | begin |
| 1188 | FWrappedProtocol.WriteBool( b); |
| 1189 | end; |
| 1190 | |
| 1191 | |
| 1192 | procedure TProtocolDecorator.WriteByte( b: ShortInt); |
| 1193 | begin |
| 1194 | FWrappedProtocol.WriteByte( b); |
| 1195 | end; |
| 1196 | |
| 1197 | |
| 1198 | procedure TProtocolDecorator.WriteI16( i16: SmallInt); |
| 1199 | begin |
| 1200 | FWrappedProtocol.WriteI16( i16); |
| 1201 | end; |
| 1202 | |
| 1203 | |
| 1204 | procedure TProtocolDecorator.WriteI32( i32: Integer); |
| 1205 | begin |
| 1206 | FWrappedProtocol.WriteI32( i32); |
| 1207 | end; |
| 1208 | |
| 1209 | |
| 1210 | procedure TProtocolDecorator.WriteI64( const i64: Int64); |
| 1211 | begin |
| 1212 | FWrappedProtocol.WriteI64( i64); |
| 1213 | end; |
| 1214 | |
| 1215 | |
| 1216 | procedure TProtocolDecorator.WriteDouble( const d: Double); |
| 1217 | begin |
| 1218 | FWrappedProtocol.WriteDouble( d); |
| 1219 | end; |
| 1220 | |
| 1221 | |
| 1222 | procedure TProtocolDecorator.WriteString( const s: string ); |
| 1223 | begin |
| 1224 | FWrappedProtocol.WriteString( s); |
| 1225 | end; |
| 1226 | |
| 1227 | |
| 1228 | procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString); |
| 1229 | begin |
| 1230 | FWrappedProtocol.WriteAnsiString( s); |
| 1231 | end; |
| 1232 | |
| 1233 | |
| 1234 | procedure TProtocolDecorator.WriteBinary( const b: TBytes); |
| 1235 | begin |
| 1236 | FWrappedProtocol.WriteBinary( b); |
| 1237 | end; |
| 1238 | |
| 1239 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1240 | function TProtocolDecorator.ReadMessageBegin: TThriftMessage; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1241 | begin |
| 1242 | result := FWrappedProtocol.ReadMessageBegin; |
| 1243 | end; |
| 1244 | |
| 1245 | |
| 1246 | procedure TProtocolDecorator.ReadMessageEnd(); |
| 1247 | begin |
| 1248 | FWrappedProtocol.ReadMessageEnd(); |
| 1249 | end; |
| 1250 | |
| 1251 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1252 | function TProtocolDecorator.ReadStructBegin: TThriftStruct; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1253 | begin |
| 1254 | result := FWrappedProtocol.ReadStructBegin; |
| 1255 | end; |
| 1256 | |
| 1257 | |
| 1258 | procedure TProtocolDecorator.ReadStructEnd; |
| 1259 | begin |
| 1260 | FWrappedProtocol.ReadStructEnd; |
| 1261 | end; |
| 1262 | |
| 1263 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1264 | function TProtocolDecorator.ReadFieldBegin: TThriftField; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1265 | begin |
| 1266 | result := FWrappedProtocol.ReadFieldBegin; |
| 1267 | end; |
| 1268 | |
| 1269 | |
| 1270 | procedure TProtocolDecorator.ReadFieldEnd(); |
| 1271 | begin |
| 1272 | FWrappedProtocol.ReadFieldEnd(); |
| 1273 | end; |
| 1274 | |
| 1275 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1276 | function TProtocolDecorator.ReadMapBegin: TThriftMap; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1277 | begin |
| 1278 | result := FWrappedProtocol.ReadMapBegin; |
| 1279 | end; |
| 1280 | |
| 1281 | |
| 1282 | procedure TProtocolDecorator.ReadMapEnd(); |
| 1283 | begin |
| 1284 | FWrappedProtocol.ReadMapEnd(); |
| 1285 | end; |
| 1286 | |
| 1287 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1288 | function TProtocolDecorator.ReadListBegin: TThriftList; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1289 | begin |
| 1290 | result := FWrappedProtocol.ReadListBegin; |
| 1291 | end; |
| 1292 | |
| 1293 | |
| 1294 | procedure TProtocolDecorator.ReadListEnd(); |
| 1295 | begin |
| 1296 | FWrappedProtocol.ReadListEnd(); |
| 1297 | end; |
| 1298 | |
| 1299 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1300 | function TProtocolDecorator.ReadSetBegin: TThriftSet; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1301 | begin |
| 1302 | result := FWrappedProtocol.ReadSetBegin; |
| 1303 | end; |
| 1304 | |
| 1305 | |
| 1306 | procedure TProtocolDecorator.ReadSetEnd(); |
| 1307 | begin |
| 1308 | FWrappedProtocol.ReadSetEnd(); |
| 1309 | end; |
| 1310 | |
| 1311 | |
| 1312 | function TProtocolDecorator.ReadBool: Boolean; |
| 1313 | begin |
| 1314 | result := FWrappedProtocol.ReadBool; |
| 1315 | end; |
| 1316 | |
| 1317 | |
| 1318 | function TProtocolDecorator.ReadByte: ShortInt; |
| 1319 | begin |
| 1320 | result := FWrappedProtocol.ReadByte; |
| 1321 | end; |
| 1322 | |
| 1323 | |
| 1324 | function TProtocolDecorator.ReadI16: SmallInt; |
| 1325 | begin |
| 1326 | result := FWrappedProtocol.ReadI16; |
| 1327 | end; |
| 1328 | |
| 1329 | |
| 1330 | function TProtocolDecorator.ReadI32: Integer; |
| 1331 | begin |
| 1332 | result := FWrappedProtocol.ReadI32; |
| 1333 | end; |
| 1334 | |
| 1335 | |
| 1336 | function TProtocolDecorator.ReadI64: Int64; |
| 1337 | begin |
| 1338 | result := FWrappedProtocol.ReadI64; |
| 1339 | end; |
| 1340 | |
| 1341 | |
| 1342 | function TProtocolDecorator.ReadDouble:Double; |
| 1343 | begin |
| 1344 | result := FWrappedProtocol.ReadDouble; |
| 1345 | end; |
| 1346 | |
| 1347 | |
| 1348 | function TProtocolDecorator.ReadBinary: TBytes; |
| 1349 | begin |
| 1350 | result := FWrappedProtocol.ReadBinary; |
| 1351 | end; |
| 1352 | |
| 1353 | |
| 1354 | function TProtocolDecorator.ReadString: string; |
| 1355 | begin |
| 1356 | result := FWrappedProtocol.ReadString; |
| 1357 | end; |
| 1358 | |
| 1359 | |
| 1360 | function TProtocolDecorator.ReadAnsiString: AnsiString; |
| 1361 | begin |
| 1362 | result := FWrappedProtocol.ReadAnsiString; |
| 1363 | end; |
| 1364 | |
| 1365 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1366 | { Init helper functions } |
| 1367 | |
| 1368 | procedure Init( var rec : TThriftMessage; const AName: string; const AMessageType: TMessageType; const ASeqID: Integer); |
| 1369 | begin |
| 1370 | rec.Name := AName; |
| 1371 | rec.Type_ := AMessageType; |
| 1372 | rec.SeqID := ASeqID; |
| 1373 | end; |
| 1374 | |
| 1375 | |
| 1376 | procedure Init( var rec : TThriftStruct; const AName: string = ''); |
| 1377 | begin |
| 1378 | rec.Name := AName; |
| 1379 | end; |
| 1380 | |
| 1381 | |
| 1382 | procedure Init( var rec : TThriftField; const AName: string; const AType: TType; const AID: SmallInt); |
| 1383 | begin |
| 1384 | rec.Name := AName; |
| 1385 | rec.Type_ := AType; |
| 1386 | rec.Id := AId; |
| 1387 | end; |
| 1388 | |
| 1389 | |
| 1390 | procedure Init( var rec : TThriftMap; const AKeyType, AValueType: TType; const ACount: Integer); |
| 1391 | begin |
| 1392 | rec.ValueType := AValueType; |
| 1393 | rec.KeyType := AKeyType; |
| 1394 | rec.Count := ACount; |
| 1395 | end; |
| 1396 | |
| 1397 | |
| 1398 | procedure Init( var rec : TThriftSet; const AElementType: TType; const ACount: Integer); |
| 1399 | begin |
| 1400 | rec.Count := ACount; |
| 1401 | rec.ElementType := AElementType; |
| 1402 | end; |
| 1403 | |
| 1404 | |
| 1405 | procedure Init( var rec : TThriftList; const AElementType: TType; const ACount: Integer); |
| 1406 | begin |
| 1407 | rec.Count := ACount; |
| 1408 | rec.ElementType := AElementType; |
| 1409 | end; |
| 1410 | |
| 1411 | |
| 1412 | |
| 1413 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1414 | |
| 1415 | end. |
| 1416 | |