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