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