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;
|
| 373 | FReadLength : Integer;
|
| 374 | FCheckReadLength : Boolean;
|
| 375 |
|
| 376 | private
|
| 377 | function ReadAll( var buf: TBytes; off: Integer; len: Integer ): Integer;
|
| 378 | function ReadStringBody( size: Integer): string;
|
| 379 | procedure CheckReadLength( len: Integer );
|
| 380 | public
|
| 381 |
|
| 382 | type
|
| 383 | TFactory = class( TInterfacedObject, IProtocolFactory)
|
| 384 | protected
|
| 385 | FStrictRead : Boolean;
|
| 386 | FStrictWrite : Boolean;
|
| 387 | public
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 388 | function GetProtocol( const trans: ITransport): IProtocol;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 389 | constructor Create( AStrictRead, AStrictWrite: Boolean ); overload;
|
| 390 | constructor Create; overload;
|
| 391 | end;
|
| 392 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 393 | constructor Create( const trans: ITransport); overload;
|
| 394 | constructor Create( const trans: ITransport; strictRead: Boolean; strictWrite: Boolean); overload;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 395 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 396 | procedure WriteMessageBegin( const msg: IMessage); override;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 397 | procedure WriteMessageEnd; override;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 398 | procedure WriteStructBegin( const struc: IStruct); override;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 399 | procedure WriteStructEnd; override;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 400 | procedure WriteFieldBegin( const field: IField); override;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 401 | procedure WriteFieldEnd; override;
|
| 402 | procedure WriteFieldStop; override;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 403 | procedure WriteMapBegin( const map: IMap); override;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 404 | procedure WriteMapEnd; override;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 405 | procedure WriteListBegin( const list: IList); override;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 406 | procedure WriteListEnd(); override;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 407 | procedure WriteSetBegin( const set_: ISet ); override;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 408 | procedure WriteSetEnd(); override;
|
| 409 | procedure WriteBool( b: Boolean); override;
|
| 410 | procedure WriteByte( b: ShortInt); override;
|
| 411 | procedure WriteI16( i16: SmallInt); override;
|
| 412 | procedure WriteI32( i32: Integer); override;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 413 | procedure WriteI64( const i64: Int64); override;
|
| 414 | procedure WriteDouble( const d: Double); override;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 415 | procedure WriteBinary( const b: TBytes); override;
|
| 416 |
|
| 417 | function ReadMessageBegin: IMessage; override;
|
| 418 | procedure ReadMessageEnd(); override;
|
| 419 | function ReadStructBegin: IStruct; override;
|
| 420 | procedure ReadStructEnd; override;
|
| 421 | function ReadFieldBegin: IField; override;
|
| 422 | procedure ReadFieldEnd(); override;
|
| 423 | function ReadMapBegin: IMap; override;
|
| 424 | procedure ReadMapEnd(); override;
|
| 425 | function ReadListBegin: IList; override;
|
| 426 | procedure ReadListEnd(); override;
|
| 427 | function ReadSetBegin: ISet; override;
|
| 428 | procedure ReadSetEnd(); override;
|
| 429 | function ReadBool: Boolean; override;
|
| 430 | function ReadByte: ShortInt; override;
|
| 431 | function ReadI16: SmallInt; override;
|
| 432 | function ReadI32: Integer; override;
|
| 433 | function ReadI64: Int64; override;
|
| 434 | function ReadDouble:Double; override;
|
| 435 | function ReadBinary: TBytes; override;
|
| 436 |
|
| 437 | procedure SetReadLength( readLength: Integer );
|
| 438 | end;
|
| 439 |
|
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame^] | 440 |
|
| 441 | { TProtocolDecorator forwards all requests to an enclosed TProtocol instance,
|
| 442 | providing a way to author concise concrete decorator subclasses. The decorator
|
| 443 | does not (and should not) modify the behaviour of the enclosed TProtocol
|
| 444 |
|
| 445 | See p.175 of Design Patterns (by Gamma et al.)
|
| 446 | }
|
| 447 | TProtocolDecorator = class( TProtocolImpl)
|
| 448 | private
|
| 449 | FWrappedProtocol : IProtocol;
|
| 450 |
|
| 451 | public
|
| 452 | // Encloses the specified protocol.
|
| 453 | // All operations will be forward to the given protocol. Must be non-null.
|
| 454 | constructor Create( const aProtocol : IProtocol);
|
| 455 |
|
| 456 | procedure WriteMessageBegin( const msg: IMessage); override;
|
| 457 | procedure WriteMessageEnd; override;
|
| 458 | procedure WriteStructBegin( const struc: IStruct); override;
|
| 459 | procedure WriteStructEnd; override;
|
| 460 | procedure WriteFieldBegin( const field: IField); override;
|
| 461 | procedure WriteFieldEnd; override;
|
| 462 | procedure WriteFieldStop; override;
|
| 463 | procedure WriteMapBegin( const map: IMap); override;
|
| 464 | procedure WriteMapEnd; override;
|
| 465 | procedure WriteListBegin( const list: IList); override;
|
| 466 | procedure WriteListEnd(); override;
|
| 467 | procedure WriteSetBegin( const set_: ISet ); override;
|
| 468 | procedure WriteSetEnd(); override;
|
| 469 | procedure WriteBool( b: Boolean); override;
|
| 470 | procedure WriteByte( b: ShortInt); override;
|
| 471 | procedure WriteI16( i16: SmallInt); override;
|
| 472 | procedure WriteI32( i32: Integer); override;
|
| 473 | procedure WriteI64( const i64: Int64); override;
|
| 474 | procedure WriteDouble( const d: Double); override;
|
| 475 | procedure WriteString( const s: string ); override;
|
| 476 | procedure WriteAnsiString( const s: AnsiString); override;
|
| 477 | procedure WriteBinary( const b: TBytes); override;
|
| 478 |
|
| 479 | function ReadMessageBegin: IMessage; override;
|
| 480 | procedure ReadMessageEnd(); override;
|
| 481 | function ReadStructBegin: IStruct; override;
|
| 482 | procedure ReadStructEnd; override;
|
| 483 | function ReadFieldBegin: IField; override;
|
| 484 | procedure ReadFieldEnd(); override;
|
| 485 | function ReadMapBegin: IMap; override;
|
| 486 | procedure ReadMapEnd(); override;
|
| 487 | function ReadListBegin: IList; override;
|
| 488 | procedure ReadListEnd(); override;
|
| 489 | function ReadSetBegin: ISet; override;
|
| 490 | procedure ReadSetEnd(); override;
|
| 491 | function ReadBool: Boolean; override;
|
| 492 | function ReadByte: ShortInt; override;
|
| 493 | function ReadI16: SmallInt; override;
|
| 494 | function ReadI32: Integer; override;
|
| 495 | function ReadI64: Int64; override;
|
| 496 | function ReadDouble:Double; override;
|
| 497 | function ReadBinary: TBytes; override;
|
| 498 | function ReadString: string; override;
|
| 499 | function ReadAnsiString: AnsiString; override;
|
| 500 | end;
|
| 501 |
|
| 502 |
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 503 | implementation
|
| 504 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 505 | function ConvertInt64ToDouble( const n: Int64): Double;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 506 | begin
|
| 507 | ASSERT( SizeOf(n) = SizeOf(Result));
|
| 508 | System.Move( n, Result, SizeOf(Result));
|
| 509 | end;
|
| 510 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 511 | function ConvertDoubleToInt64( const d: Double): Int64;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 512 | begin
|
| 513 | ASSERT( SizeOf(d) = SizeOf(Result));
|
| 514 | System.Move( d, Result, SizeOf(Result));
|
| 515 | end;
|
| 516 |
|
| 517 | { TFieldImpl }
|
| 518 |
|
| 519 | constructor TFieldImpl.Create(const AName: string; const AType: TType;
|
| 520 | AId: SmallInt);
|
| 521 | begin
|
| 522 | FName := AName;
|
| 523 | FType := AType;
|
| 524 | FId := AId;
|
| 525 | end;
|
| 526 |
|
| 527 | constructor TFieldImpl.Create;
|
| 528 | begin
|
| 529 | FName := '';
|
| 530 | FType := Low(TType);
|
| 531 | FId := 0;
|
| 532 | end;
|
| 533 |
|
| 534 | function TFieldImpl.GetId: SmallInt;
|
| 535 | begin
|
| 536 | Result := FId;
|
| 537 | end;
|
| 538 |
|
| 539 | function TFieldImpl.GetName: string;
|
| 540 | begin
|
| 541 | Result := FName;
|
| 542 | end;
|
| 543 |
|
| 544 | function TFieldImpl.GetType: TType;
|
| 545 | begin
|
| 546 | Result := FType;
|
| 547 | end;
|
| 548 |
|
| 549 | procedure TFieldImpl.SetId(Value: SmallInt);
|
| 550 | begin
|
| 551 | FId := Value;
|
| 552 | end;
|
| 553 |
|
| 554 | procedure TFieldImpl.SetName(const Value: string);
|
| 555 | begin
|
| 556 | FName := Value;
|
| 557 | end;
|
| 558 |
|
| 559 | procedure TFieldImpl.SetType(Value: TType);
|
| 560 | begin
|
| 561 | FType := Value;
|
| 562 | end;
|
| 563 |
|
| 564 | { TProtocolImpl }
|
| 565 |
|
| 566 | constructor TProtocolImpl.Create(trans: ITransport);
|
| 567 | begin
|
| 568 | inherited Create;
|
| 569 | FTrans := trans;
|
| 570 | end;
|
| 571 |
|
| 572 | function TProtocolImpl.GetTransport: ITransport;
|
| 573 | begin
|
| 574 | Result := FTrans;
|
| 575 | end;
|
| 576 |
|
| 577 | function TProtocolImpl.ReadAnsiString: AnsiString;
|
| 578 | var
|
| 579 | b : TBytes;
|
| 580 | len : Integer;
|
| 581 | begin
|
| 582 | Result := '';
|
| 583 | b := ReadBinary;
|
| 584 | len := Length( b );
|
| 585 | if len > 0 then
|
| 586 | begin
|
| 587 | SetLength( Result, len);
|
| 588 | System.Move( b[0], Pointer(Result)^, len );
|
| 589 | end;
|
| 590 | end;
|
| 591 |
|
| 592 | function TProtocolImpl.ReadString: string;
|
| 593 | begin
|
| 594 | Result := TEncoding.UTF8.GetString( ReadBinary );
|
| 595 | end;
|
| 596 |
|
| 597 | procedure TProtocolImpl.WriteAnsiString(const s: AnsiString);
|
| 598 | var
|
| 599 | b : TBytes;
|
| 600 | len : Integer;
|
| 601 | begin
|
| 602 | len := Length(s);
|
| 603 | SetLength( b, len);
|
| 604 | if len > 0 then
|
| 605 | begin
|
| 606 | System.Move( Pointer(s)^, b[0], len );
|
| 607 | end;
|
| 608 | WriteBinary( b );
|
| 609 | end;
|
| 610 |
|
| 611 | procedure TProtocolImpl.WriteString(const s: string);
|
| 612 | var
|
| 613 | b : TBytes;
|
| 614 | begin
|
| 615 | b := TEncoding.UTF8.GetBytes(s);
|
| 616 | WriteBinary( b );
|
| 617 | end;
|
| 618 |
|
| 619 | { TProtocolUtil }
|
| 620 |
|
| 621 | class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType);
|
Jake Farrell | 6cd63ec | 2012-08-29 02:04:35 +0000 | [diff] [blame] | 622 | var field : IField;
|
| 623 | map : IMap;
|
| 624 | set_ : ISet;
|
| 625 | list : IList;
|
| 626 | i : Integer;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 627 | begin
|
Jake Farrell | 6cd63ec | 2012-08-29 02:04:35 +0000 | [diff] [blame] | 628 | case type_ of
|
| 629 | // simple types
|
| 630 | TType.Bool_ : prot.ReadBool();
|
| 631 | TType.Byte_ : prot.ReadByte();
|
| 632 | TType.I16 : prot.ReadI16();
|
| 633 | TType.I32 : prot.ReadI32();
|
| 634 | TType.I64 : prot.ReadI64();
|
| 635 | TType.Double_ : prot.ReadDouble();
|
| 636 | 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] | 637 |
|
Jake Farrell | 6cd63ec | 2012-08-29 02:04:35 +0000 | [diff] [blame] | 638 | // structured types
|
| 639 | TType.Struct : begin
|
| 640 | prot.ReadStructBegin();
|
| 641 | while TRUE do begin
|
| 642 | field := prot.ReadFieldBegin();
|
| 643 | if (field.Type_ = TType.Stop) then Break;
|
| 644 | Skip(prot, field.Type_);
|
| 645 | prot.ReadFieldEnd();
|
| 646 | end;
|
| 647 | prot.ReadStructEnd();
|
| 648 | end;
|
| 649 |
|
| 650 | TType.Map : begin
|
| 651 | map := prot.ReadMapBegin();
|
| 652 | for i := 0 to map.Count-1 do begin
|
| 653 | Skip(prot, map.KeyType);
|
| 654 | Skip(prot, map.ValueType);
|
| 655 | end;
|
| 656 | prot.ReadMapEnd();
|
| 657 | end;
|
| 658 |
|
| 659 | TType.Set_ : begin
|
| 660 | set_ := prot.ReadSetBegin();
|
| 661 | for i := 0 to set_.Count-1
|
| 662 | do Skip( prot, set_.ElementType);
|
| 663 | prot.ReadSetEnd();
|
| 664 | end;
|
| 665 |
|
| 666 | TType.List : begin
|
| 667 | list := prot.ReadListBegin();
|
| 668 | for i := 0 to list.Count-1
|
| 669 | do Skip( prot, list.ElementType);
|
| 670 | prot.ReadListEnd();
|
| 671 | end;
|
| 672 |
|
| 673 | else
|
| 674 | ASSERT( FALSE); // any new types?
|
| 675 | end;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 676 | end;
|
| 677 |
|
| 678 | { TStructImpl }
|
| 679 |
|
| 680 | constructor TStructImpl.Create(const AName: string);
|
| 681 | begin
|
| 682 | inherited Create;
|
| 683 | FName := AName;
|
| 684 | end;
|
| 685 |
|
| 686 | function TStructImpl.GetName: string;
|
| 687 | begin
|
| 688 | Result := FName;
|
| 689 | end;
|
| 690 |
|
| 691 | procedure TStructImpl.SetName(const Value: string);
|
| 692 | begin
|
| 693 | FName := Value;
|
| 694 | end;
|
| 695 |
|
| 696 | { TMapImpl }
|
| 697 |
|
| 698 | constructor TMapImpl.Create(AValueType, AKeyType: TType; ACount: Integer);
|
| 699 | begin
|
| 700 | inherited Create;
|
| 701 | FValueType := AValueType;
|
| 702 | FKeyType := AKeyType;
|
| 703 | FCount := ACount;
|
| 704 | end;
|
| 705 |
|
| 706 | constructor TMapImpl.Create;
|
| 707 | begin
|
| 708 |
|
| 709 | end;
|
| 710 |
|
| 711 | function TMapImpl.GetCount: Integer;
|
| 712 | begin
|
| 713 | Result := FCount;
|
| 714 | end;
|
| 715 |
|
| 716 | function TMapImpl.GetKeyType: TType;
|
| 717 | begin
|
| 718 | Result := FKeyType;
|
| 719 | end;
|
| 720 |
|
| 721 | function TMapImpl.GetValueType: TType;
|
| 722 | begin
|
| 723 | Result := FValueType;
|
| 724 | end;
|
| 725 |
|
| 726 | procedure TMapImpl.SetCount(Value: Integer);
|
| 727 | begin
|
| 728 | FCount := Value;
|
| 729 | end;
|
| 730 |
|
| 731 | procedure TMapImpl.SetKeyType(Value: TType);
|
| 732 | begin
|
| 733 | FKeyType := Value;
|
| 734 | end;
|
| 735 |
|
| 736 | procedure TMapImpl.SetValueType(Value: TType);
|
| 737 | begin
|
| 738 | FValueType := Value;
|
| 739 | end;
|
| 740 |
|
| 741 | { IMessage }
|
| 742 |
|
| 743 | constructor TMessageImpl.Create(AName: string; AMessageType: TMessageType;
|
| 744 | ASeqID: Integer);
|
| 745 | begin
|
| 746 | inherited Create;
|
| 747 | FName := AName;
|
| 748 | FMessageType := AMessageType;
|
| 749 | FSeqID := ASeqID;
|
| 750 | end;
|
| 751 |
|
| 752 | constructor TMessageImpl.Create;
|
| 753 | begin
|
| 754 | inherited;
|
| 755 | end;
|
| 756 |
|
| 757 | function TMessageImpl.GetName: string;
|
| 758 | begin
|
| 759 | Result := FName;
|
| 760 | end;
|
| 761 |
|
| 762 | function TMessageImpl.GetSeqID: Integer;
|
| 763 | begin
|
| 764 | Result := FSeqID;
|
| 765 | end;
|
| 766 |
|
| 767 | function TMessageImpl.GetType: TMessageType;
|
| 768 | begin
|
| 769 | Result := FMessageType;
|
| 770 | end;
|
| 771 |
|
| 772 | procedure TMessageImpl.SetName(const Value: string);
|
| 773 | begin
|
| 774 | FName := Value;
|
| 775 | end;
|
| 776 |
|
| 777 | procedure TMessageImpl.SetSeqID(Value: Integer);
|
| 778 | begin
|
| 779 | FSeqID := Value;
|
| 780 | end;
|
| 781 |
|
| 782 | procedure TMessageImpl.SetType(Value: TMessageType);
|
| 783 | begin
|
| 784 | FMessageType := Value;
|
| 785 | end;
|
| 786 |
|
| 787 | { ISet }
|
| 788 |
|
| 789 | constructor TSetImpl.Create( AElementType: TType; ACount: Integer);
|
| 790 | begin
|
| 791 | inherited Create;
|
| 792 | FCount := ACount;
|
| 793 | FElementType := AElementType;
|
| 794 | end;
|
| 795 |
|
| 796 | constructor TSetImpl.Create;
|
| 797 | begin
|
| 798 |
|
| 799 | end;
|
| 800 |
|
| 801 | function TSetImpl.GetCount: Integer;
|
| 802 | begin
|
| 803 | Result := FCount;
|
| 804 | end;
|
| 805 |
|
| 806 | function TSetImpl.GetElementType: TType;
|
| 807 | begin
|
| 808 | Result := FElementType;
|
| 809 | end;
|
| 810 |
|
| 811 | procedure TSetImpl.SetCount(Value: Integer);
|
| 812 | begin
|
| 813 | FCount := Value;
|
| 814 | end;
|
| 815 |
|
| 816 | procedure TSetImpl.SetElementType(Value: TType);
|
| 817 | begin
|
| 818 | FElementType := Value;
|
| 819 | end;
|
| 820 |
|
| 821 | { IList }
|
| 822 |
|
| 823 | constructor TListImpl.Create( AElementType: TType; ACount: Integer);
|
| 824 | begin
|
| 825 | inherited Create;
|
| 826 | FCount := ACount;
|
| 827 | FElementType := AElementType;
|
| 828 | end;
|
| 829 |
|
| 830 | constructor TListImpl.Create;
|
| 831 | begin
|
| 832 |
|
| 833 | end;
|
| 834 |
|
| 835 | function TListImpl.GetCount: Integer;
|
| 836 | begin
|
| 837 | Result := FCount;
|
| 838 | end;
|
| 839 |
|
| 840 | function TListImpl.GetElementType: TType;
|
| 841 | begin
|
| 842 | Result := FElementType;
|
| 843 | end;
|
| 844 |
|
| 845 | procedure TListImpl.SetCount(Value: Integer);
|
| 846 | begin
|
| 847 | FCount := Value;
|
| 848 | end;
|
| 849 |
|
| 850 | procedure TListImpl.SetElementType(Value: TType);
|
| 851 | begin
|
| 852 | FElementType := Value;
|
| 853 | end;
|
| 854 |
|
| 855 | { TBinaryProtocolImpl }
|
| 856 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 857 | constructor TBinaryProtocolImpl.Create( const trans: ITransport);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 858 | begin
|
| 859 | Create( trans, False, True);
|
| 860 | end;
|
| 861 |
|
| 862 | procedure TBinaryProtocolImpl.CheckReadLength(len: Integer);
|
| 863 | begin
|
| 864 | if FCheckReadLength then
|
| 865 | begin
|
| 866 | Dec( FReadLength, len);
|
| 867 | if FReadLength < 0 then
|
| 868 | begin
|
| 869 | raise Exception.Create( 'Message length exceeded: ' + IntToStr( len ) );
|
| 870 | end;
|
| 871 | end;
|
| 872 | end;
|
| 873 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 874 | constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead,
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 875 | strictWrite: Boolean);
|
| 876 | begin
|
| 877 | inherited Create( trans );
|
| 878 | FStrictRead := strictRead;
|
| 879 | FStrictWrite := strictWrite;
|
| 880 | end;
|
| 881 |
|
| 882 | function TBinaryProtocolImpl.ReadAll( var buf: TBytes; off,
|
| 883 | len: Integer): Integer;
|
| 884 | begin
|
| 885 | CheckReadLength( len );
|
| 886 | Result := FTrans.ReadAll( buf, off, len );
|
| 887 | end;
|
| 888 |
|
| 889 | function TBinaryProtocolImpl.ReadBinary: TBytes;
|
| 890 | var
|
| 891 | size : Integer;
|
| 892 | buf : TBytes;
|
| 893 | begin
|
| 894 | size := ReadI32;
|
| 895 | CheckReadLength( size );
|
| 896 | SetLength( buf, size );
|
| 897 | FTrans.ReadAll( buf, 0, size);
|
| 898 | Result := buf;
|
| 899 | end;
|
| 900 |
|
| 901 | function TBinaryProtocolImpl.ReadBool: Boolean;
|
| 902 | begin
|
| 903 | Result := ReadByte = 1;
|
| 904 | end;
|
| 905 |
|
| 906 | function TBinaryProtocolImpl.ReadByte: ShortInt;
|
| 907 | var
|
| 908 | bin : TBytes;
|
| 909 | begin
|
| 910 | SetLength( bin, 1);
|
| 911 | ReadAll( bin, 0, 1 );
|
| 912 | Result := ShortInt( bin[0]);
|
| 913 | end;
|
| 914 |
|
| 915 | function TBinaryProtocolImpl.ReadDouble: Double;
|
| 916 | begin
|
| 917 | Result := ConvertInt64ToDouble( ReadI64 )
|
| 918 | end;
|
| 919 |
|
| 920 | function TBinaryProtocolImpl.ReadFieldBegin: IField;
|
| 921 | var
|
| 922 | field : IField;
|
| 923 | begin
|
| 924 | field := TFieldImpl.Create;
|
| 925 | field.Type_ := TType( ReadByte);
|
| 926 | if ( field.Type_ <> TType.Stop ) then
|
| 927 | begin
|
| 928 | field.Id := ReadI16;
|
| 929 | end;
|
| 930 | Result := field;
|
| 931 | end;
|
| 932 |
|
| 933 | procedure TBinaryProtocolImpl.ReadFieldEnd;
|
| 934 | begin
|
| 935 |
|
| 936 | end;
|
| 937 |
|
| 938 | function TBinaryProtocolImpl.ReadI16: SmallInt;
|
| 939 | var
|
| 940 | i16in : TBytes;
|
| 941 | begin
|
| 942 | SetLength( i16in, 2 );
|
| 943 | ReadAll( i16in, 0, 2);
|
| 944 | Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF));
|
| 945 | end;
|
| 946 |
|
| 947 | function TBinaryProtocolImpl.ReadI32: Integer;
|
| 948 | var
|
| 949 | i32in : TBytes;
|
| 950 | begin
|
| 951 | SetLength( i32in, 4 );
|
| 952 | ReadAll( i32in, 0, 4);
|
| 953 |
|
| 954 | Result := Integer(
|
| 955 | ((i32in[0] and $FF) shl 24) or
|
| 956 | ((i32in[1] and $FF) shl 16) or
|
| 957 | ((i32in[2] and $FF) shl 8) or
|
| 958 | (i32in[3] and $FF));
|
| 959 |
|
| 960 | end;
|
| 961 |
|
| 962 | function TBinaryProtocolImpl.ReadI64: Int64;
|
| 963 | var
|
| 964 | i64in : TBytes;
|
| 965 | begin
|
| 966 | SetLength( i64in, 8);
|
| 967 | ReadAll( i64in, 0, 8);
|
| 968 | Result :=
|
| 969 | (Int64( i64in[0] and $FF) shl 56) or
|
| 970 | (Int64( i64in[1] and $FF) shl 48) or
|
| 971 | (Int64( i64in[2] and $FF) shl 40) or
|
| 972 | (Int64( i64in[3] and $FF) shl 32) or
|
| 973 | (Int64( i64in[4] and $FF) shl 24) or
|
| 974 | (Int64( i64in[5] and $FF) shl 16) or
|
| 975 | (Int64( i64in[6] and $FF) shl 8) or
|
| 976 | (Int64( i64in[7] and $FF));
|
| 977 | end;
|
| 978 |
|
| 979 | function TBinaryProtocolImpl.ReadListBegin: IList;
|
| 980 | var
|
| 981 | list : IList;
|
| 982 | begin
|
| 983 | list := TListImpl.Create;
|
| 984 | list.ElementType := TType( ReadByte );
|
| 985 | list.Count := ReadI32;
|
| 986 | Result := list;
|
| 987 | end;
|
| 988 |
|
| 989 | procedure TBinaryProtocolImpl.ReadListEnd;
|
| 990 | begin
|
| 991 |
|
| 992 | end;
|
| 993 |
|
| 994 | function TBinaryProtocolImpl.ReadMapBegin: IMap;
|
| 995 | var
|
| 996 | map : IMap;
|
| 997 | begin
|
| 998 | map := TMapImpl.Create;
|
| 999 | map.KeyType := TType( ReadByte );
|
| 1000 | map.ValueType := TType( ReadByte );
|
| 1001 | map.Count := ReadI32;
|
| 1002 | Result := map;
|
| 1003 | end;
|
| 1004 |
|
| 1005 | procedure TBinaryProtocolImpl.ReadMapEnd;
|
| 1006 | begin
|
| 1007 |
|
| 1008 | end;
|
| 1009 |
|
| 1010 | function TBinaryProtocolImpl.ReadMessageBegin: IMessage;
|
| 1011 | var
|
| 1012 | size : Integer;
|
| 1013 | version : Integer;
|
| 1014 | message : IMessage;
|
| 1015 | begin
|
| 1016 | message := TMessageImpl.Create;
|
| 1017 | size := ReadI32;
|
| 1018 | if (size < 0) then
|
| 1019 | begin
|
| 1020 | version := size and Integer( VERSION_MASK);
|
| 1021 | if ( version <> Integer( VERSION_1)) then
|
| 1022 | begin
|
| 1023 | raise TProtocolException.Create(TProtocolException.BAD_VERSION, 'Bad version in ReadMessageBegin: ' + IntToStr(version) );
|
| 1024 | end;
|
| 1025 | message.Type_ := TMessageType( size and $000000ff);
|
| 1026 | message.Name := ReadString;
|
| 1027 | message.SeqID := ReadI32;
|
| 1028 | end else
|
| 1029 | begin
|
| 1030 | if FStrictRead then
|
| 1031 | begin
|
| 1032 | raise TProtocolException.Create( TProtocolException.BAD_VERSION, 'Missing version in readMessageBegin, old client?' );
|
| 1033 | end;
|
| 1034 | message.Name := ReadStringBody( size );
|
| 1035 | message.Type_ := TMessageType( ReadByte );
|
| 1036 | message.SeqID := ReadI32;
|
| 1037 | end;
|
| 1038 | Result := message;
|
| 1039 | end;
|
| 1040 |
|
| 1041 | procedure TBinaryProtocolImpl.ReadMessageEnd;
|
| 1042 | begin
|
| 1043 | inherited;
|
| 1044 |
|
| 1045 | end;
|
| 1046 |
|
| 1047 | function TBinaryProtocolImpl.ReadSetBegin: ISet;
|
| 1048 | var
|
| 1049 | set_ : ISet;
|
| 1050 | begin
|
| 1051 | set_ := TSetImpl.Create;
|
| 1052 | set_.ElementType := TType( ReadByte );
|
| 1053 | set_.Count := ReadI32;
|
| 1054 | Result := set_;
|
| 1055 | end;
|
| 1056 |
|
| 1057 | procedure TBinaryProtocolImpl.ReadSetEnd;
|
| 1058 | begin
|
| 1059 |
|
| 1060 | end;
|
| 1061 |
|
| 1062 | function TBinaryProtocolImpl.ReadStringBody( size: Integer): string;
|
| 1063 | var
|
| 1064 | buf : TBytes;
|
| 1065 | begin
|
| 1066 | CheckReadLength( size );
|
| 1067 | SetLength( buf, size );
|
| 1068 | FTrans.ReadAll( buf, 0, size );
|
| 1069 | Result := TEncoding.UTF8.GetString( buf);
|
| 1070 | end;
|
| 1071 |
|
| 1072 | function TBinaryProtocolImpl.ReadStructBegin: IStruct;
|
| 1073 | begin
|
| 1074 | Result := TStructImpl.Create('');
|
| 1075 | end;
|
| 1076 |
|
| 1077 | procedure TBinaryProtocolImpl.ReadStructEnd;
|
| 1078 | begin
|
| 1079 | inherited;
|
| 1080 |
|
| 1081 | end;
|
| 1082 |
|
| 1083 | procedure TBinaryProtocolImpl.SetReadLength(readLength: Integer);
|
| 1084 | begin
|
| 1085 | FReadLength := readLength;
|
| 1086 | FCheckReadLength := True;
|
| 1087 | end;
|
| 1088 |
|
| 1089 | procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);
|
Jake Farrell | 9c6773a | 2012-03-22 02:40:45 +0000 | [diff] [blame] | 1090 | var iLen : Integer;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1091 | begin
|
Jake Farrell | 9c6773a | 2012-03-22 02:40:45 +0000 | [diff] [blame] | 1092 | iLen := Length(b);
|
| 1093 | WriteI32( iLen);
|
| 1094 | if iLen > 0 then FTrans.Write(b, 0, iLen);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1095 | end;
|
| 1096 |
|
| 1097 | procedure TBinaryProtocolImpl.WriteBool(b: Boolean);
|
| 1098 | begin
|
| 1099 | if b then
|
| 1100 | begin
|
| 1101 | WriteByte( 1 );
|
| 1102 | end else
|
| 1103 | begin
|
| 1104 | WriteByte( 0 );
|
| 1105 | end;
|
| 1106 | end;
|
| 1107 |
|
| 1108 | procedure TBinaryProtocolImpl.WriteByte(b: ShortInt);
|
| 1109 | var
|
| 1110 | a : TBytes;
|
| 1111 | begin
|
| 1112 | SetLength( a, 1);
|
| 1113 | a[0] := Byte( b );
|
| 1114 | FTrans.Write( a, 0, 1 );
|
| 1115 | end;
|
| 1116 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1117 | procedure TBinaryProtocolImpl.WriteDouble( const d: Double);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1118 | begin
|
| 1119 | WriteI64(ConvertDoubleToInt64(d));
|
| 1120 | end;
|
| 1121 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1122 | procedure TBinaryProtocolImpl.WriteFieldBegin( const field: IField);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1123 | begin
|
| 1124 | WriteByte(ShortInt(field.Type_));
|
| 1125 | WriteI16(field.ID);
|
| 1126 | end;
|
| 1127 |
|
| 1128 | procedure TBinaryProtocolImpl.WriteFieldEnd;
|
| 1129 | begin
|
| 1130 |
|
| 1131 | end;
|
| 1132 |
|
| 1133 | procedure TBinaryProtocolImpl.WriteFieldStop;
|
| 1134 | begin
|
| 1135 | WriteByte(ShortInt(TType.Stop));
|
| 1136 | end;
|
| 1137 |
|
| 1138 | procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt);
|
| 1139 | var
|
| 1140 | i16out : TBytes;
|
| 1141 | begin
|
| 1142 | SetLength( i16out, 2);
|
| 1143 | i16out[0] := Byte($FF and (i16 shr 8));
|
| 1144 | i16out[1] := Byte($FF and i16);
|
| 1145 | FTrans.Write( i16out );
|
| 1146 | end;
|
| 1147 |
|
| 1148 | procedure TBinaryProtocolImpl.WriteI32(i32: Integer);
|
| 1149 | var
|
| 1150 | i32out : TBytes;
|
| 1151 | begin
|
| 1152 | SetLength( i32out, 4);
|
| 1153 | i32out[0] := Byte($FF and (i32 shr 24));
|
| 1154 | i32out[1] := Byte($FF and (i32 shr 16));
|
| 1155 | i32out[2] := Byte($FF and (i32 shr 8));
|
| 1156 | i32out[3] := Byte($FF and i32);
|
| 1157 | FTrans.Write( i32out, 0, 4);
|
| 1158 | end;
|
| 1159 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1160 | procedure TBinaryProtocolImpl.WriteI64( const i64: Int64);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1161 | var
|
| 1162 | i64out : TBytes;
|
| 1163 | begin
|
| 1164 | SetLength( i64out, 8);
|
| 1165 | i64out[0] := Byte($FF and (i64 shr 56));
|
| 1166 | i64out[1] := Byte($FF and (i64 shr 48));
|
| 1167 | i64out[2] := Byte($FF and (i64 shr 40));
|
| 1168 | i64out[3] := Byte($FF and (i64 shr 32));
|
| 1169 | i64out[4] := Byte($FF and (i64 shr 24));
|
| 1170 | i64out[5] := Byte($FF and (i64 shr 16));
|
| 1171 | i64out[6] := Byte($FF and (i64 shr 8));
|
| 1172 | i64out[7] := Byte($FF and i64);
|
| 1173 | FTrans.Write( i64out, 0, 8);
|
| 1174 | end;
|
| 1175 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1176 | procedure TBinaryProtocolImpl.WriteListBegin( const list: IList);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1177 | begin
|
| 1178 | WriteByte(ShortInt(list.ElementType));
|
| 1179 | WriteI32(list.Count);
|
| 1180 | end;
|
| 1181 |
|
| 1182 | procedure TBinaryProtocolImpl.WriteListEnd;
|
| 1183 | begin
|
| 1184 |
|
| 1185 | end;
|
| 1186 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1187 | procedure TBinaryProtocolImpl.WriteMapBegin( const map: IMap);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1188 | begin
|
| 1189 | WriteByte(ShortInt(map.KeyType));
|
| 1190 | WriteByte(ShortInt(map.ValueType));
|
| 1191 | WriteI32(map.Count);
|
| 1192 | end;
|
| 1193 |
|
| 1194 | procedure TBinaryProtocolImpl.WriteMapEnd;
|
| 1195 | begin
|
| 1196 |
|
| 1197 | end;
|
| 1198 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1199 | procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: IMessage);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1200 | var
|
| 1201 | version : Cardinal;
|
| 1202 | begin
|
| 1203 | if FStrictWrite then
|
| 1204 | begin
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1205 | version := VERSION_1 or Cardinal( msg.Type_);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1206 | WriteI32( Integer( version) );
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1207 | WriteString( msg.Name);
|
Jake Farrell | 6cd63ec | 2012-08-29 02:04:35 +0000 | [diff] [blame] | 1208 | WriteI32( msg.SeqID);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1209 | end else
|
| 1210 | begin
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1211 | WriteString( msg.Name);
|
| 1212 | WriteByte(ShortInt( msg.Type_));
|
| 1213 | WriteI32( msg.SeqID);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1214 | end;
|
| 1215 | end;
|
| 1216 |
|
| 1217 | procedure TBinaryProtocolImpl.WriteMessageEnd;
|
| 1218 | begin
|
| 1219 |
|
| 1220 | end;
|
| 1221 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1222 | procedure TBinaryProtocolImpl.WriteSetBegin( const set_: ISet);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1223 | begin
|
| 1224 | WriteByte(ShortInt(set_.ElementType));
|
| 1225 | WriteI32(set_.Count);
|
| 1226 | end;
|
| 1227 |
|
| 1228 | procedure TBinaryProtocolImpl.WriteSetEnd;
|
| 1229 | begin
|
| 1230 |
|
| 1231 | end;
|
| 1232 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1233 | procedure TBinaryProtocolImpl.WriteStructBegin( const struc: IStruct);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1234 | begin
|
| 1235 |
|
| 1236 | end;
|
| 1237 |
|
| 1238 | procedure TBinaryProtocolImpl.WriteStructEnd;
|
| 1239 | begin
|
| 1240 |
|
| 1241 | end;
|
| 1242 |
|
| 1243 | { TProtocolException }
|
| 1244 |
|
| 1245 | constructor TProtocolException.Create;
|
| 1246 | begin
|
| 1247 | inherited Create('');
|
| 1248 | FType := UNKNOWN;
|
| 1249 | end;
|
| 1250 |
|
| 1251 | constructor TProtocolException.Create(type_: Integer);
|
| 1252 | begin
|
| 1253 | inherited Create('');
|
| 1254 | FType := type_;
|
| 1255 | end;
|
| 1256 |
|
| 1257 | constructor TProtocolException.Create(type_: Integer; const msg: string);
|
| 1258 | begin
|
| 1259 | inherited Create( msg );
|
| 1260 | FType := type_;
|
| 1261 | end;
|
| 1262 |
|
| 1263 | { TThriftStringBuilder }
|
| 1264 |
|
| 1265 | function TThriftStringBuilder.Append(const Value: TBytes): TStringBuilder;
|
| 1266 | begin
|
| 1267 | Result := Append( string( RawByteString(Value)) );
|
| 1268 | end;
|
| 1269 |
|
| 1270 | function TThriftStringBuilder.Append(
|
| 1271 | const Value: IThriftContainer): TStringBuilder;
|
| 1272 | begin
|
| 1273 | Result := Append( Value.ToString );
|
| 1274 | end;
|
| 1275 |
|
| 1276 | { TBinaryProtocolImpl.TFactory }
|
| 1277 |
|
| 1278 | constructor TBinaryProtocolImpl.TFactory.Create(AStrictRead, AStrictWrite: Boolean);
|
| 1279 | begin
|
| 1280 | FStrictRead := AStrictRead;
|
| 1281 | FStrictWrite := AStrictWrite;
|
| 1282 | end;
|
| 1283 |
|
| 1284 | constructor TBinaryProtocolImpl.TFactory.Create;
|
| 1285 | begin
|
| 1286 | Create( False, True )
|
| 1287 | end;
|
| 1288 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 1289 | function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1290 | begin
|
Jens Geyer | 5cb0d22 | 2013-03-07 20:44:22 +0100 | [diff] [blame] | 1291 | Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1292 | end;
|
| 1293 |
|
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame^] | 1294 |
|
| 1295 | { TProtocolDecorator }
|
| 1296 |
|
| 1297 | constructor TProtocolDecorator.Create( const aProtocol : IProtocol);
|
| 1298 | begin
|
| 1299 | ASSERT( aProtocol <> nil);
|
| 1300 | inherited Create( aProtocol.Transport);
|
| 1301 | FWrappedProtocol := aProtocol;
|
| 1302 | end;
|
| 1303 |
|
| 1304 |
|
| 1305 | procedure TProtocolDecorator.WriteMessageBegin( const msg: IMessage);
|
| 1306 | begin
|
| 1307 | FWrappedProtocol.WriteMessageBegin( msg);
|
| 1308 | end;
|
| 1309 |
|
| 1310 |
|
| 1311 | procedure TProtocolDecorator.WriteMessageEnd;
|
| 1312 | begin
|
| 1313 | FWrappedProtocol.WriteMessageEnd;
|
| 1314 | end;
|
| 1315 |
|
| 1316 |
|
| 1317 | procedure TProtocolDecorator.WriteStructBegin( const struc: IStruct);
|
| 1318 | begin
|
| 1319 | FWrappedProtocol.WriteStructBegin( struc);
|
| 1320 | end;
|
| 1321 |
|
| 1322 |
|
| 1323 | procedure TProtocolDecorator.WriteStructEnd;
|
| 1324 | begin
|
| 1325 | FWrappedProtocol.WriteStructEnd;
|
| 1326 | end;
|
| 1327 |
|
| 1328 |
|
| 1329 | procedure TProtocolDecorator.WriteFieldBegin( const field: IField);
|
| 1330 | begin
|
| 1331 | FWrappedProtocol.WriteFieldBegin( field);
|
| 1332 | end;
|
| 1333 |
|
| 1334 |
|
| 1335 | procedure TProtocolDecorator.WriteFieldEnd;
|
| 1336 | begin
|
| 1337 | FWrappedProtocol.WriteFieldEnd;
|
| 1338 | end;
|
| 1339 |
|
| 1340 |
|
| 1341 | procedure TProtocolDecorator.WriteFieldStop;
|
| 1342 | begin
|
| 1343 | FWrappedProtocol.WriteFieldStop;
|
| 1344 | end;
|
| 1345 |
|
| 1346 |
|
| 1347 | procedure TProtocolDecorator.WriteMapBegin( const map: IMap);
|
| 1348 | begin
|
| 1349 | FWrappedProtocol.WriteMapBegin( map);
|
| 1350 | end;
|
| 1351 |
|
| 1352 |
|
| 1353 | procedure TProtocolDecorator.WriteMapEnd;
|
| 1354 | begin
|
| 1355 | FWrappedProtocol.WriteMapEnd;
|
| 1356 | end;
|
| 1357 |
|
| 1358 |
|
| 1359 | procedure TProtocolDecorator.WriteListBegin( const list: IList);
|
| 1360 | begin
|
| 1361 | FWrappedProtocol.WriteListBegin( list);
|
| 1362 | end;
|
| 1363 |
|
| 1364 |
|
| 1365 | procedure TProtocolDecorator.WriteListEnd();
|
| 1366 | begin
|
| 1367 | FWrappedProtocol.WriteListEnd();
|
| 1368 | end;
|
| 1369 |
|
| 1370 |
|
| 1371 | procedure TProtocolDecorator.WriteSetBegin( const set_: ISet );
|
| 1372 | begin
|
| 1373 | FWrappedProtocol.WriteSetBegin( set_);
|
| 1374 | end;
|
| 1375 |
|
| 1376 |
|
| 1377 | procedure TProtocolDecorator.WriteSetEnd();
|
| 1378 | begin
|
| 1379 | FWrappedProtocol.WriteSetEnd();
|
| 1380 | end;
|
| 1381 |
|
| 1382 |
|
| 1383 | procedure TProtocolDecorator.WriteBool( b: Boolean);
|
| 1384 | begin
|
| 1385 | FWrappedProtocol.WriteBool( b);
|
| 1386 | end;
|
| 1387 |
|
| 1388 |
|
| 1389 | procedure TProtocolDecorator.WriteByte( b: ShortInt);
|
| 1390 | begin
|
| 1391 | FWrappedProtocol.WriteByte( b);
|
| 1392 | end;
|
| 1393 |
|
| 1394 |
|
| 1395 | procedure TProtocolDecorator.WriteI16( i16: SmallInt);
|
| 1396 | begin
|
| 1397 | FWrappedProtocol.WriteI16( i16);
|
| 1398 | end;
|
| 1399 |
|
| 1400 |
|
| 1401 | procedure TProtocolDecorator.WriteI32( i32: Integer);
|
| 1402 | begin
|
| 1403 | FWrappedProtocol.WriteI32( i32);
|
| 1404 | end;
|
| 1405 |
|
| 1406 |
|
| 1407 | procedure TProtocolDecorator.WriteI64( const i64: Int64);
|
| 1408 | begin
|
| 1409 | FWrappedProtocol.WriteI64( i64);
|
| 1410 | end;
|
| 1411 |
|
| 1412 |
|
| 1413 | procedure TProtocolDecorator.WriteDouble( const d: Double);
|
| 1414 | begin
|
| 1415 | FWrappedProtocol.WriteDouble( d);
|
| 1416 | end;
|
| 1417 |
|
| 1418 |
|
| 1419 | procedure TProtocolDecorator.WriteString( const s: string );
|
| 1420 | begin
|
| 1421 | FWrappedProtocol.WriteString( s);
|
| 1422 | end;
|
| 1423 |
|
| 1424 |
|
| 1425 | procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString);
|
| 1426 | begin
|
| 1427 | FWrappedProtocol.WriteAnsiString( s);
|
| 1428 | end;
|
| 1429 |
|
| 1430 |
|
| 1431 | procedure TProtocolDecorator.WriteBinary( const b: TBytes);
|
| 1432 | begin
|
| 1433 | FWrappedProtocol.WriteBinary( b);
|
| 1434 | end;
|
| 1435 |
|
| 1436 |
|
| 1437 | function TProtocolDecorator.ReadMessageBegin: IMessage;
|
| 1438 | begin
|
| 1439 | result := FWrappedProtocol.ReadMessageBegin;
|
| 1440 | end;
|
| 1441 |
|
| 1442 |
|
| 1443 | procedure TProtocolDecorator.ReadMessageEnd();
|
| 1444 | begin
|
| 1445 | FWrappedProtocol.ReadMessageEnd();
|
| 1446 | end;
|
| 1447 |
|
| 1448 |
|
| 1449 | function TProtocolDecorator.ReadStructBegin: IStruct;
|
| 1450 | begin
|
| 1451 | result := FWrappedProtocol.ReadStructBegin;
|
| 1452 | end;
|
| 1453 |
|
| 1454 |
|
| 1455 | procedure TProtocolDecorator.ReadStructEnd;
|
| 1456 | begin
|
| 1457 | FWrappedProtocol.ReadStructEnd;
|
| 1458 | end;
|
| 1459 |
|
| 1460 |
|
| 1461 | function TProtocolDecorator.ReadFieldBegin: IField;
|
| 1462 | begin
|
| 1463 | result := FWrappedProtocol.ReadFieldBegin;
|
| 1464 | end;
|
| 1465 |
|
| 1466 |
|
| 1467 | procedure TProtocolDecorator.ReadFieldEnd();
|
| 1468 | begin
|
| 1469 | FWrappedProtocol.ReadFieldEnd();
|
| 1470 | end;
|
| 1471 |
|
| 1472 |
|
| 1473 | function TProtocolDecorator.ReadMapBegin: IMap;
|
| 1474 | begin
|
| 1475 | result := FWrappedProtocol.ReadMapBegin;
|
| 1476 | end;
|
| 1477 |
|
| 1478 |
|
| 1479 | procedure TProtocolDecorator.ReadMapEnd();
|
| 1480 | begin
|
| 1481 | FWrappedProtocol.ReadMapEnd();
|
| 1482 | end;
|
| 1483 |
|
| 1484 |
|
| 1485 | function TProtocolDecorator.ReadListBegin: IList;
|
| 1486 | begin
|
| 1487 | result := FWrappedProtocol.ReadListBegin;
|
| 1488 | end;
|
| 1489 |
|
| 1490 |
|
| 1491 | procedure TProtocolDecorator.ReadListEnd();
|
| 1492 | begin
|
| 1493 | FWrappedProtocol.ReadListEnd();
|
| 1494 | end;
|
| 1495 |
|
| 1496 |
|
| 1497 | function TProtocolDecorator.ReadSetBegin: ISet;
|
| 1498 | begin
|
| 1499 | result := FWrappedProtocol.ReadSetBegin;
|
| 1500 | end;
|
| 1501 |
|
| 1502 |
|
| 1503 | procedure TProtocolDecorator.ReadSetEnd();
|
| 1504 | begin
|
| 1505 | FWrappedProtocol.ReadSetEnd();
|
| 1506 | end;
|
| 1507 |
|
| 1508 |
|
| 1509 | function TProtocolDecorator.ReadBool: Boolean;
|
| 1510 | begin
|
| 1511 | result := FWrappedProtocol.ReadBool;
|
| 1512 | end;
|
| 1513 |
|
| 1514 |
|
| 1515 | function TProtocolDecorator.ReadByte: ShortInt;
|
| 1516 | begin
|
| 1517 | result := FWrappedProtocol.ReadByte;
|
| 1518 | end;
|
| 1519 |
|
| 1520 |
|
| 1521 | function TProtocolDecorator.ReadI16: SmallInt;
|
| 1522 | begin
|
| 1523 | result := FWrappedProtocol.ReadI16;
|
| 1524 | end;
|
| 1525 |
|
| 1526 |
|
| 1527 | function TProtocolDecorator.ReadI32: Integer;
|
| 1528 | begin
|
| 1529 | result := FWrappedProtocol.ReadI32;
|
| 1530 | end;
|
| 1531 |
|
| 1532 |
|
| 1533 | function TProtocolDecorator.ReadI64: Int64;
|
| 1534 | begin
|
| 1535 | result := FWrappedProtocol.ReadI64;
|
| 1536 | end;
|
| 1537 |
|
| 1538 |
|
| 1539 | function TProtocolDecorator.ReadDouble:Double;
|
| 1540 | begin
|
| 1541 | result := FWrappedProtocol.ReadDouble;
|
| 1542 | end;
|
| 1543 |
|
| 1544 |
|
| 1545 | function TProtocolDecorator.ReadBinary: TBytes;
|
| 1546 | begin
|
| 1547 | result := FWrappedProtocol.ReadBinary;
|
| 1548 | end;
|
| 1549 |
|
| 1550 |
|
| 1551 | function TProtocolDecorator.ReadString: string;
|
| 1552 | begin
|
| 1553 | result := FWrappedProtocol.ReadString;
|
| 1554 | end;
|
| 1555 |
|
| 1556 |
|
| 1557 | function TProtocolDecorator.ReadAnsiString: AnsiString;
|
| 1558 | begin
|
| 1559 | result := FWrappedProtocol.ReadAnsiString;
|
| 1560 | end;
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1564 | end.
|
| 1565 |
|