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} |
Jens Geyer | 93222f6 | 2023-12-15 16:03:48 +0100 | [diff] [blame] | 21 | {$IFOPT M+} {$DEFINE TYPEINFO_WAS_ON} {$ELSE} {$UNDEF TYPEINFO_WAS_ON} {$ENDIF} |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 22 | |
| 23 | unit Thrift.Protocol; |
| 24 | |
| 25 | interface |
| 26 | |
| 27 | uses |
| 28 | Classes, |
| 29 | SysUtils, |
| 30 | Contnrs, |
Jens Geyer | 606f1ef | 2018-04-09 23:09:41 +0200 | [diff] [blame] | 31 | Thrift.Exception, |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 32 | Thrift.Stream, |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame] | 33 | Thrift.Utils, |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 34 | Thrift.Collections, |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 35 | Thrift.Configuration, |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 36 | Thrift.Transport; |
| 37 | |
| 38 | type |
| 39 | |
| 40 | TType = ( |
| 41 | Stop = 0, |
| 42 | Void = 1, |
| 43 | Bool_ = 2, |
| 44 | Byte_ = 3, |
| 45 | Double_ = 4, |
| 46 | I16 = 6, |
| 47 | I32 = 8, |
| 48 | I64 = 10, |
| 49 | String_ = 11, |
| 50 | Struct = 12, |
| 51 | Map = 13, |
| 52 | Set_ = 14, |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 53 | List = 15, |
| 54 | Uuid = 16 |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 55 | ); |
| 56 | |
| 57 | TMessageType = ( |
| 58 | Call = 1, |
| 59 | Reply = 2, |
| 60 | Exception = 3, |
| 61 | Oneway = 4 |
| 62 | ); |
| 63 | |
Jens Geyer | f0e6331 | 2015-03-01 18:47:49 +0100 | [diff] [blame] | 64 | const |
| 65 | VALID_TTYPES = [ |
| 66 | TType.Stop, TType.Void, |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 67 | TType.Bool_, TType.Byte_, TType.Double_, TType.I16, TType.I32, TType.I64, TType.String_, TType.Uuid, |
Jens Geyer | f0e6331 | 2015-03-01 18:47:49 +0100 | [diff] [blame] | 68 | TType.Struct, TType.Map, TType.Set_, TType.List |
| 69 | ]; |
| 70 | |
| 71 | VALID_MESSAGETYPES = [Low(TMessageType)..High(TMessageType)]; |
| 72 | |
| 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 | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 198 | IThriftBytes = interface; // forward |
| 199 | |
Jens Geyer | 5cf71b2 | 2023-12-18 11:44:55 +0100 | [diff] [blame] | 200 | {$TYPEINFO ON} |
| 201 | TThriftBytes = packed record // can't use SysUtils.TBytes because it has no typinfo -> E2134 |
| 202 | data : System.TArray<System.Byte>; |
| 203 | |
| 204 | class operator Implicit(aRec : SysUtils.TBytes) : TThriftBytes; |
| 205 | class operator Implicit(aRec : TThriftBytes) : SysUtils.TBytes; |
| 206 | function Length : Integer; |
| 207 | end; |
| 208 | {$IFNDEF TYPEINFO_WAS_ON} {$TYPEINFO OFF} {$ENDIF} |
| 209 | |
| 210 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 211 | IProtocol = interface |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 212 | ['{6067A28E-15BF-4C9D-9A6F-D991BB3DCB85}'] |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 213 | function GetTransport: ITransport; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 214 | procedure WriteMessageBegin( const msg: TThriftMessage); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 215 | procedure WriteMessageEnd; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 216 | procedure WriteStructBegin( const struc: TThriftStruct); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 217 | procedure WriteStructEnd; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 218 | procedure WriteFieldBegin( const field: TThriftField); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 219 | procedure WriteFieldEnd; |
| 220 | procedure WriteFieldStop; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 221 | procedure WriteMapBegin( const map: TThriftMap); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 222 | procedure WriteMapEnd; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 223 | procedure WriteListBegin( const list: TThriftList); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 224 | procedure WriteListEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 225 | procedure WriteSetBegin( const set_: TThriftSet ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 226 | procedure WriteSetEnd(); |
| 227 | procedure WriteBool( b: Boolean); |
| 228 | procedure WriteByte( b: ShortInt); |
| 229 | procedure WriteI16( i16: SmallInt); |
| 230 | procedure WriteI32( i32: Integer); |
| 231 | procedure WriteI64( const i64: Int64); |
| 232 | procedure WriteDouble( const d: Double); |
| 233 | procedure WriteString( const s: string ); |
| 234 | procedure WriteAnsiString( const s: AnsiString); |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 235 | procedure WriteBinary( const b: TBytes); overload; |
| 236 | procedure WriteBinary( const b: IThriftBytes); overload; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 237 | procedure WriteUuid( const uuid: TGuid); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 238 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 239 | function ReadMessageBegin: TThriftMessage; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 240 | procedure ReadMessageEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 241 | function ReadStructBegin: TThriftStruct; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 242 | procedure ReadStructEnd; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 243 | function ReadFieldBegin: TThriftField; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 244 | procedure ReadFieldEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 245 | function ReadMapBegin: TThriftMap; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 246 | procedure ReadMapEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 247 | function ReadListBegin: TThriftList; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 248 | procedure ReadListEnd(); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 249 | function ReadSetBegin: TThriftSet; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 250 | procedure ReadSetEnd(); |
| 251 | function ReadBool: Boolean; |
| 252 | function ReadByte: ShortInt; |
| 253 | function ReadI16: SmallInt; |
| 254 | function ReadI32: Integer; |
| 255 | function ReadI64: Int64; |
| 256 | function ReadDouble:Double; |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 257 | function ReadBinary: TBytes; // IMPORTANT: this is NOT safe across module boundaries |
| 258 | function ReadBinaryCOM : IThriftBytes; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 259 | function ReadUuid: TGuid; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 260 | function ReadString: string; |
| 261 | function ReadAnsiString: AnsiString; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 262 | |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 263 | function NextRecursionLevel : IProtocolRecursionTracker; |
| 264 | procedure IncrementRecursionDepth; |
| 265 | procedure DecrementRecursionDepth; |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 266 | function GetMinSerializedSize( const aType : TType) : Integer; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 267 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 268 | property Transport: ITransport read GetTransport; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 269 | function Configuration : IThriftConfiguration; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 270 | end; |
| 271 | |
Jens Geyer | 3b68653 | 2021-07-01 23:04:08 +0200 | [diff] [blame] | 272 | TProtocolImplClass = class of TProtocolImpl; |
| 273 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 274 | TProtocolImpl = class abstract( TInterfacedObject, IProtocol) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 275 | strict protected |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 276 | FTrans : ITransport; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 277 | FRecursionLimit : Integer; |
| 278 | FRecursionDepth : Integer; |
| 279 | |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 280 | function NextRecursionLevel : IProtocolRecursionTracker; |
| 281 | procedure IncrementRecursionDepth; |
| 282 | procedure DecrementRecursionDepth; |
| 283 | |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 284 | function GetMinSerializedSize( const aType : TType) : Integer; virtual; abstract; |
| 285 | procedure CheckReadBytesAvailable( const value : TThriftList); overload; inline; |
| 286 | procedure CheckReadBytesAvailable( const value : TThriftSet); overload; inline; |
| 287 | procedure CheckReadBytesAvailable( const value : TThriftMap); overload; inline; |
| 288 | |
| 289 | procedure Reset; virtual; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 290 | function GetTransport: ITransport; |
| 291 | function Configuration : IThriftConfiguration; |
| 292 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 293 | procedure WriteMessageBegin( const msg: TThriftMessage); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 294 | procedure WriteMessageEnd; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 295 | procedure WriteStructBegin( const struc: TThriftStruct); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 296 | procedure WriteStructEnd; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 297 | procedure WriteFieldBegin( const field: TThriftField); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 298 | procedure WriteFieldEnd; virtual; abstract; |
| 299 | procedure WriteFieldStop; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 300 | procedure WriteMapBegin( const map: TThriftMap); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 301 | procedure WriteMapEnd; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 302 | procedure WriteListBegin( const list: TThriftList); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 303 | procedure WriteListEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 304 | procedure WriteSetBegin( const set_: TThriftSet ); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 305 | procedure WriteSetEnd(); virtual; abstract; |
| 306 | procedure WriteBool( b: Boolean); virtual; abstract; |
| 307 | procedure WriteByte( b: ShortInt); virtual; abstract; |
| 308 | procedure WriteI16( i16: SmallInt); virtual; abstract; |
| 309 | procedure WriteI32( i32: Integer); virtual; abstract; |
| 310 | procedure WriteI64( const i64: Int64); virtual; abstract; |
| 311 | procedure WriteDouble( const d: Double); virtual; abstract; |
| 312 | procedure WriteString( const s: string ); virtual; |
| 313 | procedure WriteAnsiString( const s: AnsiString); virtual; |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 314 | procedure WriteBinary( const b: TBytes); overload; virtual; abstract; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 315 | procedure WriteUuid( const b: TGuid); virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 316 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 317 | function ReadMessageBegin: TThriftMessage; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 318 | procedure ReadMessageEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 319 | function ReadStructBegin: TThriftStruct; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 320 | procedure ReadStructEnd; virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 321 | function ReadFieldBegin: TThriftField; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 322 | procedure ReadFieldEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 323 | function ReadMapBegin: TThriftMap; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 324 | procedure ReadMapEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 325 | function ReadListBegin: TThriftList; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 326 | procedure ReadListEnd(); virtual; abstract; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 327 | function ReadSetBegin: TThriftSet; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 328 | procedure ReadSetEnd(); virtual; abstract; |
| 329 | function ReadBool: Boolean; virtual; abstract; |
| 330 | function ReadByte: ShortInt; virtual; abstract; |
| 331 | function ReadI16: SmallInt; virtual; abstract; |
| 332 | function ReadI32: Integer; virtual; abstract; |
| 333 | function ReadI64: Int64; virtual; abstract; |
| 334 | function ReadDouble:Double; virtual; abstract; |
| 335 | function ReadBinary: TBytes; virtual; abstract; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 336 | function ReadUuid: TGuid; virtual; abstract; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 337 | function ReadString: string; virtual; |
| 338 | function ReadAnsiString: AnsiString; virtual; |
| 339 | |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 340 | // provide generic implementation for all derived classes |
| 341 | procedure WriteBinary( const bytes : IThriftBytes); overload; virtual; |
| 342 | function ReadBinaryCOM : IThriftBytes; virtual; |
| 343 | |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 344 | property Transport: ITransport read GetTransport; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 345 | |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 346 | public |
Jens Geyer | 3b68653 | 2021-07-01 23:04:08 +0200 | [diff] [blame] | 347 | constructor Create( const aTransport : ITransport); virtual; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 348 | end; |
| 349 | |
Jens Geyer | 5cf71b2 | 2023-12-18 11:44:55 +0100 | [diff] [blame] | 350 | {.$TYPEINFO ON} // big NO -> may cause E2134 due to Delphis stupidity on enums vs TypeInfo |
Jens Geyer | 93222f6 | 2023-12-15 16:03:48 +0100 | [diff] [blame] | 351 | {$RTTI EXPLICIT METHODS([vcPublic, vcPublished]) PROPERTIES([vcPublic, vcPublished])} |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame] | 352 | IBase = interface( ISupportsToString) |
| 353 | ['{AFF6CECA-5200-4540-950E-9B89E0C1C00C}'] |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 354 | procedure Read( const prot: IProtocol); |
| 355 | procedure Write( const prot: IProtocol); |
| 356 | end; |
Jens Geyer | 5cf71b2 | 2023-12-18 11:44:55 +0100 | [diff] [blame] | 357 | |
| 358 | {$TYPEINFO ON} |
| 359 | {$RTTI EXPLICIT METHODS([vcPublic, vcPublished]) PROPERTIES([vcPublic, vcPublished])} |
| 360 | IBaseWithTypeInfo = interface( IBase) end; |
| 361 | |
Jens Geyer | 93222f6 | 2023-12-15 16:03:48 +0100 | [diff] [blame] | 362 | {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} |
| 363 | {$IFNDEF TYPEINFO_WAS_ON} {$TYPEINFO OFF} {$ENDIF} |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 364 | |
| 365 | |
| 366 | IThriftBytes = interface( ISupportsToString) |
| 367 | ['{CDBEF7E8-BEF2-4A0A-983A-F334E3FF0016}'] |
| 368 | function GetCount : Integer; |
| 369 | procedure SetCount(const value : Integer); |
| 370 | |
| 371 | // WARNING: This returns a direct pointer to the underlying data structure |
| 372 | function QueryRawDataPtr : Pointer; |
| 373 | |
| 374 | property Count : Integer read GetCount write SetCount; |
| 375 | end; |
| 376 | |
| 377 | |
| 378 | TThriftBytesImpl = class( TInterfacedObject, IThriftBytes, ISupportsToString) |
| 379 | strict private |
| 380 | FData : TBytes; |
| 381 | |
| 382 | strict protected |
| 383 | function GetCount : Integer; |
| 384 | procedure SetCount(const value : Integer); |
| 385 | function QueryRawDataPtr : Pointer; |
| 386 | |
| 387 | public |
| 388 | constructor Create; overload; |
| 389 | constructor Create( const bytes : TBytes); overload; |
| 390 | constructor Create( var bytes : TBytes; const aTakeOwnership : Boolean = FALSE); overload; |
| 391 | |
| 392 | function ToString : string; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 393 | end; |
| 394 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 395 | |
| 396 | TBinaryProtocolImpl = class( TProtocolImpl ) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 397 | strict protected |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 398 | const |
| 399 | VERSION_MASK : Cardinal = $ffff0000; |
| 400 | VERSION_1 : Cardinal = $80010000; |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 401 | strict protected |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 402 | FStrictRead : Boolean; |
| 403 | FStrictWrite : Boolean; |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 404 | function GetMinSerializedSize( const aType : TType) : Integer; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 405 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 406 | strict private |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 407 | 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] | 408 | function ReadStringBody( size: Integer): string; |
| 409 | |
| 410 | public |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 411 | type |
| 412 | TFactory = class( TInterfacedObject, IProtocolFactory) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 413 | strict protected |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 414 | FStrictRead : Boolean; |
| 415 | FStrictWrite : Boolean; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 416 | function GetProtocol( const trans: ITransport): IProtocol; |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 417 | public |
| 418 | constructor Create( const aStrictRead : Boolean = FALSE; const aStrictWrite: Boolean = TRUE); reintroduce; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 419 | end; |
| 420 | |
Jens Geyer | 3b68653 | 2021-07-01 23:04:08 +0200 | [diff] [blame] | 421 | constructor Create( const trans: ITransport); overload; override; |
| 422 | constructor Create( const trans: ITransport; strictRead, strictWrite: Boolean); reintroduce; overload; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 423 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 424 | procedure WriteMessageBegin( const msg: TThriftMessage); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 425 | procedure WriteMessageEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 426 | procedure WriteStructBegin( const struc: TThriftStruct); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 427 | procedure WriteStructEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 428 | procedure WriteFieldBegin( const field: TThriftField); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 429 | procedure WriteFieldEnd; override; |
| 430 | procedure WriteFieldStop; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 431 | procedure WriteMapBegin( const map: TThriftMap); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 432 | procedure WriteMapEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 433 | procedure WriteListBegin( const list: TThriftList); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 434 | procedure WriteListEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 435 | procedure WriteSetBegin( const set_: TThriftSet ); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 436 | procedure WriteSetEnd(); override; |
| 437 | procedure WriteBool( b: Boolean); override; |
| 438 | procedure WriteByte( b: ShortInt); override; |
| 439 | procedure WriteI16( i16: SmallInt); override; |
| 440 | procedure WriteI32( i32: Integer); override; |
| 441 | procedure WriteI64( const i64: Int64); override; |
| 442 | procedure WriteDouble( const d: Double); override; |
| 443 | procedure WriteBinary( const b: TBytes); override; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 444 | procedure WriteUuid( const uuid: TGuid); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 445 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 446 | function ReadMessageBegin: TThriftMessage; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 447 | procedure ReadMessageEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 448 | function ReadStructBegin: TThriftStruct; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 449 | procedure ReadStructEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 450 | function ReadFieldBegin: TThriftField; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 451 | procedure ReadFieldEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 452 | function ReadMapBegin: TThriftMap; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 453 | procedure ReadMapEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 454 | function ReadListBegin: TThriftList; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 455 | procedure ReadListEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 456 | function ReadSetBegin: TThriftSet; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 457 | procedure ReadSetEnd(); override; |
| 458 | function ReadBool: Boolean; override; |
| 459 | function ReadByte: ShortInt; override; |
| 460 | function ReadI16: SmallInt; override; |
| 461 | function ReadI32: Integer; override; |
| 462 | function ReadI64: Int64; override; |
| 463 | function ReadDouble:Double; override; |
| 464 | function ReadBinary: TBytes; override; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 465 | function ReadUuid: TGuid; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 466 | |
| 467 | end; |
| 468 | |
| 469 | |
| 470 | { TProtocolDecorator forwards all requests to an enclosed TProtocol instance, |
| 471 | providing a way to author concise concrete decorator subclasses. The decorator |
| 472 | does not (and should not) modify the behaviour of the enclosed TProtocol |
| 473 | |
| 474 | See p.175 of Design Patterns (by Gamma et al.) |
| 475 | } |
| 476 | TProtocolDecorator = class( TProtocolImpl) |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 477 | strict private |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 478 | FWrappedProtocol : IProtocol; |
| 479 | |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 480 | strict protected |
| 481 | function GetMinSerializedSize( const aType : TType) : Integer; override; |
| 482 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 483 | public |
| 484 | // Encloses the specified protocol. |
| 485 | // All operations will be forward to the given protocol. Must be non-null. |
Jens Geyer | 3b68653 | 2021-07-01 23:04:08 +0200 | [diff] [blame] | 486 | constructor Create( const aProtocol : IProtocol); reintroduce; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 487 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 488 | procedure WriteMessageBegin( const msg: TThriftMessage); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 489 | procedure WriteMessageEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 490 | procedure WriteStructBegin( const struc: TThriftStruct); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 491 | procedure WriteStructEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 492 | procedure WriteFieldBegin( const field: TThriftField); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 493 | procedure WriteFieldEnd; override; |
| 494 | procedure WriteFieldStop; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 495 | procedure WriteMapBegin( const map: TThriftMap); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 496 | procedure WriteMapEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 497 | procedure WriteListBegin( const list: TThriftList); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 498 | procedure WriteListEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 499 | procedure WriteSetBegin( const set_: TThriftSet ); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 500 | procedure WriteSetEnd(); override; |
| 501 | procedure WriteBool( b: Boolean); override; |
| 502 | procedure WriteByte( b: ShortInt); override; |
| 503 | procedure WriteI16( i16: SmallInt); override; |
| 504 | procedure WriteI32( i32: Integer); override; |
| 505 | procedure WriteI64( const i64: Int64); override; |
| 506 | procedure WriteDouble( const d: Double); override; |
| 507 | procedure WriteString( const s: string ); override; |
| 508 | procedure WriteAnsiString( const s: AnsiString); override; |
| 509 | procedure WriteBinary( const b: TBytes); override; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 510 | procedure WriteUuid( const uuid: TGuid); override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 511 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 512 | function ReadMessageBegin: TThriftMessage; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 513 | procedure ReadMessageEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 514 | function ReadStructBegin: TThriftStruct; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 515 | procedure ReadStructEnd; override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 516 | function ReadFieldBegin: TThriftField; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 517 | procedure ReadFieldEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 518 | function ReadMapBegin: TThriftMap; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 519 | procedure ReadMapEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 520 | function ReadListBegin: TThriftList; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 521 | procedure ReadListEnd(); override; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 522 | function ReadSetBegin: TThriftSet; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 523 | procedure ReadSetEnd(); override; |
| 524 | function ReadBool: Boolean; override; |
| 525 | function ReadByte: ShortInt; override; |
| 526 | function ReadI16: SmallInt; override; |
| 527 | function ReadI32: Integer; override; |
| 528 | function ReadI64: Int64; override; |
| 529 | function ReadDouble:Double; override; |
| 530 | function ReadBinary: TBytes; override; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 531 | function ReadUuid: TGuid; override; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 532 | function ReadString: string; override; |
| 533 | function ReadAnsiString: AnsiString; override; |
| 534 | end; |
| 535 | |
| 536 | |
| 537 | type |
| 538 | IRequestEvents = interface |
Jens Geyer | 0164040 | 2013-09-25 21:12:21 +0200 | [diff] [blame] | 539 | ['{F926A26A-5B00-4560-86FA-2CAE3BA73DAF}'] |
| 540 | // Called before reading arguments. |
| 541 | procedure PreRead; |
| 542 | // Called between reading arguments and calling the handler. |
| 543 | procedure PostRead; |
| 544 | // Called between calling the handler and writing the response. |
| 545 | procedure PreWrite; |
| 546 | // Called after writing the response. |
| 547 | procedure PostWrite; |
| 548 | // Called when an oneway (async) function call completes successfully. |
| 549 | procedure OnewayComplete; |
| 550 | // Called if the handler throws an undeclared exception. |
| 551 | procedure UnhandledError( const e : Exception); |
| 552 | // Called when a client has finished request-handling to clean up |
| 553 | procedure CleanupContext; |
| 554 | end; |
| 555 | |
| 556 | |
| 557 | IProcessorEvents = interface |
| 558 | ['{A8661119-657C-447D-93C5-512E36162A45}'] |
| 559 | // Called when a client is about to call the processor. |
| 560 | procedure Processing( const transport : ITransport); |
| 561 | // Called on any service function invocation |
| 562 | function CreateRequestContext( const aFunctionName : string) : IRequestEvents; |
| 563 | // Called when a client has finished request-handling to clean up |
| 564 | procedure CleanupContext; |
| 565 | end; |
| 566 | |
| 567 | |
| 568 | IProcessor = interface |
| 569 | ['{7BAE92A5-46DA-4F13-B6EA-0EABE233EE5F}'] |
Jens Geyer | d430bbd | 2013-09-26 23:37:54 +0200 | [diff] [blame] | 570 | 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] | 571 | end; |
| 572 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 573 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 574 | procedure Init( var rec : TThriftMessage; const AName: string = ''; const AMessageType: TMessageType = Low(TMessageType); const ASeqID: Integer = 0); overload; inline; |
| 575 | procedure Init( var rec : TThriftStruct; const AName: string = ''); overload; inline; |
| 576 | procedure Init( var rec : TThriftField; const AName: string = ''; const AType: TType = Low(TType); const AID: SmallInt = 0); overload; inline; |
| 577 | procedure Init( var rec : TThriftMap; const AKeyType: TType = Low(TType); const AValueType: TType = Low(TType); const ACount: Integer = 0); overload; inline; |
| 578 | procedure Init( var rec : TThriftSet; const AElementType: TType = Low(TType); const ACount: Integer = 0); overload; inline; |
| 579 | procedure Init( var rec : TThriftList; const AElementType: TType = Low(TType); const ACount: Integer = 0); overload; inline; |
| 580 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 581 | |
| 582 | implementation |
| 583 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 584 | function ConvertInt64ToDouble( const n: Int64): Double; inline; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 585 | begin |
| 586 | ASSERT( SizeOf(n) = SizeOf(Result)); |
| 587 | System.Move( n, Result, SizeOf(Result)); |
| 588 | end; |
| 589 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 590 | function ConvertDoubleToInt64( const d: Double): Int64; inline; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 591 | begin |
| 592 | ASSERT( SizeOf(d) = SizeOf(Result)); |
| 593 | System.Move( d, Result, SizeOf(Result)); |
| 594 | end; |
| 595 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 596 | |
Jens Geyer | 5cf71b2 | 2023-12-18 11:44:55 +0100 | [diff] [blame] | 597 | //--- TThriftBytes ---------------------------------------------------------------------- |
| 598 | |
| 599 | |
| 600 | class operator TThriftBytes.Implicit(aRec : SysUtils.TBytes) : TThriftBytes; |
| 601 | begin |
| 602 | ASSERT( @result.data = @result); // must be first field |
| 603 | ASSERT( SizeOf(aRec) = SizeOf(result)); // must be the only field |
| 604 | result := TThriftBytes(aRec); |
| 605 | end; |
| 606 | |
| 607 | |
| 608 | class operator TThriftBytes.Implicit(aRec : TThriftBytes) : SysUtils.TBytes; |
| 609 | begin |
| 610 | ASSERT( @aRec.data = @aRec); // must be first field |
| 611 | ASSERT( SizeOf(aRec) = SizeOf(result)); // must be the only field |
| 612 | result := SysUtils.TBytes(aRec.data); |
| 613 | end; |
| 614 | |
| 615 | |
| 616 | function TThriftBytes.Length : Integer; |
| 617 | begin |
| 618 | result := System.Length(data); |
| 619 | end; |
| 620 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 621 | |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 622 | { TProtocolRecursionTrackerImpl } |
| 623 | |
| 624 | constructor TProtocolRecursionTrackerImpl.Create( prot : IProtocol); |
| 625 | begin |
| 626 | inherited Create; |
| 627 | |
| 628 | // storing the pointer *after* the (successful) increment is important here |
| 629 | prot.IncrementRecursionDepth; |
| 630 | FProtocol := prot; |
| 631 | end; |
| 632 | |
| 633 | destructor TProtocolRecursionTrackerImpl.Destroy; |
| 634 | begin |
| 635 | try |
| 636 | // we have to release the reference iff the pointer has been stored |
| 637 | if FProtocol <> nil then begin |
| 638 | FProtocol.DecrementRecursionDepth; |
| 639 | FProtocol := nil; |
| 640 | end; |
| 641 | finally |
| 642 | inherited Destroy; |
| 643 | end; |
| 644 | end; |
| 645 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 646 | { TProtocolImpl } |
| 647 | |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 648 | constructor TProtocolImpl.Create( const aTransport : ITransport); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 649 | begin |
| 650 | inherited Create; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 651 | FTrans := aTransport; |
| 652 | FRecursionLimit := aTransport.Configuration.RecursionLimit; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 653 | FRecursionDepth := 0; |
| 654 | end; |
| 655 | |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 656 | function TProtocolImpl.NextRecursionLevel : IProtocolRecursionTracker; |
| 657 | begin |
| 658 | result := TProtocolRecursionTrackerImpl.Create(Self); |
| 659 | end; |
| 660 | |
| 661 | procedure TProtocolImpl.IncrementRecursionDepth; |
| 662 | begin |
| 663 | if FRecursionDepth < FRecursionLimit |
| 664 | then Inc(FRecursionDepth) |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 665 | else raise TProtocolExceptionDepthLimit.Create('Depth limit exceeded'); |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 666 | end; |
| 667 | |
| 668 | procedure TProtocolImpl.DecrementRecursionDepth; |
| 669 | begin |
| 670 | Dec(FRecursionDepth) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 671 | end; |
| 672 | |
| 673 | function TProtocolImpl.GetTransport: ITransport; |
| 674 | begin |
| 675 | Result := FTrans; |
| 676 | end; |
| 677 | |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 678 | function TProtocolImpl.Configuration : IThriftConfiguration; |
| 679 | begin |
| 680 | Result := FTrans.Configuration; |
| 681 | end; |
| 682 | |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 683 | procedure TProtocolImpl.Reset; |
| 684 | begin |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 685 | FTrans.ResetConsumedMessageSize; |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 686 | end; |
| 687 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 688 | function TProtocolImpl.ReadAnsiString: AnsiString; |
| 689 | var |
| 690 | b : TBytes; |
| 691 | len : Integer; |
| 692 | begin |
| 693 | Result := ''; |
| 694 | b := ReadBinary; |
| 695 | len := Length( b ); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 696 | if len > 0 then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 697 | SetLength( Result, len); |
| 698 | System.Move( b[0], Pointer(Result)^, len ); |
| 699 | end; |
| 700 | end; |
| 701 | |
| 702 | function TProtocolImpl.ReadString: string; |
| 703 | begin |
| 704 | Result := TEncoding.UTF8.GetString( ReadBinary ); |
| 705 | end; |
| 706 | |
| 707 | procedure TProtocolImpl.WriteAnsiString(const s: AnsiString); |
| 708 | var |
| 709 | b : TBytes; |
| 710 | len : Integer; |
| 711 | begin |
| 712 | len := Length(s); |
| 713 | SetLength( b, len); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 714 | if len > 0 then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 715 | System.Move( Pointer(s)^, b[0], len ); |
| 716 | end; |
| 717 | WriteBinary( b ); |
| 718 | end; |
| 719 | |
| 720 | procedure TProtocolImpl.WriteString(const s: string); |
| 721 | var |
| 722 | b : TBytes; |
| 723 | begin |
| 724 | b := TEncoding.UTF8.GetBytes(s); |
| 725 | WriteBinary( b ); |
| 726 | end; |
| 727 | |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 728 | |
| 729 | procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftList); |
| 730 | begin |
| 731 | FTrans.CheckReadBytesAvailable( value.Count * GetMinSerializedSize(value.ElementType)); |
| 732 | end; |
| 733 | |
| 734 | |
| 735 | procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftSet); |
| 736 | begin |
| 737 | FTrans.CheckReadBytesAvailable( value.Count * GetMinSerializedSize(value.ElementType)); |
| 738 | end; |
| 739 | |
| 740 | |
| 741 | procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftMap); |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 742 | var nPairSize : Integer; |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 743 | begin |
| 744 | nPairSize := GetMinSerializedSize(value.KeyType) + GetMinSerializedSize(value.ValueType); |
| 745 | FTrans.CheckReadBytesAvailable( value.Count * nPairSize); |
| 746 | end; |
| 747 | |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 748 | |
| 749 | procedure TProtocolImpl.WriteBinary( const bytes : IThriftBytes); |
| 750 | var tmp : TBytes; |
| 751 | begin |
| 752 | SetLength( tmp, bytes.Count); |
| 753 | if Length(tmp) > 0 |
| 754 | then Move( bytes.QueryRawDataPtr^, tmp[0], Length(tmp)); |
| 755 | WriteBinary( tmp); |
| 756 | end; |
| 757 | |
| 758 | |
| 759 | function TProtocolImpl.ReadBinaryCOM : IThriftBytes; |
| 760 | var bytes : TBytes; |
| 761 | begin |
| 762 | bytes := ReadBinary; |
| 763 | result := TThriftBytesImpl.Create(bytes,TRUE); |
| 764 | end; |
| 765 | |
| 766 | |
| 767 | { TThriftBytesImpl } |
| 768 | |
| 769 | constructor TThriftBytesImpl.Create; |
| 770 | begin |
| 771 | inherited Create; |
| 772 | ASSERT( Length(FData) = 0); |
| 773 | end; |
| 774 | |
| 775 | |
| 776 | constructor TThriftBytesImpl.Create( const bytes : TBytes); |
| 777 | begin |
| 778 | FData := bytes; // copies the data |
| 779 | end; |
| 780 | |
| 781 | |
| 782 | constructor TThriftBytesImpl.Create( var bytes : TBytes; const aTakeOwnership : Boolean); |
| 783 | |
| 784 | procedure SwapPointer( var one, two); |
| 785 | var |
| 786 | pOne : Pointer absolute one; |
| 787 | pTwo : Pointer absolute two; |
| 788 | pTmp : Pointer; |
| 789 | begin |
| 790 | pTmp := pOne; |
| 791 | pOne := pTwo; |
| 792 | pTwo := pTmp; |
| 793 | end; |
| 794 | |
| 795 | begin |
| 796 | inherited Create; |
| 797 | ASSERT( Length(FData) = 0); |
| 798 | |
| 799 | if aTakeOwnership |
| 800 | then SwapPointer( FData, bytes) |
| 801 | else FData := bytes; // copies the data |
| 802 | end; |
| 803 | |
| 804 | |
| 805 | function TThriftBytesImpl.ToString : string; |
| 806 | var sb : TThriftStringBuilder; |
| 807 | begin |
| 808 | sb := TThriftStringBuilder.Create(); |
| 809 | try |
| 810 | sb.Append('Bin: '); |
| 811 | sb.Append( FData); |
| 812 | |
| 813 | result := sb.ToString; |
| 814 | finally |
| 815 | sb.Free; |
| 816 | end; |
| 817 | end; |
| 818 | |
| 819 | |
| 820 | function TThriftBytesImpl.GetCount : Integer; |
| 821 | begin |
| 822 | result := Length(FData); |
| 823 | end; |
| 824 | |
| 825 | |
| 826 | procedure TThriftBytesImpl.SetCount(const value : Integer); |
| 827 | begin |
| 828 | SetLength( FData, value); |
| 829 | end; |
| 830 | |
| 831 | |
| 832 | function TThriftBytesImpl.QueryRawDataPtr : Pointer; |
| 833 | begin |
| 834 | result := FData; |
| 835 | end; |
| 836 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 837 | { TProtocolUtil } |
| 838 | |
| 839 | class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 840 | var field : TThriftField; |
| 841 | map : TThriftMap; |
| 842 | set_ : TThriftSet; |
| 843 | list : TThriftList; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 844 | i : Integer; |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 845 | tracker : IProtocolRecursionTracker; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 846 | begin |
Jens Geyer | d47fcdd | 2015-07-09 22:05:18 +0200 | [diff] [blame] | 847 | tracker := prot.NextRecursionLevel; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 848 | case type_ of |
| 849 | // simple types |
| 850 | TType.Bool_ : prot.ReadBool(); |
| 851 | TType.Byte_ : prot.ReadByte(); |
| 852 | TType.I16 : prot.ReadI16(); |
| 853 | TType.I32 : prot.ReadI32(); |
| 854 | TType.I64 : prot.ReadI64(); |
| 855 | TType.Double_ : prot.ReadDouble(); |
| 856 | TType.String_ : prot.ReadBinary();// Don't try to decode the string, just skip it. |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 857 | TType.Uuid : prot.ReadUuid(); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 858 | |
| 859 | // structured types |
| 860 | TType.Struct : begin |
| 861 | prot.ReadStructBegin(); |
| 862 | while TRUE do begin |
| 863 | field := prot.ReadFieldBegin(); |
| 864 | if (field.Type_ = TType.Stop) then Break; |
| 865 | Skip(prot, field.Type_); |
| 866 | prot.ReadFieldEnd(); |
| 867 | end; |
| 868 | prot.ReadStructEnd(); |
| 869 | end; |
| 870 | |
| 871 | TType.Map : begin |
| 872 | map := prot.ReadMapBegin(); |
| 873 | for i := 0 to map.Count-1 do begin |
| 874 | Skip(prot, map.KeyType); |
| 875 | Skip(prot, map.ValueType); |
| 876 | end; |
| 877 | prot.ReadMapEnd(); |
| 878 | end; |
| 879 | |
| 880 | TType.Set_ : begin |
| 881 | set_ := prot.ReadSetBegin(); |
| 882 | for i := 0 to set_.Count-1 |
| 883 | do Skip( prot, set_.ElementType); |
| 884 | prot.ReadSetEnd(); |
| 885 | end; |
| 886 | |
| 887 | TType.List : begin |
| 888 | list := prot.ReadListBegin(); |
| 889 | for i := 0 to list.Count-1 |
| 890 | do Skip( prot, list.ElementType); |
| 891 | prot.ReadListEnd(); |
| 892 | end; |
| 893 | |
| 894 | else |
Jens Geyer | 5f723cd | 2017-01-10 21:57:48 +0100 | [diff] [blame] | 895 | raise TProtocolExceptionInvalidData.Create('Unexpected type '+IntToStr(Ord(type_))); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 896 | end; |
| 897 | end; |
| 898 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 899 | |
| 900 | { TBinaryProtocolImpl } |
| 901 | |
Jens Geyer | 3b68653 | 2021-07-01 23:04:08 +0200 | [diff] [blame] | 902 | constructor TBinaryProtocolImpl.Create( const trans: ITransport); |
| 903 | begin |
| 904 | // call the real CTOR |
| 905 | Self.Create( trans, FALSE, TRUE); |
| 906 | end; |
| 907 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 908 | constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead, strictWrite: Boolean); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 909 | begin |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 910 | inherited Create( trans); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 911 | FStrictRead := strictRead; |
| 912 | FStrictWrite := strictWrite; |
| 913 | end; |
| 914 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 915 | 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] | 916 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 917 | Result := FTrans.ReadAll( pBuf, buflen, off, len ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 918 | end; |
| 919 | |
| 920 | function TBinaryProtocolImpl.ReadBinary: TBytes; |
| 921 | var |
| 922 | size : Integer; |
| 923 | buf : TBytes; |
| 924 | begin |
| 925 | size := ReadI32; |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 926 | FTrans.CheckReadBytesAvailable( size); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 927 | SetLength( buf, size); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 928 | FTrans.ReadAll( buf, 0, size); |
| 929 | Result := buf; |
| 930 | end; |
| 931 | |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 932 | function TBinaryProtocolImpl.ReadUuid : TGuid; |
| 933 | var network : TGuid; // in network order (Big Endian) |
| 934 | begin |
| 935 | ASSERT( SizeOf(result) = 16); |
| 936 | FTrans.ReadAll( @network, SizeOf(network), 0, SizeOf(network)); |
Jens Geyer | f8f6278 | 2022-09-10 00:55:02 +0200 | [diff] [blame] | 937 | result := GuidUtils.SwapByteOrder(network); |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 938 | end; |
| 939 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 940 | function TBinaryProtocolImpl.ReadBool: Boolean; |
| 941 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 942 | Result := (ReadByte = 1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 943 | end; |
| 944 | |
| 945 | function TBinaryProtocolImpl.ReadByte: ShortInt; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 946 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 947 | ReadAll( @result, SizeOf(result), 0, 1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 948 | end; |
| 949 | |
| 950 | function TBinaryProtocolImpl.ReadDouble: Double; |
| 951 | begin |
| 952 | Result := ConvertInt64ToDouble( ReadI64 ) |
| 953 | end; |
| 954 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 955 | function TBinaryProtocolImpl.ReadFieldBegin: TThriftField; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 956 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 957 | Init( result, '', TType( ReadByte), 0); |
| 958 | if ( result.Type_ <> TType.Stop ) then begin |
| 959 | result.Id := ReadI16; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 960 | end; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 961 | end; |
| 962 | |
| 963 | procedure TBinaryProtocolImpl.ReadFieldEnd; |
| 964 | begin |
| 965 | |
| 966 | end; |
| 967 | |
| 968 | function TBinaryProtocolImpl.ReadI16: SmallInt; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 969 | var i16in : packed array[0..1] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 970 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 971 | ReadAll( @i16in, Sizeof(i16in), 0, 2); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 972 | Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF)); |
| 973 | end; |
| 974 | |
| 975 | function TBinaryProtocolImpl.ReadI32: Integer; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 976 | var i32in : packed array[0..3] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 977 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 978 | ReadAll( @i32in, SizeOf(i32in), 0, 4); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 979 | |
| 980 | Result := Integer( |
| 981 | ((i32in[0] and $FF) shl 24) or |
| 982 | ((i32in[1] and $FF) shl 16) or |
| 983 | ((i32in[2] and $FF) shl 8) or |
| 984 | (i32in[3] and $FF)); |
| 985 | |
| 986 | end; |
| 987 | |
| 988 | function TBinaryProtocolImpl.ReadI64: Int64; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 989 | var i64in : packed array[0..7] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 990 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 991 | ReadAll( @i64in, SizeOf(i64in), 0, 8); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 992 | Result := |
| 993 | (Int64( i64in[0] and $FF) shl 56) or |
| 994 | (Int64( i64in[1] and $FF) shl 48) or |
| 995 | (Int64( i64in[2] and $FF) shl 40) or |
| 996 | (Int64( i64in[3] and $FF) shl 32) or |
| 997 | (Int64( i64in[4] and $FF) shl 24) or |
| 998 | (Int64( i64in[5] and $FF) shl 16) or |
| 999 | (Int64( i64in[6] and $FF) shl 8) or |
| 1000 | (Int64( i64in[7] and $FF)); |
| 1001 | end; |
| 1002 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1003 | function TBinaryProtocolImpl.ReadListBegin: TThriftList; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1004 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1005 | result.ElementType := TType(ReadByte); |
| 1006 | result.Count := ReadI32; |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1007 | CheckReadBytesAvailable(result); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1008 | end; |
| 1009 | |
| 1010 | procedure TBinaryProtocolImpl.ReadListEnd; |
| 1011 | begin |
| 1012 | |
| 1013 | end; |
| 1014 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1015 | function TBinaryProtocolImpl.ReadMapBegin: TThriftMap; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1016 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1017 | result.KeyType := TType(ReadByte); |
| 1018 | result.ValueType := TType(ReadByte); |
| 1019 | result.Count := ReadI32; |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1020 | CheckReadBytesAvailable(result); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1021 | end; |
| 1022 | |
| 1023 | procedure TBinaryProtocolImpl.ReadMapEnd; |
| 1024 | begin |
| 1025 | |
| 1026 | end; |
| 1027 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1028 | function TBinaryProtocolImpl.ReadMessageBegin: TThriftMessage; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1029 | var |
| 1030 | size : Integer; |
| 1031 | version : Integer; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1032 | begin |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1033 | Reset; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1034 | Init( result); |
Jens Geyer | 589ee5b | 2021-03-29 21:40:55 +0200 | [diff] [blame] | 1035 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1036 | size := ReadI32; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1037 | if (size < 0) then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1038 | version := size and Integer( VERSION_MASK); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1039 | if ( version <> Integer( VERSION_1)) then begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1040 | raise TProtocolExceptionBadVersion.Create('Bad version in ReadMessageBegin: ' + IntToStr(version) ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1041 | end; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1042 | result.Type_ := TMessageType( size and $000000ff); |
| 1043 | result.Name := ReadString; |
| 1044 | result.SeqID := ReadI32; |
Jens Geyer | 589ee5b | 2021-03-29 21:40:55 +0200 | [diff] [blame] | 1045 | Exit; |
| 1046 | end; |
| 1047 | |
| 1048 | try |
| 1049 | if FStrictRead |
| 1050 | then raise TProtocolExceptionBadVersion.Create('Missing version in readMessageBegin, old client?' ); |
| 1051 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1052 | result.Name := ReadStringBody( size ); |
| 1053 | result.Type_ := TMessageType( ReadByte ); |
| 1054 | result.SeqID := ReadI32; |
Jens Geyer | 589ee5b | 2021-03-29 21:40:55 +0200 | [diff] [blame] | 1055 | except |
| 1056 | if CharUtils.IsHtmlDoctype(size) |
| 1057 | then raise TProtocolExceptionInvalidData.Create('Remote end sends HTML instead of data') |
| 1058 | else raise; // something else |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1059 | end; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1060 | end; |
| 1061 | |
| 1062 | procedure TBinaryProtocolImpl.ReadMessageEnd; |
| 1063 | begin |
| 1064 | inherited; |
| 1065 | |
| 1066 | end; |
| 1067 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1068 | function TBinaryProtocolImpl.ReadSetBegin: TThriftSet; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1069 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1070 | result.ElementType := TType(ReadByte); |
| 1071 | result.Count := ReadI32; |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1072 | CheckReadBytesAvailable(result); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1073 | end; |
| 1074 | |
| 1075 | procedure TBinaryProtocolImpl.ReadSetEnd; |
| 1076 | begin |
| 1077 | |
| 1078 | end; |
| 1079 | |
| 1080 | function TBinaryProtocolImpl.ReadStringBody( size: Integer): string; |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1081 | var buf : TBytes; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1082 | begin |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1083 | FTrans.CheckReadBytesAvailable( size); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1084 | SetLength( buf, size); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1085 | FTrans.ReadAll( buf, 0, size ); |
| 1086 | Result := TEncoding.UTF8.GetString( buf); |
| 1087 | end; |
| 1088 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1089 | function TBinaryProtocolImpl.ReadStructBegin: TThriftStruct; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1090 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1091 | Init( Result); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1092 | end; |
| 1093 | |
| 1094 | procedure TBinaryProtocolImpl.ReadStructEnd; |
| 1095 | begin |
| 1096 | inherited; |
| 1097 | |
| 1098 | end; |
| 1099 | |
| 1100 | procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes); |
| 1101 | var iLen : Integer; |
| 1102 | begin |
| 1103 | iLen := Length(b); |
| 1104 | WriteI32( iLen); |
| 1105 | if iLen > 0 then FTrans.Write(b, 0, iLen); |
| 1106 | end; |
| 1107 | |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 1108 | procedure TBinaryProtocolImpl.WriteUuid( const uuid: TGuid); |
| 1109 | var network : TGuid; // in network order (Big Endian) |
| 1110 | begin |
| 1111 | ASSERT( SizeOf(uuid) = 16); |
Jens Geyer | f8f6278 | 2022-09-10 00:55:02 +0200 | [diff] [blame] | 1112 | network := GuidUtils.SwapByteOrder(uuid); |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 1113 | Transport.Write( @network, 0, SizeOf(network)); |
| 1114 | end; |
| 1115 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1116 | procedure TBinaryProtocolImpl.WriteBool(b: Boolean); |
| 1117 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1118 | if b then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1119 | WriteByte( 1 ); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1120 | end else begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1121 | WriteByte( 0 ); |
| 1122 | end; |
| 1123 | end; |
| 1124 | |
| 1125 | procedure TBinaryProtocolImpl.WriteByte(b: ShortInt); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1126 | begin |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1127 | FTrans.Write( @b, 0, 1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1128 | end; |
| 1129 | |
| 1130 | procedure TBinaryProtocolImpl.WriteDouble( const d: Double); |
| 1131 | begin |
| 1132 | WriteI64(ConvertDoubleToInt64(d)); |
| 1133 | end; |
| 1134 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1135 | procedure TBinaryProtocolImpl.WriteFieldBegin( const field: TThriftField); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1136 | begin |
| 1137 | WriteByte(ShortInt(field.Type_)); |
| 1138 | WriteI16(field.ID); |
| 1139 | end; |
| 1140 | |
| 1141 | procedure TBinaryProtocolImpl.WriteFieldEnd; |
| 1142 | begin |
| 1143 | |
| 1144 | end; |
| 1145 | |
| 1146 | procedure TBinaryProtocolImpl.WriteFieldStop; |
| 1147 | begin |
| 1148 | WriteByte(ShortInt(TType.Stop)); |
| 1149 | end; |
| 1150 | |
| 1151 | procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1152 | var i16out : packed array[0..1] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1153 | begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1154 | i16out[0] := Byte($FF and (i16 shr 8)); |
| 1155 | i16out[1] := Byte($FF and i16); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1156 | FTrans.Write( @i16out, 0, 2); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1157 | end; |
| 1158 | |
| 1159 | procedure TBinaryProtocolImpl.WriteI32(i32: Integer); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1160 | var i32out : packed array[0..3] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1161 | begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1162 | i32out[0] := Byte($FF and (i32 shr 24)); |
| 1163 | i32out[1] := Byte($FF and (i32 shr 16)); |
| 1164 | i32out[2] := Byte($FF and (i32 shr 8)); |
| 1165 | i32out[3] := Byte($FF and i32); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1166 | FTrans.Write( @i32out, 0, 4); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1167 | end; |
| 1168 | |
| 1169 | procedure TBinaryProtocolImpl.WriteI64( const i64: Int64); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1170 | var i64out : packed array[0..7] of Byte; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1171 | begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1172 | i64out[0] := Byte($FF and (i64 shr 56)); |
| 1173 | i64out[1] := Byte($FF and (i64 shr 48)); |
| 1174 | i64out[2] := Byte($FF and (i64 shr 40)); |
| 1175 | i64out[3] := Byte($FF and (i64 shr 32)); |
| 1176 | i64out[4] := Byte($FF and (i64 shr 24)); |
| 1177 | i64out[5] := Byte($FF and (i64 shr 16)); |
| 1178 | i64out[6] := Byte($FF and (i64 shr 8)); |
| 1179 | i64out[7] := Byte($FF and i64); |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1180 | FTrans.Write( @i64out, 0, 8); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1181 | end; |
| 1182 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1183 | procedure TBinaryProtocolImpl.WriteListBegin( const list: TThriftList); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1184 | begin |
| 1185 | WriteByte(ShortInt(list.ElementType)); |
| 1186 | WriteI32(list.Count); |
| 1187 | end; |
| 1188 | |
| 1189 | procedure TBinaryProtocolImpl.WriteListEnd; |
| 1190 | begin |
| 1191 | |
| 1192 | end; |
| 1193 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1194 | procedure TBinaryProtocolImpl.WriteMapBegin( const map: TThriftMap); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1195 | begin |
| 1196 | WriteByte(ShortInt(map.KeyType)); |
| 1197 | WriteByte(ShortInt(map.ValueType)); |
| 1198 | WriteI32(map.Count); |
| 1199 | end; |
| 1200 | |
| 1201 | procedure TBinaryProtocolImpl.WriteMapEnd; |
| 1202 | begin |
| 1203 | |
| 1204 | end; |
| 1205 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1206 | procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: TThriftMessage); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1207 | var version : Cardinal; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1208 | begin |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1209 | Reset; |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1210 | if FStrictWrite then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1211 | version := VERSION_1 or Cardinal( msg.Type_); |
| 1212 | WriteI32( Integer( version) ); |
| 1213 | WriteString( msg.Name); |
| 1214 | WriteI32( msg.SeqID); |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1215 | end else begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1216 | WriteString( msg.Name); |
| 1217 | WriteByte(ShortInt( msg.Type_)); |
| 1218 | WriteI32( msg.SeqID); |
| 1219 | end; |
| 1220 | end; |
| 1221 | |
| 1222 | procedure TBinaryProtocolImpl.WriteMessageEnd; |
| 1223 | begin |
| 1224 | |
| 1225 | end; |
| 1226 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1227 | procedure TBinaryProtocolImpl.WriteSetBegin( const set_: TThriftSet); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1228 | begin |
| 1229 | WriteByte(ShortInt(set_.ElementType)); |
| 1230 | WriteI32(set_.Count); |
| 1231 | end; |
| 1232 | |
| 1233 | procedure TBinaryProtocolImpl.WriteSetEnd; |
| 1234 | begin |
| 1235 | |
| 1236 | end; |
| 1237 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1238 | procedure TBinaryProtocolImpl.WriteStructBegin( const struc: TThriftStruct); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1239 | begin |
| 1240 | |
| 1241 | end; |
| 1242 | |
| 1243 | procedure TBinaryProtocolImpl.WriteStructEnd; |
| 1244 | begin |
| 1245 | |
| 1246 | end; |
| 1247 | |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1248 | function TBinaryProtocolImpl.GetMinSerializedSize( const aType : TType) : Integer; |
| 1249 | // Return the minimum number of bytes a type will consume on the wire |
| 1250 | begin |
| 1251 | case aType of |
| 1252 | TType.Stop: result := 0; |
| 1253 | TType.Void: result := 0; |
| 1254 | TType.Bool_: result := SizeOf(Byte); |
| 1255 | TType.Byte_: result := SizeOf(Byte); |
| 1256 | TType.Double_: result := SizeOf(Double); |
| 1257 | TType.I16: result := SizeOf(Int16); |
| 1258 | TType.I32: result := SizeOf(Int32); |
| 1259 | TType.I64: result := SizeOf(Int64); |
| 1260 | TType.String_: result := SizeOf(Int32); // string length |
| 1261 | TType.Struct: result := 0; // empty struct |
| 1262 | TType.Map: result := SizeOf(Int32); // element count |
| 1263 | TType.Set_: result := SizeOf(Int32); // element count |
| 1264 | TType.List: result := SizeOf(Int32); // element count |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 1265 | TType.Uuid: result := SizeOf(TGuid); |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1266 | else |
| 1267 | raise TTransportExceptionBadArgs.Create('Unhandled type code'); |
| 1268 | end; |
| 1269 | end; |
| 1270 | |
| 1271 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1272 | { TProtocolException } |
| 1273 | |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1274 | constructor TProtocolException.HiddenCreate(const Msg: string); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1275 | begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1276 | inherited Create(Msg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1277 | end; |
| 1278 | |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1279 | class function TProtocolException.Create(const Msg: string): TProtocolException; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1280 | begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1281 | Result := TProtocolExceptionUnknown.Create(Msg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1282 | end; |
| 1283 | |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1284 | class function TProtocolException.Create: TProtocolException; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1285 | begin |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1286 | Result := TProtocolExceptionUnknown.Create(''); |
| 1287 | end; |
| 1288 | |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1289 | class function TProtocolException.Create(aType: TExceptionType): TProtocolException; |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1290 | begin |
| 1291 | {$WARN SYMBOL_DEPRECATED OFF} |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1292 | Result := Create(aType, ''); |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1293 | {$WARN SYMBOL_DEPRECATED DEFAULT} |
| 1294 | end; |
| 1295 | |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1296 | class function TProtocolException.Create(aType: TExceptionType; const msg: string): TProtocolException; |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1297 | begin |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1298 | case aType of |
| 1299 | TExceptionType.INVALID_DATA: Result := TProtocolExceptionInvalidData.Create(msg); |
| 1300 | TExceptionType.NEGATIVE_SIZE: Result := TProtocolExceptionNegativeSize.Create(msg); |
| 1301 | TExceptionType.SIZE_LIMIT: Result := TProtocolExceptionSizeLimit.Create(msg); |
| 1302 | TExceptionType.BAD_VERSION: Result := TProtocolExceptionBadVersion.Create(msg); |
| 1303 | TExceptionType.NOT_IMPLEMENTED: Result := TProtocolExceptionNotImplemented.Create(msg); |
| 1304 | TExceptionType.DEPTH_LIMIT: Result := TProtocolExceptionDepthLimit.Create(msg); |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1305 | else |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1306 | ASSERT( TExceptionType.UNKNOWN = aType); |
Jens Geyer | e0e3240 | 2016-04-20 21:50:48 +0200 | [diff] [blame] | 1307 | Result := TProtocolExceptionUnknown.Create(msg); |
| 1308 | end; |
| 1309 | end; |
| 1310 | |
| 1311 | { TProtocolExceptionSpecialized } |
| 1312 | |
| 1313 | constructor TProtocolExceptionSpecialized.Create(const Msg: string); |
| 1314 | begin |
| 1315 | inherited HiddenCreate(Msg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1316 | end; |
| 1317 | |
Jens Geyer | 9f11c1e | 2019-11-09 19:39:20 +0100 | [diff] [blame] | 1318 | { specialized TProtocolExceptions } |
| 1319 | |
| 1320 | class function TProtocolExceptionUnknown.GetType: TProtocolException.TExceptionType; |
| 1321 | begin |
| 1322 | result := TExceptionType.UNKNOWN; |
| 1323 | end; |
| 1324 | |
| 1325 | class function TProtocolExceptionInvalidData.GetType: TProtocolException.TExceptionType; |
| 1326 | begin |
| 1327 | result := TExceptionType.INVALID_DATA; |
| 1328 | end; |
| 1329 | |
| 1330 | class function TProtocolExceptionNegativeSize.GetType: TProtocolException.TExceptionType; |
| 1331 | begin |
| 1332 | result := TExceptionType.NEGATIVE_SIZE; |
| 1333 | end; |
| 1334 | |
| 1335 | class function TProtocolExceptionSizeLimit.GetType: TProtocolException.TExceptionType; |
| 1336 | begin |
| 1337 | result := TExceptionType.SIZE_LIMIT; |
| 1338 | end; |
| 1339 | |
| 1340 | class function TProtocolExceptionBadVersion.GetType: TProtocolException.TExceptionType; |
| 1341 | begin |
| 1342 | result := TExceptionType.BAD_VERSION; |
| 1343 | end; |
| 1344 | |
| 1345 | class function TProtocolExceptionNotImplemented.GetType: TProtocolException.TExceptionType; |
| 1346 | begin |
| 1347 | result := TExceptionType.NOT_IMPLEMENTED; |
| 1348 | end; |
| 1349 | |
| 1350 | class function TProtocolExceptionDepthLimit.GetType: TProtocolException.TExceptionType; |
| 1351 | begin |
| 1352 | result := TExceptionType.DEPTH_LIMIT; |
| 1353 | end; |
| 1354 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1355 | { TBinaryProtocolImpl.TFactory } |
| 1356 | |
Jens Geyer | fad7fd3 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1357 | constructor TBinaryProtocolImpl.TFactory.Create( const aStrictRead, aStrictWrite: Boolean); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1358 | begin |
| 1359 | inherited Create; |
| 1360 | FStrictRead := AStrictRead; |
| 1361 | FStrictWrite := AStrictWrite; |
| 1362 | end; |
| 1363 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1364 | function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol; |
| 1365 | begin |
| 1366 | Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite); |
| 1367 | end; |
| 1368 | |
| 1369 | |
| 1370 | { TProtocolDecorator } |
| 1371 | |
| 1372 | constructor TProtocolDecorator.Create( const aProtocol : IProtocol); |
| 1373 | begin |
| 1374 | ASSERT( aProtocol <> nil); |
| 1375 | inherited Create( aProtocol.Transport); |
| 1376 | FWrappedProtocol := aProtocol; |
| 1377 | end; |
| 1378 | |
| 1379 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1380 | procedure TProtocolDecorator.WriteMessageBegin( const msg: TThriftMessage); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1381 | begin |
| 1382 | FWrappedProtocol.WriteMessageBegin( msg); |
| 1383 | end; |
| 1384 | |
| 1385 | |
| 1386 | procedure TProtocolDecorator.WriteMessageEnd; |
| 1387 | begin |
| 1388 | FWrappedProtocol.WriteMessageEnd; |
| 1389 | end; |
| 1390 | |
| 1391 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1392 | procedure TProtocolDecorator.WriteStructBegin( const struc: TThriftStruct); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1393 | begin |
| 1394 | FWrappedProtocol.WriteStructBegin( struc); |
| 1395 | end; |
| 1396 | |
| 1397 | |
| 1398 | procedure TProtocolDecorator.WriteStructEnd; |
| 1399 | begin |
| 1400 | FWrappedProtocol.WriteStructEnd; |
| 1401 | end; |
| 1402 | |
| 1403 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1404 | procedure TProtocolDecorator.WriteFieldBegin( const field: TThriftField); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1405 | begin |
| 1406 | FWrappedProtocol.WriteFieldBegin( field); |
| 1407 | end; |
| 1408 | |
| 1409 | |
| 1410 | procedure TProtocolDecorator.WriteFieldEnd; |
| 1411 | begin |
| 1412 | FWrappedProtocol.WriteFieldEnd; |
| 1413 | end; |
| 1414 | |
| 1415 | |
| 1416 | procedure TProtocolDecorator.WriteFieldStop; |
| 1417 | begin |
| 1418 | FWrappedProtocol.WriteFieldStop; |
| 1419 | end; |
| 1420 | |
| 1421 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1422 | procedure TProtocolDecorator.WriteMapBegin( const map: TThriftMap); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1423 | begin |
| 1424 | FWrappedProtocol.WriteMapBegin( map); |
| 1425 | end; |
| 1426 | |
| 1427 | |
| 1428 | procedure TProtocolDecorator.WriteMapEnd; |
| 1429 | begin |
| 1430 | FWrappedProtocol.WriteMapEnd; |
| 1431 | end; |
| 1432 | |
| 1433 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1434 | procedure TProtocolDecorator.WriteListBegin( const list: TThriftList); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1435 | begin |
| 1436 | FWrappedProtocol.WriteListBegin( list); |
| 1437 | end; |
| 1438 | |
| 1439 | |
| 1440 | procedure TProtocolDecorator.WriteListEnd(); |
| 1441 | begin |
| 1442 | FWrappedProtocol.WriteListEnd(); |
| 1443 | end; |
| 1444 | |
| 1445 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1446 | procedure TProtocolDecorator.WriteSetBegin( const set_: TThriftSet ); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1447 | begin |
| 1448 | FWrappedProtocol.WriteSetBegin( set_); |
| 1449 | end; |
| 1450 | |
| 1451 | |
| 1452 | procedure TProtocolDecorator.WriteSetEnd(); |
| 1453 | begin |
| 1454 | FWrappedProtocol.WriteSetEnd(); |
| 1455 | end; |
| 1456 | |
| 1457 | |
| 1458 | procedure TProtocolDecorator.WriteBool( b: Boolean); |
| 1459 | begin |
| 1460 | FWrappedProtocol.WriteBool( b); |
| 1461 | end; |
| 1462 | |
| 1463 | |
| 1464 | procedure TProtocolDecorator.WriteByte( b: ShortInt); |
| 1465 | begin |
| 1466 | FWrappedProtocol.WriteByte( b); |
| 1467 | end; |
| 1468 | |
| 1469 | |
| 1470 | procedure TProtocolDecorator.WriteI16( i16: SmallInt); |
| 1471 | begin |
| 1472 | FWrappedProtocol.WriteI16( i16); |
| 1473 | end; |
| 1474 | |
| 1475 | |
| 1476 | procedure TProtocolDecorator.WriteI32( i32: Integer); |
| 1477 | begin |
| 1478 | FWrappedProtocol.WriteI32( i32); |
| 1479 | end; |
| 1480 | |
| 1481 | |
| 1482 | procedure TProtocolDecorator.WriteI64( const i64: Int64); |
| 1483 | begin |
| 1484 | FWrappedProtocol.WriteI64( i64); |
| 1485 | end; |
| 1486 | |
| 1487 | |
| 1488 | procedure TProtocolDecorator.WriteDouble( const d: Double); |
| 1489 | begin |
| 1490 | FWrappedProtocol.WriteDouble( d); |
| 1491 | end; |
| 1492 | |
| 1493 | |
| 1494 | procedure TProtocolDecorator.WriteString( const s: string ); |
| 1495 | begin |
| 1496 | FWrappedProtocol.WriteString( s); |
| 1497 | end; |
| 1498 | |
| 1499 | |
| 1500 | procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString); |
| 1501 | begin |
| 1502 | FWrappedProtocol.WriteAnsiString( s); |
| 1503 | end; |
| 1504 | |
| 1505 | |
| 1506 | procedure TProtocolDecorator.WriteBinary( const b: TBytes); |
| 1507 | begin |
| 1508 | FWrappedProtocol.WriteBinary( b); |
| 1509 | end; |
| 1510 | |
| 1511 | |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 1512 | procedure TProtocolDecorator.WriteUuid( const uuid: TGuid); |
| 1513 | begin |
| 1514 | FWrappedProtocol.WriteUuid( uuid); |
| 1515 | end; |
| 1516 | |
| 1517 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1518 | function TProtocolDecorator.ReadMessageBegin: TThriftMessage; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1519 | begin |
| 1520 | result := FWrappedProtocol.ReadMessageBegin; |
| 1521 | end; |
| 1522 | |
| 1523 | |
| 1524 | procedure TProtocolDecorator.ReadMessageEnd(); |
| 1525 | begin |
| 1526 | FWrappedProtocol.ReadMessageEnd(); |
| 1527 | end; |
| 1528 | |
| 1529 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1530 | function TProtocolDecorator.ReadStructBegin: TThriftStruct; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1531 | begin |
| 1532 | result := FWrappedProtocol.ReadStructBegin; |
| 1533 | end; |
| 1534 | |
| 1535 | |
| 1536 | procedure TProtocolDecorator.ReadStructEnd; |
| 1537 | begin |
| 1538 | FWrappedProtocol.ReadStructEnd; |
| 1539 | end; |
| 1540 | |
| 1541 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1542 | function TProtocolDecorator.ReadFieldBegin: TThriftField; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1543 | begin |
| 1544 | result := FWrappedProtocol.ReadFieldBegin; |
| 1545 | end; |
| 1546 | |
| 1547 | |
| 1548 | procedure TProtocolDecorator.ReadFieldEnd(); |
| 1549 | begin |
| 1550 | FWrappedProtocol.ReadFieldEnd(); |
| 1551 | end; |
| 1552 | |
| 1553 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1554 | function TProtocolDecorator.ReadMapBegin: TThriftMap; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1555 | begin |
| 1556 | result := FWrappedProtocol.ReadMapBegin; |
| 1557 | end; |
| 1558 | |
| 1559 | |
| 1560 | procedure TProtocolDecorator.ReadMapEnd(); |
| 1561 | begin |
| 1562 | FWrappedProtocol.ReadMapEnd(); |
| 1563 | end; |
| 1564 | |
| 1565 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1566 | function TProtocolDecorator.ReadListBegin: TThriftList; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1567 | begin |
| 1568 | result := FWrappedProtocol.ReadListBegin; |
| 1569 | end; |
| 1570 | |
| 1571 | |
| 1572 | procedure TProtocolDecorator.ReadListEnd(); |
| 1573 | begin |
| 1574 | FWrappedProtocol.ReadListEnd(); |
| 1575 | end; |
| 1576 | |
| 1577 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1578 | function TProtocolDecorator.ReadSetBegin: TThriftSet; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1579 | begin |
| 1580 | result := FWrappedProtocol.ReadSetBegin; |
| 1581 | end; |
| 1582 | |
| 1583 | |
| 1584 | procedure TProtocolDecorator.ReadSetEnd(); |
| 1585 | begin |
| 1586 | FWrappedProtocol.ReadSetEnd(); |
| 1587 | end; |
| 1588 | |
| 1589 | |
| 1590 | function TProtocolDecorator.ReadBool: Boolean; |
| 1591 | begin |
| 1592 | result := FWrappedProtocol.ReadBool; |
| 1593 | end; |
| 1594 | |
| 1595 | |
| 1596 | function TProtocolDecorator.ReadByte: ShortInt; |
| 1597 | begin |
| 1598 | result := FWrappedProtocol.ReadByte; |
| 1599 | end; |
| 1600 | |
| 1601 | |
| 1602 | function TProtocolDecorator.ReadI16: SmallInt; |
| 1603 | begin |
| 1604 | result := FWrappedProtocol.ReadI16; |
| 1605 | end; |
| 1606 | |
| 1607 | |
| 1608 | function TProtocolDecorator.ReadI32: Integer; |
| 1609 | begin |
| 1610 | result := FWrappedProtocol.ReadI32; |
| 1611 | end; |
| 1612 | |
| 1613 | |
| 1614 | function TProtocolDecorator.ReadI64: Int64; |
| 1615 | begin |
| 1616 | result := FWrappedProtocol.ReadI64; |
| 1617 | end; |
| 1618 | |
| 1619 | |
| 1620 | function TProtocolDecorator.ReadDouble:Double; |
| 1621 | begin |
| 1622 | result := FWrappedProtocol.ReadDouble; |
| 1623 | end; |
| 1624 | |
| 1625 | |
| 1626 | function TProtocolDecorator.ReadBinary: TBytes; |
| 1627 | begin |
| 1628 | result := FWrappedProtocol.ReadBinary; |
| 1629 | end; |
| 1630 | |
| 1631 | |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 1632 | function TProtocolDecorator.ReadUuid: TGuid; |
| 1633 | begin |
| 1634 | result := FWrappedProtocol.ReadUuid; |
| 1635 | end; |
| 1636 | |
| 1637 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1638 | function TProtocolDecorator.ReadString: string; |
| 1639 | begin |
| 1640 | result := FWrappedProtocol.ReadString; |
| 1641 | end; |
| 1642 | |
| 1643 | |
| 1644 | function TProtocolDecorator.ReadAnsiString: AnsiString; |
| 1645 | begin |
| 1646 | result := FWrappedProtocol.ReadAnsiString; |
| 1647 | end; |
| 1648 | |
| 1649 | |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1650 | function TProtocolDecorator.GetMinSerializedSize( const aType : TType) : Integer; |
| 1651 | begin |
| 1652 | result := FWrappedProtocol.GetMinSerializedSize(aType); |
| 1653 | end; |
| 1654 | |
| 1655 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1656 | { Init helper functions } |
| 1657 | |
| 1658 | procedure Init( var rec : TThriftMessage; const AName: string; const AMessageType: TMessageType; const ASeqID: Integer); |
| 1659 | begin |
| 1660 | rec.Name := AName; |
| 1661 | rec.Type_ := AMessageType; |
| 1662 | rec.SeqID := ASeqID; |
| 1663 | end; |
| 1664 | |
| 1665 | |
| 1666 | procedure Init( var rec : TThriftStruct; const AName: string = ''); |
| 1667 | begin |
| 1668 | rec.Name := AName; |
| 1669 | end; |
| 1670 | |
| 1671 | |
| 1672 | procedure Init( var rec : TThriftField; const AName: string; const AType: TType; const AID: SmallInt); |
| 1673 | begin |
| 1674 | rec.Name := AName; |
| 1675 | rec.Type_ := AType; |
| 1676 | rec.Id := AId; |
| 1677 | end; |
| 1678 | |
| 1679 | |
| 1680 | procedure Init( var rec : TThriftMap; const AKeyType, AValueType: TType; const ACount: Integer); |
| 1681 | begin |
| 1682 | rec.ValueType := AValueType; |
| 1683 | rec.KeyType := AKeyType; |
| 1684 | rec.Count := ACount; |
| 1685 | end; |
| 1686 | |
| 1687 | |
| 1688 | procedure Init( var rec : TThriftSet; const AElementType: TType; const ACount: Integer); |
| 1689 | begin |
| 1690 | rec.Count := ACount; |
| 1691 | rec.ElementType := AElementType; |
| 1692 | end; |
| 1693 | |
| 1694 | |
| 1695 | procedure Init( var rec : TThriftList; const AElementType: TType; const ACount: Integer); |
| 1696 | begin |
| 1697 | rec.Count := ACount; |
| 1698 | rec.ElementType := AElementType; |
| 1699 | end; |
| 1700 | |
| 1701 | |
| 1702 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 1703 | end. |
| 1704 | |