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