blob: d5a758797ebc001206f02f46aa6d4f7f4aeba6b1 [file] [log] [blame]
Jens Geyerd5436f52014-10-03 19:50:38 +02001(*
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
22unit Thrift.Protocol;
23
24interface
25
26uses
27 Classes,
28 SysUtils,
29 Contnrs,
Jens Geyer606f1ef2018-04-09 23:09:41 +020030 Thrift.Exception,
Jens Geyerd5436f52014-10-03 19:50:38 +020031 Thrift.Stream,
Jens Geyer8f7487e2019-05-09 22:21:32 +020032 Thrift.Utils,
Jens Geyerd5436f52014-10-03 19:50:38 +020033 Thrift.Collections,
Jens Geyera019cda2019-11-09 23:24:52 +010034 Thrift.Configuration,
Jens Geyerd5436f52014-10-03 19:50:38 +020035 Thrift.Transport;
36
37type
38
39 TType = (
40 Stop = 0,
41 Void = 1,
42 Bool_ = 2,
43 Byte_ = 3,
44 Double_ = 4,
45 I16 = 6,
46 I32 = 8,
47 I64 = 10,
48 String_ = 11,
49 Struct = 12,
50 Map = 13,
51 Set_ = 14,
52 List = 15
53 );
54
55 TMessageType = (
56 Call = 1,
57 Reply = 2,
58 Exception = 3,
59 Oneway = 4
60 );
61
Jens Geyerf0e63312015-03-01 18:47:49 +010062const
63 VALID_TTYPES = [
64 TType.Stop, TType.Void,
65 TType.Bool_, TType.Byte_, TType.Double_, TType.I16, TType.I32, TType.I64, TType.String_,
66 TType.Struct, TType.Map, TType.Set_, TType.List
67 ];
68
69 VALID_MESSAGETYPES = [Low(TMessageType)..High(TMessageType)];
70
71type
Jens Geyerd5436f52014-10-03 19:50:38 +020072 IProtocol = interface;
Jens Geyer17c3ad92017-09-05 20:31:27 +020073
74 TThriftMessage = record
75 Name: string;
76 Type_: TMessageType;
77 SeqID: Integer;
78 end;
79
80 TThriftStruct = record
81 Name: string;
82 end;
83
84 TThriftField = record
85 Name: string;
86 Type_: TType;
87 Id: SmallInt;
88 end;
89
90 TThriftList = record
91 ElementType: TType;
92 Count: Integer;
93 end;
94
95 TThriftMap = record
96 KeyType: TType;
97 ValueType: TType;
98 Count: Integer;
99 end;
100
101 TThriftSet = record
102 ElementType: TType;
103 Count: Integer;
104 end;
105
106
Jens Geyerd5436f52014-10-03 19:50:38 +0200107 IProtocolFactory = interface
108 ['{7CD64A10-4E9F-4E99-93BF-708A31F4A67B}']
109 function GetProtocol( const trans: ITransport): IProtocol;
110 end;
111
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100112 TProtocolException = class abstract( TException)
Jens Geyerd5436f52014-10-03 19:50:38 +0200113 public
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100114 type TExceptionType = (
115 UNKNOWN = 0,
116 INVALID_DATA = 1,
117 NEGATIVE_SIZE = 2,
118 SIZE_LIMIT = 3,
119 BAD_VERSION = 4,
120 NOT_IMPLEMENTED = 5,
121 DEPTH_LIMIT = 6
122 );
Jens Geyerfad7fd32019-11-09 23:24:52 +0100123 strict protected
Jens Geyere0e32402016-04-20 21:50:48 +0200124 constructor HiddenCreate(const Msg: string);
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100125 class function GetType: TExceptionType; virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200126 public
Jens Geyere0e32402016-04-20 21:50:48 +0200127 // purposefully hide inherited constructor
128 class function Create(const Msg: string): TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)';
129 class function Create: TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)';
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100130 class function Create( aType: TExceptionType): TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)';
131 class function Create( aType: TExceptionType; const msg: string): TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)';
132 property Type_: TExceptionType read GetType;
Jens Geyerd5436f52014-10-03 19:50:38 +0200133 end;
134
Jens Geyere0e32402016-04-20 21:50:48 +0200135 // Needed to remove deprecation warning
136 TProtocolExceptionSpecialized = class abstract (TProtocolException)
137 public
138 constructor Create(const Msg: string);
139 end;
140
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100141 TProtocolExceptionUnknown = class (TProtocolExceptionSpecialized)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100142 strict protected
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100143 class function GetType: TProtocolException.TExceptionType; override;
144 end;
145
146 TProtocolExceptionInvalidData = class (TProtocolExceptionSpecialized)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100147 strict protected
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100148 class function GetType: TProtocolException.TExceptionType; override;
149 end;
150
151 TProtocolExceptionNegativeSize = class (TProtocolExceptionSpecialized)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100152 strict protected
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100153 class function GetType: TProtocolException.TExceptionType; override;
154 end;
155
156 TProtocolExceptionSizeLimit = class (TProtocolExceptionSpecialized)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100157 strict protected
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100158 class function GetType: TProtocolException.TExceptionType; override;
159 end;
160
161 TProtocolExceptionBadVersion = class (TProtocolExceptionSpecialized)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100162 strict protected
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100163 class function GetType: TProtocolException.TExceptionType; override;
164 end;
165
166 TProtocolExceptionNotImplemented = class (TProtocolExceptionSpecialized)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100167 strict protected
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100168 class function GetType: TProtocolException.TExceptionType; override;
169 end;
170
171 TProtocolExceptionDepthLimit = class (TProtocolExceptionSpecialized)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100172 strict protected
Jens Geyer9f11c1e2019-11-09 19:39:20 +0100173 class function GetType: TProtocolException.TExceptionType; override;
174 end;
175
Jens Geyere0e32402016-04-20 21:50:48 +0200176
Jens Geyerd5436f52014-10-03 19:50:38 +0200177
178 TProtocolUtil = class
179 public
180 class procedure Skip( prot: IProtocol; type_: TType);
181 end;
182
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200183 IProtocolRecursionTracker = interface
184 ['{29CA033F-BB56-49B1-9EE3-31B1E82FC7A5}']
185 // no members yet
186 end;
187
188 TProtocolRecursionTrackerImpl = class abstract( TInterfacedObject, IProtocolRecursionTracker)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100189 strict protected
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200190 FProtocol : IProtocol;
191 public
192 constructor Create( prot : IProtocol);
193 destructor Destroy; override;
194 end;
195
Jens Geyerd5436f52014-10-03 19:50:38 +0200196 IProtocol = interface
Jens Geyera019cda2019-11-09 23:24:52 +0100197 ['{F0040D99-937F-400D-9932-AF04F665899F}']
Jens Geyerd5436f52014-10-03 19:50:38 +0200198 function GetTransport: ITransport;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200199 procedure WriteMessageBegin( const msg: TThriftMessage);
Jens Geyerd5436f52014-10-03 19:50:38 +0200200 procedure WriteMessageEnd;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200201 procedure WriteStructBegin( const struc: TThriftStruct);
Jens Geyerd5436f52014-10-03 19:50:38 +0200202 procedure WriteStructEnd;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200203 procedure WriteFieldBegin( const field: TThriftField);
Jens Geyerd5436f52014-10-03 19:50:38 +0200204 procedure WriteFieldEnd;
205 procedure WriteFieldStop;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200206 procedure WriteMapBegin( const map: TThriftMap);
Jens Geyerd5436f52014-10-03 19:50:38 +0200207 procedure WriteMapEnd;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200208 procedure WriteListBegin( const list: TThriftList);
Jens Geyerd5436f52014-10-03 19:50:38 +0200209 procedure WriteListEnd();
Jens Geyer17c3ad92017-09-05 20:31:27 +0200210 procedure WriteSetBegin( const set_: TThriftSet );
Jens Geyerd5436f52014-10-03 19:50:38 +0200211 procedure WriteSetEnd();
212 procedure WriteBool( b: Boolean);
213 procedure WriteByte( b: ShortInt);
214 procedure WriteI16( i16: SmallInt);
215 procedure WriteI32( i32: Integer);
216 procedure WriteI64( const i64: Int64);
217 procedure WriteDouble( const d: Double);
218 procedure WriteString( const s: string );
219 procedure WriteAnsiString( const s: AnsiString);
220 procedure WriteBinary( const b: TBytes);
221
Jens Geyer17c3ad92017-09-05 20:31:27 +0200222 function ReadMessageBegin: TThriftMessage;
Jens Geyerd5436f52014-10-03 19:50:38 +0200223 procedure ReadMessageEnd();
Jens Geyer17c3ad92017-09-05 20:31:27 +0200224 function ReadStructBegin: TThriftStruct;
Jens Geyerd5436f52014-10-03 19:50:38 +0200225 procedure ReadStructEnd;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200226 function ReadFieldBegin: TThriftField;
Jens Geyerd5436f52014-10-03 19:50:38 +0200227 procedure ReadFieldEnd();
Jens Geyer17c3ad92017-09-05 20:31:27 +0200228 function ReadMapBegin: TThriftMap;
Jens Geyerd5436f52014-10-03 19:50:38 +0200229 procedure ReadMapEnd();
Jens Geyer17c3ad92017-09-05 20:31:27 +0200230 function ReadListBegin: TThriftList;
Jens Geyerd5436f52014-10-03 19:50:38 +0200231 procedure ReadListEnd();
Jens Geyer17c3ad92017-09-05 20:31:27 +0200232 function ReadSetBegin: TThriftSet;
Jens Geyerd5436f52014-10-03 19:50:38 +0200233 procedure ReadSetEnd();
234 function ReadBool: Boolean;
235 function ReadByte: ShortInt;
236 function ReadI16: SmallInt;
237 function ReadI32: Integer;
238 function ReadI64: Int64;
239 function ReadDouble:Double;
240 function ReadBinary: TBytes;
241 function ReadString: string;
242 function ReadAnsiString: AnsiString;
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200243
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200244 function NextRecursionLevel : IProtocolRecursionTracker;
245 procedure IncrementRecursionDepth;
246 procedure DecrementRecursionDepth;
Jens Geyer41f47af2019-11-09 23:24:52 +0100247 function GetMinSerializedSize( const aType : TType) : Integer;
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200248
Jens Geyerd5436f52014-10-03 19:50:38 +0200249 property Transport: ITransport read GetTransport;
Jens Geyera019cda2019-11-09 23:24:52 +0100250 function Configuration : IThriftConfiguration;
Jens Geyerd5436f52014-10-03 19:50:38 +0200251 end;
252
253 TProtocolImpl = class abstract( TInterfacedObject, IProtocol)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100254 strict protected
Jens Geyerd5436f52014-10-03 19:50:38 +0200255 FTrans : ITransport;
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200256 FRecursionLimit : Integer;
257 FRecursionDepth : Integer;
258
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200259 function NextRecursionLevel : IProtocolRecursionTracker;
260 procedure IncrementRecursionDepth;
261 procedure DecrementRecursionDepth;
262
Jens Geyer41f47af2019-11-09 23:24:52 +0100263 function GetMinSerializedSize( const aType : TType) : Integer; virtual; abstract;
264 procedure CheckReadBytesAvailable( const value : TThriftList); overload; inline;
265 procedure CheckReadBytesAvailable( const value : TThriftSet); overload; inline;
266 procedure CheckReadBytesAvailable( const value : TThriftMap); overload; inline;
267
268 procedure Reset; virtual;
Jens Geyera019cda2019-11-09 23:24:52 +0100269 function GetTransport: ITransport;
270 function Configuration : IThriftConfiguration;
271
Jens Geyer17c3ad92017-09-05 20:31:27 +0200272 procedure WriteMessageBegin( const msg: TThriftMessage); virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200273 procedure WriteMessageEnd; virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200274 procedure WriteStructBegin( const struc: TThriftStruct); virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200275 procedure WriteStructEnd; virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200276 procedure WriteFieldBegin( const field: TThriftField); virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200277 procedure WriteFieldEnd; virtual; abstract;
278 procedure WriteFieldStop; virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200279 procedure WriteMapBegin( const map: TThriftMap); virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200280 procedure WriteMapEnd; virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200281 procedure WriteListBegin( const list: TThriftList); virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200282 procedure WriteListEnd(); virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200283 procedure WriteSetBegin( const set_: TThriftSet ); virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200284 procedure WriteSetEnd(); virtual; abstract;
285 procedure WriteBool( b: Boolean); virtual; abstract;
286 procedure WriteByte( b: ShortInt); virtual; abstract;
287 procedure WriteI16( i16: SmallInt); virtual; abstract;
288 procedure WriteI32( i32: Integer); virtual; abstract;
289 procedure WriteI64( const i64: Int64); virtual; abstract;
290 procedure WriteDouble( const d: Double); virtual; abstract;
291 procedure WriteString( const s: string ); virtual;
292 procedure WriteAnsiString( const s: AnsiString); virtual;
293 procedure WriteBinary( const b: TBytes); virtual; abstract;
294
Jens Geyer17c3ad92017-09-05 20:31:27 +0200295 function ReadMessageBegin: TThriftMessage; virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200296 procedure ReadMessageEnd(); virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200297 function ReadStructBegin: TThriftStruct; virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200298 procedure ReadStructEnd; virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200299 function ReadFieldBegin: TThriftField; virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200300 procedure ReadFieldEnd(); virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200301 function ReadMapBegin: TThriftMap; virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200302 procedure ReadMapEnd(); virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200303 function ReadListBegin: TThriftList; virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200304 procedure ReadListEnd(); virtual; abstract;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200305 function ReadSetBegin: TThriftSet; virtual; abstract;
Jens Geyerd5436f52014-10-03 19:50:38 +0200306 procedure ReadSetEnd(); virtual; abstract;
307 function ReadBool: Boolean; virtual; abstract;
308 function ReadByte: ShortInt; virtual; abstract;
309 function ReadI16: SmallInt; virtual; abstract;
310 function ReadI32: Integer; virtual; abstract;
311 function ReadI64: Int64; virtual; abstract;
312 function ReadDouble:Double; virtual; abstract;
313 function ReadBinary: TBytes; virtual; abstract;
314 function ReadString: string; virtual;
315 function ReadAnsiString: AnsiString; virtual;
316
Jens Geyera019cda2019-11-09 23:24:52 +0100317 property Transport: ITransport read GetTransport;
Jens Geyerd5436f52014-10-03 19:50:38 +0200318
Jens Geyera019cda2019-11-09 23:24:52 +0100319 public
320 constructor Create( const aTransport : ITransport);
Jens Geyerd5436f52014-10-03 19:50:38 +0200321 end;
322
Jens Geyer8f7487e2019-05-09 22:21:32 +0200323 IBase = interface( ISupportsToString)
324 ['{AFF6CECA-5200-4540-950E-9B89E0C1C00C}']
Jens Geyerd5436f52014-10-03 19:50:38 +0200325 procedure Read( const iprot: IProtocol);
326 procedure Write( const iprot: IProtocol);
327 end;
328
Jens Geyerd5436f52014-10-03 19:50:38 +0200329
330 TBinaryProtocolImpl = class( TProtocolImpl )
Jens Geyerfad7fd32019-11-09 23:24:52 +0100331 strict protected
Jens Geyerd5436f52014-10-03 19:50:38 +0200332 const
333 VERSION_MASK : Cardinal = $ffff0000;
334 VERSION_1 : Cardinal = $80010000;
Jens Geyerfad7fd32019-11-09 23:24:52 +0100335 strict protected
Jens Geyerd5436f52014-10-03 19:50:38 +0200336 FStrictRead : Boolean;
337 FStrictWrite : Boolean;
Jens Geyer41f47af2019-11-09 23:24:52 +0100338 function GetMinSerializedSize( const aType : TType) : Integer; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200339
Jens Geyerfad7fd32019-11-09 23:24:52 +0100340 strict private
Jens Geyer17c3ad92017-09-05 20:31:27 +0200341 function ReadAll( const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer ): Integer; inline;
Jens Geyerd5436f52014-10-03 19:50:38 +0200342 function ReadStringBody( size: Integer): string;
343
344 public
Jens Geyerd5436f52014-10-03 19:50:38 +0200345 type
346 TFactory = class( TInterfacedObject, IProtocolFactory)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100347 strict protected
Jens Geyerd5436f52014-10-03 19:50:38 +0200348 FStrictRead : Boolean;
349 FStrictWrite : Boolean;
Jens Geyerd5436f52014-10-03 19:50:38 +0200350 function GetProtocol( const trans: ITransport): IProtocol;
Jens Geyerfad7fd32019-11-09 23:24:52 +0100351 public
352 constructor Create( const aStrictRead : Boolean = FALSE; const aStrictWrite: Boolean = TRUE); reintroduce;
Jens Geyerd5436f52014-10-03 19:50:38 +0200353 end;
354
Jens Geyerfad7fd32019-11-09 23:24:52 +0100355 constructor Create( const trans: ITransport; strictRead: Boolean = FALSE; strictWrite: Boolean = TRUE); reintroduce;
Jens Geyerd5436f52014-10-03 19:50:38 +0200356
Jens Geyer17c3ad92017-09-05 20:31:27 +0200357 procedure WriteMessageBegin( const msg: TThriftMessage); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200358 procedure WriteMessageEnd; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200359 procedure WriteStructBegin( const struc: TThriftStruct); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200360 procedure WriteStructEnd; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200361 procedure WriteFieldBegin( const field: TThriftField); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200362 procedure WriteFieldEnd; override;
363 procedure WriteFieldStop; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200364 procedure WriteMapBegin( const map: TThriftMap); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200365 procedure WriteMapEnd; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200366 procedure WriteListBegin( const list: TThriftList); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200367 procedure WriteListEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200368 procedure WriteSetBegin( const set_: TThriftSet ); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200369 procedure WriteSetEnd(); override;
370 procedure WriteBool( b: Boolean); override;
371 procedure WriteByte( b: ShortInt); override;
372 procedure WriteI16( i16: SmallInt); override;
373 procedure WriteI32( i32: Integer); override;
374 procedure WriteI64( const i64: Int64); override;
375 procedure WriteDouble( const d: Double); override;
376 procedure WriteBinary( const b: TBytes); override;
377
Jens Geyer17c3ad92017-09-05 20:31:27 +0200378 function ReadMessageBegin: TThriftMessage; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200379 procedure ReadMessageEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200380 function ReadStructBegin: TThriftStruct; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200381 procedure ReadStructEnd; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200382 function ReadFieldBegin: TThriftField; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200383 procedure ReadFieldEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200384 function ReadMapBegin: TThriftMap; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200385 procedure ReadMapEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200386 function ReadListBegin: TThriftList; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200387 procedure ReadListEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200388 function ReadSetBegin: TThriftSet; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200389 procedure ReadSetEnd(); override;
390 function ReadBool: Boolean; override;
391 function ReadByte: ShortInt; override;
392 function ReadI16: SmallInt; override;
393 function ReadI32: Integer; override;
394 function ReadI64: Int64; override;
395 function ReadDouble:Double; override;
396 function ReadBinary: TBytes; override;
397
398 end;
399
400
401 { TProtocolDecorator forwards all requests to an enclosed TProtocol instance,
402 providing a way to author concise concrete decorator subclasses. The decorator
403 does not (and should not) modify the behaviour of the enclosed TProtocol
404
405 See p.175 of Design Patterns (by Gamma et al.)
406 }
407 TProtocolDecorator = class( TProtocolImpl)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100408 strict private
Jens Geyerd5436f52014-10-03 19:50:38 +0200409 FWrappedProtocol : IProtocol;
410
Jens Geyer41f47af2019-11-09 23:24:52 +0100411 strict protected
412 function GetMinSerializedSize( const aType : TType) : Integer; override;
413
Jens Geyerd5436f52014-10-03 19:50:38 +0200414 public
415 // Encloses the specified protocol.
416 // All operations will be forward to the given protocol. Must be non-null.
417 constructor Create( const aProtocol : IProtocol);
418
Jens Geyer17c3ad92017-09-05 20:31:27 +0200419 procedure WriteMessageBegin( const msg: TThriftMessage); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200420 procedure WriteMessageEnd; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200421 procedure WriteStructBegin( const struc: TThriftStruct); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200422 procedure WriteStructEnd; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200423 procedure WriteFieldBegin( const field: TThriftField); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200424 procedure WriteFieldEnd; override;
425 procedure WriteFieldStop; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200426 procedure WriteMapBegin( const map: TThriftMap); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200427 procedure WriteMapEnd; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200428 procedure WriteListBegin( const list: TThriftList); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200429 procedure WriteListEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200430 procedure WriteSetBegin( const set_: TThriftSet ); override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200431 procedure WriteSetEnd(); override;
432 procedure WriteBool( b: Boolean); override;
433 procedure WriteByte( b: ShortInt); override;
434 procedure WriteI16( i16: SmallInt); override;
435 procedure WriteI32( i32: Integer); override;
436 procedure WriteI64( const i64: Int64); override;
437 procedure WriteDouble( const d: Double); override;
438 procedure WriteString( const s: string ); override;
439 procedure WriteAnsiString( const s: AnsiString); override;
440 procedure WriteBinary( const b: TBytes); override;
441
Jens Geyer17c3ad92017-09-05 20:31:27 +0200442 function ReadMessageBegin: TThriftMessage; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200443 procedure ReadMessageEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200444 function ReadStructBegin: TThriftStruct; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200445 procedure ReadStructEnd; override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200446 function ReadFieldBegin: TThriftField; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200447 procedure ReadFieldEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200448 function ReadMapBegin: TThriftMap; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200449 procedure ReadMapEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200450 function ReadListBegin: TThriftList; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200451 procedure ReadListEnd(); override;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200452 function ReadSetBegin: TThriftSet; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200453 procedure ReadSetEnd(); override;
454 function ReadBool: Boolean; override;
455 function ReadByte: ShortInt; override;
456 function ReadI16: SmallInt; override;
457 function ReadI32: Integer; override;
458 function ReadI64: Int64; override;
459 function ReadDouble:Double; override;
460 function ReadBinary: TBytes; override;
461 function ReadString: string; override;
462 function ReadAnsiString: AnsiString; override;
463 end;
464
465
466type
467 IRequestEvents = interface
Jens Geyer01640402013-09-25 21:12:21 +0200468 ['{F926A26A-5B00-4560-86FA-2CAE3BA73DAF}']
469 // Called before reading arguments.
470 procedure PreRead;
471 // Called between reading arguments and calling the handler.
472 procedure PostRead;
473 // Called between calling the handler and writing the response.
474 procedure PreWrite;
475 // Called after writing the response.
476 procedure PostWrite;
477 // Called when an oneway (async) function call completes successfully.
478 procedure OnewayComplete;
479 // Called if the handler throws an undeclared exception.
480 procedure UnhandledError( const e : Exception);
481 // Called when a client has finished request-handling to clean up
482 procedure CleanupContext;
483 end;
484
485
486 IProcessorEvents = interface
487 ['{A8661119-657C-447D-93C5-512E36162A45}']
488 // Called when a client is about to call the processor.
489 procedure Processing( const transport : ITransport);
490 // Called on any service function invocation
491 function CreateRequestContext( const aFunctionName : string) : IRequestEvents;
492 // Called when a client has finished request-handling to clean up
493 procedure CleanupContext;
494 end;
495
496
497 IProcessor = interface
498 ['{7BAE92A5-46DA-4F13-B6EA-0EABE233EE5F}']
Jens Geyerd430bbd2013-09-26 23:37:54 +0200499 function Process( const iprot :IProtocol; const oprot: IProtocol; const events : IProcessorEvents = nil): Boolean;
Jens Geyer01640402013-09-25 21:12:21 +0200500 end;
501
Jens Geyerd5436f52014-10-03 19:50:38 +0200502
Jens Geyer17c3ad92017-09-05 20:31:27 +0200503procedure Init( var rec : TThriftMessage; const AName: string = ''; const AMessageType: TMessageType = Low(TMessageType); const ASeqID: Integer = 0); overload; inline;
504procedure Init( var rec : TThriftStruct; const AName: string = ''); overload; inline;
505procedure Init( var rec : TThriftField; const AName: string = ''; const AType: TType = Low(TType); const AID: SmallInt = 0); overload; inline;
506procedure Init( var rec : TThriftMap; const AKeyType: TType = Low(TType); const AValueType: TType = Low(TType); const ACount: Integer = 0); overload; inline;
507procedure Init( var rec : TThriftSet; const AElementType: TType = Low(TType); const ACount: Integer = 0); overload; inline;
508procedure Init( var rec : TThriftList; const AElementType: TType = Low(TType); const ACount: Integer = 0); overload; inline;
509
Jens Geyerd5436f52014-10-03 19:50:38 +0200510
511implementation
512
Jens Geyerfad7fd32019-11-09 23:24:52 +0100513function ConvertInt64ToDouble( const n: Int64): Double; inline;
Jens Geyerd5436f52014-10-03 19:50:38 +0200514begin
515 ASSERT( SizeOf(n) = SizeOf(Result));
516 System.Move( n, Result, SizeOf(Result));
517end;
518
Jens Geyerfad7fd32019-11-09 23:24:52 +0100519function ConvertDoubleToInt64( const d: Double): Int64; inline;
Jens Geyerd5436f52014-10-03 19:50:38 +0200520begin
521 ASSERT( SizeOf(d) = SizeOf(Result));
522 System.Move( d, Result, SizeOf(Result));
523end;
524
Jens Geyerd5436f52014-10-03 19:50:38 +0200525
Jens Geyerd5436f52014-10-03 19:50:38 +0200526
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200527{ TProtocolRecursionTrackerImpl }
528
529constructor TProtocolRecursionTrackerImpl.Create( prot : IProtocol);
530begin
531 inherited Create;
532
533 // storing the pointer *after* the (successful) increment is important here
534 prot.IncrementRecursionDepth;
535 FProtocol := prot;
536end;
537
538destructor TProtocolRecursionTrackerImpl.Destroy;
539begin
540 try
541 // we have to release the reference iff the pointer has been stored
542 if FProtocol <> nil then begin
543 FProtocol.DecrementRecursionDepth;
544 FProtocol := nil;
545 end;
546 finally
547 inherited Destroy;
548 end;
549end;
550
Jens Geyerd5436f52014-10-03 19:50:38 +0200551{ TProtocolImpl }
552
Jens Geyera019cda2019-11-09 23:24:52 +0100553constructor TProtocolImpl.Create( const aTransport : ITransport);
Jens Geyerd5436f52014-10-03 19:50:38 +0200554begin
555 inherited Create;
Jens Geyera019cda2019-11-09 23:24:52 +0100556 FTrans := aTransport;
557 FRecursionLimit := aTransport.Configuration.RecursionLimit;
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200558 FRecursionDepth := 0;
559end;
560
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200561function TProtocolImpl.NextRecursionLevel : IProtocolRecursionTracker;
562begin
563 result := TProtocolRecursionTrackerImpl.Create(Self);
564end;
565
566procedure TProtocolImpl.IncrementRecursionDepth;
567begin
568 if FRecursionDepth < FRecursionLimit
569 then Inc(FRecursionDepth)
Jens Geyere0e32402016-04-20 21:50:48 +0200570 else raise TProtocolExceptionDepthLimit.Create('Depth limit exceeded');
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200571end;
572
573procedure TProtocolImpl.DecrementRecursionDepth;
574begin
575 Dec(FRecursionDepth)
Jens Geyerd5436f52014-10-03 19:50:38 +0200576end;
577
578function TProtocolImpl.GetTransport: ITransport;
579begin
580 Result := FTrans;
581end;
582
Jens Geyera019cda2019-11-09 23:24:52 +0100583function TProtocolImpl.Configuration : IThriftConfiguration;
584begin
585 Result := FTrans.Configuration;
586end;
587
Jens Geyer41f47af2019-11-09 23:24:52 +0100588procedure TProtocolImpl.Reset;
589begin
Jens Geyera019cda2019-11-09 23:24:52 +0100590 FTrans.ResetConsumedMessageSize;
Jens Geyer41f47af2019-11-09 23:24:52 +0100591end;
592
Jens Geyerd5436f52014-10-03 19:50:38 +0200593function TProtocolImpl.ReadAnsiString: AnsiString;
594var
595 b : TBytes;
596 len : Integer;
597begin
598 Result := '';
599 b := ReadBinary;
600 len := Length( b );
Jens Geyerfad7fd32019-11-09 23:24:52 +0100601 if len > 0 then begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200602 SetLength( Result, len);
603 System.Move( b[0], Pointer(Result)^, len );
604 end;
605end;
606
607function TProtocolImpl.ReadString: string;
608begin
609 Result := TEncoding.UTF8.GetString( ReadBinary );
610end;
611
612procedure TProtocolImpl.WriteAnsiString(const s: AnsiString);
613var
614 b : TBytes;
615 len : Integer;
616begin
617 len := Length(s);
618 SetLength( b, len);
Jens Geyerfad7fd32019-11-09 23:24:52 +0100619 if len > 0 then begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200620 System.Move( Pointer(s)^, b[0], len );
621 end;
622 WriteBinary( b );
623end;
624
625procedure TProtocolImpl.WriteString(const s: string);
626var
627 b : TBytes;
628begin
629 b := TEncoding.UTF8.GetBytes(s);
630 WriteBinary( b );
631end;
632
Jens Geyer41f47af2019-11-09 23:24:52 +0100633
634procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftList);
635begin
636 FTrans.CheckReadBytesAvailable( value.Count * GetMinSerializedSize(value.ElementType));
637end;
638
639
640procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftSet);
641begin
642 FTrans.CheckReadBytesAvailable( value.Count * GetMinSerializedSize(value.ElementType));
643end;
644
645
646procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftMap);
Jens Geyera019cda2019-11-09 23:24:52 +0100647var nPairSize : Integer;
Jens Geyer41f47af2019-11-09 23:24:52 +0100648begin
649 nPairSize := GetMinSerializedSize(value.KeyType) + GetMinSerializedSize(value.ValueType);
650 FTrans.CheckReadBytesAvailable( value.Count * nPairSize);
651end;
652
Jens Geyerd5436f52014-10-03 19:50:38 +0200653{ TProtocolUtil }
654
655class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType);
Jens Geyer17c3ad92017-09-05 20:31:27 +0200656var field : TThriftField;
657 map : TThriftMap;
658 set_ : TThriftSet;
659 list : TThriftList;
Jens Geyerd5436f52014-10-03 19:50:38 +0200660 i : Integer;
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200661 tracker : IProtocolRecursionTracker;
Jens Geyerd5436f52014-10-03 19:50:38 +0200662begin
Jens Geyerd47fcdd2015-07-09 22:05:18 +0200663 tracker := prot.NextRecursionLevel;
Jens Geyerd5436f52014-10-03 19:50:38 +0200664 case type_ of
665 // simple types
666 TType.Bool_ : prot.ReadBool();
667 TType.Byte_ : prot.ReadByte();
668 TType.I16 : prot.ReadI16();
669 TType.I32 : prot.ReadI32();
670 TType.I64 : prot.ReadI64();
671 TType.Double_ : prot.ReadDouble();
672 TType.String_ : prot.ReadBinary();// Don't try to decode the string, just skip it.
673
674 // structured types
675 TType.Struct : begin
676 prot.ReadStructBegin();
677 while TRUE do begin
678 field := prot.ReadFieldBegin();
679 if (field.Type_ = TType.Stop) then Break;
680 Skip(prot, field.Type_);
681 prot.ReadFieldEnd();
682 end;
683 prot.ReadStructEnd();
684 end;
685
686 TType.Map : begin
687 map := prot.ReadMapBegin();
688 for i := 0 to map.Count-1 do begin
689 Skip(prot, map.KeyType);
690 Skip(prot, map.ValueType);
691 end;
692 prot.ReadMapEnd();
693 end;
694
695 TType.Set_ : begin
696 set_ := prot.ReadSetBegin();
697 for i := 0 to set_.Count-1
698 do Skip( prot, set_.ElementType);
699 prot.ReadSetEnd();
700 end;
701
702 TType.List : begin
703 list := prot.ReadListBegin();
704 for i := 0 to list.Count-1
705 do Skip( prot, list.ElementType);
706 prot.ReadListEnd();
707 end;
708
709 else
Jens Geyer5f723cd2017-01-10 21:57:48 +0100710 raise TProtocolExceptionInvalidData.Create('Unexpected type '+IntToStr(Ord(type_)));
Jens Geyerd5436f52014-10-03 19:50:38 +0200711 end;
712end;
713
Jens Geyerd5436f52014-10-03 19:50:38 +0200714
715{ TBinaryProtocolImpl }
716
Jens Geyerfad7fd32019-11-09 23:24:52 +0100717constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead, strictWrite: Boolean);
Jens Geyerd5436f52014-10-03 19:50:38 +0200718begin
Jens Geyerfad7fd32019-11-09 23:24:52 +0100719 inherited Create( trans);
Jens Geyerd5436f52014-10-03 19:50:38 +0200720 FStrictRead := strictRead;
721 FStrictWrite := strictWrite;
722end;
723
Jens Geyer17c3ad92017-09-05 20:31:27 +0200724function TBinaryProtocolImpl.ReadAll( const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer ): Integer;
Jens Geyerd5436f52014-10-03 19:50:38 +0200725begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200726 Result := FTrans.ReadAll( pBuf, buflen, off, len );
Jens Geyerd5436f52014-10-03 19:50:38 +0200727end;
728
729function TBinaryProtocolImpl.ReadBinary: TBytes;
730var
731 size : Integer;
732 buf : TBytes;
733begin
734 size := ReadI32;
Jens Geyer41f47af2019-11-09 23:24:52 +0100735 FTrans.CheckReadBytesAvailable( size);
Jens Geyerfad7fd32019-11-09 23:24:52 +0100736 SetLength( buf, size);
Jens Geyerd5436f52014-10-03 19:50:38 +0200737 FTrans.ReadAll( buf, 0, size);
738 Result := buf;
739end;
740
741function TBinaryProtocolImpl.ReadBool: Boolean;
742begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200743 Result := (ReadByte = 1);
Jens Geyerd5436f52014-10-03 19:50:38 +0200744end;
745
746function TBinaryProtocolImpl.ReadByte: ShortInt;
Jens Geyerd5436f52014-10-03 19:50:38 +0200747begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200748 ReadAll( @result, SizeOf(result), 0, 1);
Jens Geyerd5436f52014-10-03 19:50:38 +0200749end;
750
751function TBinaryProtocolImpl.ReadDouble: Double;
752begin
753 Result := ConvertInt64ToDouble( ReadI64 )
754end;
755
Jens Geyer17c3ad92017-09-05 20:31:27 +0200756function TBinaryProtocolImpl.ReadFieldBegin: TThriftField;
Jens Geyerd5436f52014-10-03 19:50:38 +0200757begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200758 Init( result, '', TType( ReadByte), 0);
759 if ( result.Type_ <> TType.Stop ) then begin
760 result.Id := ReadI16;
Jens Geyerd5436f52014-10-03 19:50:38 +0200761 end;
Jens Geyerd5436f52014-10-03 19:50:38 +0200762end;
763
764procedure TBinaryProtocolImpl.ReadFieldEnd;
765begin
766
767end;
768
769function TBinaryProtocolImpl.ReadI16: SmallInt;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200770var i16in : packed array[0..1] of Byte;
Jens Geyerd5436f52014-10-03 19:50:38 +0200771begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200772 ReadAll( @i16in, Sizeof(i16in), 0, 2);
Jens Geyerd5436f52014-10-03 19:50:38 +0200773 Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF));
774end;
775
776function TBinaryProtocolImpl.ReadI32: Integer;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200777var i32in : packed array[0..3] of Byte;
Jens Geyerd5436f52014-10-03 19:50:38 +0200778begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200779 ReadAll( @i32in, SizeOf(i32in), 0, 4);
Jens Geyerd5436f52014-10-03 19:50:38 +0200780
781 Result := Integer(
782 ((i32in[0] and $FF) shl 24) or
783 ((i32in[1] and $FF) shl 16) or
784 ((i32in[2] and $FF) shl 8) or
785 (i32in[3] and $FF));
786
787end;
788
789function TBinaryProtocolImpl.ReadI64: Int64;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200790var i64in : packed array[0..7] of Byte;
Jens Geyerd5436f52014-10-03 19:50:38 +0200791begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200792 ReadAll( @i64in, SizeOf(i64in), 0, 8);
Jens Geyerd5436f52014-10-03 19:50:38 +0200793 Result :=
794 (Int64( i64in[0] and $FF) shl 56) or
795 (Int64( i64in[1] and $FF) shl 48) or
796 (Int64( i64in[2] and $FF) shl 40) or
797 (Int64( i64in[3] and $FF) shl 32) or
798 (Int64( i64in[4] and $FF) shl 24) or
799 (Int64( i64in[5] and $FF) shl 16) or
800 (Int64( i64in[6] and $FF) shl 8) or
801 (Int64( i64in[7] and $FF));
802end;
803
Jens Geyer17c3ad92017-09-05 20:31:27 +0200804function TBinaryProtocolImpl.ReadListBegin: TThriftList;
Jens Geyerd5436f52014-10-03 19:50:38 +0200805begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200806 result.ElementType := TType(ReadByte);
807 result.Count := ReadI32;
Jens Geyer41f47af2019-11-09 23:24:52 +0100808 CheckReadBytesAvailable(result);
Jens Geyerd5436f52014-10-03 19:50:38 +0200809end;
810
811procedure TBinaryProtocolImpl.ReadListEnd;
812begin
813
814end;
815
Jens Geyer17c3ad92017-09-05 20:31:27 +0200816function TBinaryProtocolImpl.ReadMapBegin: TThriftMap;
Jens Geyerd5436f52014-10-03 19:50:38 +0200817begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200818 result.KeyType := TType(ReadByte);
819 result.ValueType := TType(ReadByte);
820 result.Count := ReadI32;
Jens Geyer41f47af2019-11-09 23:24:52 +0100821 CheckReadBytesAvailable(result);
Jens Geyerd5436f52014-10-03 19:50:38 +0200822end;
823
824procedure TBinaryProtocolImpl.ReadMapEnd;
825begin
826
827end;
828
Jens Geyer17c3ad92017-09-05 20:31:27 +0200829function TBinaryProtocolImpl.ReadMessageBegin: TThriftMessage;
Jens Geyerd5436f52014-10-03 19:50:38 +0200830var
831 size : Integer;
832 version : Integer;
Jens Geyerd5436f52014-10-03 19:50:38 +0200833begin
Jens Geyer41f47af2019-11-09 23:24:52 +0100834 Reset;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200835 Init( result);
Jens Geyerd5436f52014-10-03 19:50:38 +0200836 size := ReadI32;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200837 if (size < 0) then begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200838 version := size and Integer( VERSION_MASK);
Jens Geyer17c3ad92017-09-05 20:31:27 +0200839 if ( version <> Integer( VERSION_1)) then begin
Jens Geyere0e32402016-04-20 21:50:48 +0200840 raise TProtocolExceptionBadVersion.Create('Bad version in ReadMessageBegin: ' + IntToStr(version) );
Jens Geyerd5436f52014-10-03 19:50:38 +0200841 end;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200842 result.Type_ := TMessageType( size and $000000ff);
843 result.Name := ReadString;
844 result.SeqID := ReadI32;
845 end
846 else begin
847 if FStrictRead then begin
Jens Geyere0e32402016-04-20 21:50:48 +0200848 raise TProtocolExceptionBadVersion.Create('Missing version in readMessageBegin, old client?' );
Jens Geyerd5436f52014-10-03 19:50:38 +0200849 end;
Jens Geyer17c3ad92017-09-05 20:31:27 +0200850 result.Name := ReadStringBody( size );
851 result.Type_ := TMessageType( ReadByte );
852 result.SeqID := ReadI32;
Jens Geyerd5436f52014-10-03 19:50:38 +0200853 end;
Jens Geyerd5436f52014-10-03 19:50:38 +0200854end;
855
856procedure TBinaryProtocolImpl.ReadMessageEnd;
857begin
858 inherited;
859
860end;
861
Jens Geyer17c3ad92017-09-05 20:31:27 +0200862function TBinaryProtocolImpl.ReadSetBegin: TThriftSet;
Jens Geyerd5436f52014-10-03 19:50:38 +0200863begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200864 result.ElementType := TType(ReadByte);
865 result.Count := ReadI32;
Jens Geyer41f47af2019-11-09 23:24:52 +0100866 CheckReadBytesAvailable(result);
Jens Geyerd5436f52014-10-03 19:50:38 +0200867end;
868
869procedure TBinaryProtocolImpl.ReadSetEnd;
870begin
871
872end;
873
874function TBinaryProtocolImpl.ReadStringBody( size: Integer): string;
Jens Geyerfad7fd32019-11-09 23:24:52 +0100875var buf : TBytes;
Jens Geyerd5436f52014-10-03 19:50:38 +0200876begin
Jens Geyer41f47af2019-11-09 23:24:52 +0100877 FTrans.CheckReadBytesAvailable( size);
Jens Geyerfad7fd32019-11-09 23:24:52 +0100878 SetLength( buf, size);
Jens Geyerd5436f52014-10-03 19:50:38 +0200879 FTrans.ReadAll( buf, 0, size );
880 Result := TEncoding.UTF8.GetString( buf);
881end;
882
Jens Geyer17c3ad92017-09-05 20:31:27 +0200883function TBinaryProtocolImpl.ReadStructBegin: TThriftStruct;
Jens Geyerd5436f52014-10-03 19:50:38 +0200884begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200885 Init( Result);
Jens Geyerd5436f52014-10-03 19:50:38 +0200886end;
887
888procedure TBinaryProtocolImpl.ReadStructEnd;
889begin
890 inherited;
891
892end;
893
894procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);
895var iLen : Integer;
896begin
897 iLen := Length(b);
898 WriteI32( iLen);
899 if iLen > 0 then FTrans.Write(b, 0, iLen);
900end;
901
902procedure TBinaryProtocolImpl.WriteBool(b: Boolean);
903begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200904 if b then begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200905 WriteByte( 1 );
Jens Geyer17c3ad92017-09-05 20:31:27 +0200906 end else begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200907 WriteByte( 0 );
908 end;
909end;
910
911procedure TBinaryProtocolImpl.WriteByte(b: ShortInt);
Jens Geyerd5436f52014-10-03 19:50:38 +0200912begin
Jens Geyer17c3ad92017-09-05 20:31:27 +0200913 FTrans.Write( @b, 0, 1);
Jens Geyerd5436f52014-10-03 19:50:38 +0200914end;
915
916procedure TBinaryProtocolImpl.WriteDouble( const d: Double);
917begin
918 WriteI64(ConvertDoubleToInt64(d));
919end;
920
Jens Geyer17c3ad92017-09-05 20:31:27 +0200921procedure TBinaryProtocolImpl.WriteFieldBegin( const field: TThriftField);
Jens Geyerd5436f52014-10-03 19:50:38 +0200922begin
923 WriteByte(ShortInt(field.Type_));
924 WriteI16(field.ID);
925end;
926
927procedure TBinaryProtocolImpl.WriteFieldEnd;
928begin
929
930end;
931
932procedure TBinaryProtocolImpl.WriteFieldStop;
933begin
934 WriteByte(ShortInt(TType.Stop));
935end;
936
937procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt);
Jens Geyer17c3ad92017-09-05 20:31:27 +0200938var i16out : packed array[0..1] of Byte;
Jens Geyerd5436f52014-10-03 19:50:38 +0200939begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200940 i16out[0] := Byte($FF and (i16 shr 8));
941 i16out[1] := Byte($FF and i16);
Jens Geyer17c3ad92017-09-05 20:31:27 +0200942 FTrans.Write( @i16out, 0, 2);
Jens Geyerd5436f52014-10-03 19:50:38 +0200943end;
944
945procedure TBinaryProtocolImpl.WriteI32(i32: Integer);
Jens Geyer17c3ad92017-09-05 20:31:27 +0200946var i32out : packed array[0..3] of Byte;
Jens Geyerd5436f52014-10-03 19:50:38 +0200947begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200948 i32out[0] := Byte($FF and (i32 shr 24));
949 i32out[1] := Byte($FF and (i32 shr 16));
950 i32out[2] := Byte($FF and (i32 shr 8));
951 i32out[3] := Byte($FF and i32);
Jens Geyer17c3ad92017-09-05 20:31:27 +0200952 FTrans.Write( @i32out, 0, 4);
Jens Geyerd5436f52014-10-03 19:50:38 +0200953end;
954
955procedure TBinaryProtocolImpl.WriteI64( const i64: Int64);
Jens Geyer17c3ad92017-09-05 20:31:27 +0200956var i64out : packed array[0..7] of Byte;
Jens Geyerd5436f52014-10-03 19:50:38 +0200957begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200958 i64out[0] := Byte($FF and (i64 shr 56));
959 i64out[1] := Byte($FF and (i64 shr 48));
960 i64out[2] := Byte($FF and (i64 shr 40));
961 i64out[3] := Byte($FF and (i64 shr 32));
962 i64out[4] := Byte($FF and (i64 shr 24));
963 i64out[5] := Byte($FF and (i64 shr 16));
964 i64out[6] := Byte($FF and (i64 shr 8));
965 i64out[7] := Byte($FF and i64);
Jens Geyer17c3ad92017-09-05 20:31:27 +0200966 FTrans.Write( @i64out, 0, 8);
Jens Geyerd5436f52014-10-03 19:50:38 +0200967end;
968
Jens Geyer17c3ad92017-09-05 20:31:27 +0200969procedure TBinaryProtocolImpl.WriteListBegin( const list: TThriftList);
Jens Geyerd5436f52014-10-03 19:50:38 +0200970begin
971 WriteByte(ShortInt(list.ElementType));
972 WriteI32(list.Count);
973end;
974
975procedure TBinaryProtocolImpl.WriteListEnd;
976begin
977
978end;
979
Jens Geyer17c3ad92017-09-05 20:31:27 +0200980procedure TBinaryProtocolImpl.WriteMapBegin( const map: TThriftMap);
Jens Geyerd5436f52014-10-03 19:50:38 +0200981begin
982 WriteByte(ShortInt(map.KeyType));
983 WriteByte(ShortInt(map.ValueType));
984 WriteI32(map.Count);
985end;
986
987procedure TBinaryProtocolImpl.WriteMapEnd;
988begin
989
990end;
991
Jens Geyer17c3ad92017-09-05 20:31:27 +0200992procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: TThriftMessage);
Jens Geyerfad7fd32019-11-09 23:24:52 +0100993var version : Cardinal;
Jens Geyerd5436f52014-10-03 19:50:38 +0200994begin
Jens Geyer41f47af2019-11-09 23:24:52 +0100995 Reset;
Jens Geyerfad7fd32019-11-09 23:24:52 +0100996 if FStrictWrite then begin
Jens Geyerd5436f52014-10-03 19:50:38 +0200997 version := VERSION_1 or Cardinal( msg.Type_);
998 WriteI32( Integer( version) );
999 WriteString( msg.Name);
1000 WriteI32( msg.SeqID);
Jens Geyerfad7fd32019-11-09 23:24:52 +01001001 end else begin
Jens Geyerd5436f52014-10-03 19:50:38 +02001002 WriteString( msg.Name);
1003 WriteByte(ShortInt( msg.Type_));
1004 WriteI32( msg.SeqID);
1005 end;
1006end;
1007
1008procedure TBinaryProtocolImpl.WriteMessageEnd;
1009begin
1010
1011end;
1012
Jens Geyer17c3ad92017-09-05 20:31:27 +02001013procedure TBinaryProtocolImpl.WriteSetBegin( const set_: TThriftSet);
Jens Geyerd5436f52014-10-03 19:50:38 +02001014begin
1015 WriteByte(ShortInt(set_.ElementType));
1016 WriteI32(set_.Count);
1017end;
1018
1019procedure TBinaryProtocolImpl.WriteSetEnd;
1020begin
1021
1022end;
1023
Jens Geyer17c3ad92017-09-05 20:31:27 +02001024procedure TBinaryProtocolImpl.WriteStructBegin( const struc: TThriftStruct);
Jens Geyerd5436f52014-10-03 19:50:38 +02001025begin
1026
1027end;
1028
1029procedure TBinaryProtocolImpl.WriteStructEnd;
1030begin
1031
1032end;
1033
Jens Geyer41f47af2019-11-09 23:24:52 +01001034function TBinaryProtocolImpl.GetMinSerializedSize( const aType : TType) : Integer;
1035// Return the minimum number of bytes a type will consume on the wire
1036begin
1037 case aType of
1038 TType.Stop: result := 0;
1039 TType.Void: result := 0;
1040 TType.Bool_: result := SizeOf(Byte);
1041 TType.Byte_: result := SizeOf(Byte);
1042 TType.Double_: result := SizeOf(Double);
1043 TType.I16: result := SizeOf(Int16);
1044 TType.I32: result := SizeOf(Int32);
1045 TType.I64: result := SizeOf(Int64);
1046 TType.String_: result := SizeOf(Int32); // string length
1047 TType.Struct: result := 0; // empty struct
1048 TType.Map: result := SizeOf(Int32); // element count
1049 TType.Set_: result := SizeOf(Int32); // element count
1050 TType.List: result := SizeOf(Int32); // element count
1051 else
1052 raise TTransportExceptionBadArgs.Create('Unhandled type code');
1053 end;
1054end;
1055
1056
Jens Geyerd5436f52014-10-03 19:50:38 +02001057{ TProtocolException }
1058
Jens Geyere0e32402016-04-20 21:50:48 +02001059constructor TProtocolException.HiddenCreate(const Msg: string);
Jens Geyerd5436f52014-10-03 19:50:38 +02001060begin
Jens Geyere0e32402016-04-20 21:50:48 +02001061 inherited Create(Msg);
Jens Geyerd5436f52014-10-03 19:50:38 +02001062end;
1063
Jens Geyere0e32402016-04-20 21:50:48 +02001064class function TProtocolException.Create(const Msg: string): TProtocolException;
Jens Geyerd5436f52014-10-03 19:50:38 +02001065begin
Jens Geyere0e32402016-04-20 21:50:48 +02001066 Result := TProtocolExceptionUnknown.Create(Msg);
Jens Geyerd5436f52014-10-03 19:50:38 +02001067end;
1068
Jens Geyere0e32402016-04-20 21:50:48 +02001069class function TProtocolException.Create: TProtocolException;
Jens Geyerd5436f52014-10-03 19:50:38 +02001070begin
Jens Geyere0e32402016-04-20 21:50:48 +02001071 Result := TProtocolExceptionUnknown.Create('');
1072end;
1073
Jens Geyer9f11c1e2019-11-09 19:39:20 +01001074class function TProtocolException.Create(aType: TExceptionType): TProtocolException;
Jens Geyere0e32402016-04-20 21:50:48 +02001075begin
1076{$WARN SYMBOL_DEPRECATED OFF}
Jens Geyer9f11c1e2019-11-09 19:39:20 +01001077 Result := Create(aType, '');
Jens Geyere0e32402016-04-20 21:50:48 +02001078{$WARN SYMBOL_DEPRECATED DEFAULT}
1079end;
1080
Jens Geyer9f11c1e2019-11-09 19:39:20 +01001081class function TProtocolException.Create(aType: TExceptionType; const msg: string): TProtocolException;
Jens Geyere0e32402016-04-20 21:50:48 +02001082begin
Jens Geyer9f11c1e2019-11-09 19:39:20 +01001083 case aType of
1084 TExceptionType.INVALID_DATA: Result := TProtocolExceptionInvalidData.Create(msg);
1085 TExceptionType.NEGATIVE_SIZE: Result := TProtocolExceptionNegativeSize.Create(msg);
1086 TExceptionType.SIZE_LIMIT: Result := TProtocolExceptionSizeLimit.Create(msg);
1087 TExceptionType.BAD_VERSION: Result := TProtocolExceptionBadVersion.Create(msg);
1088 TExceptionType.NOT_IMPLEMENTED: Result := TProtocolExceptionNotImplemented.Create(msg);
1089 TExceptionType.DEPTH_LIMIT: Result := TProtocolExceptionDepthLimit.Create(msg);
Jens Geyere0e32402016-04-20 21:50:48 +02001090 else
Jens Geyer9f11c1e2019-11-09 19:39:20 +01001091 ASSERT( TExceptionType.UNKNOWN = aType);
Jens Geyere0e32402016-04-20 21:50:48 +02001092 Result := TProtocolExceptionUnknown.Create(msg);
1093 end;
1094end;
1095
1096{ TProtocolExceptionSpecialized }
1097
1098constructor TProtocolExceptionSpecialized.Create(const Msg: string);
1099begin
1100 inherited HiddenCreate(Msg);
Jens Geyerd5436f52014-10-03 19:50:38 +02001101end;
1102
Jens Geyer9f11c1e2019-11-09 19:39:20 +01001103{ specialized TProtocolExceptions }
1104
1105class function TProtocolExceptionUnknown.GetType: TProtocolException.TExceptionType;
1106begin
1107 result := TExceptionType.UNKNOWN;
1108end;
1109
1110class function TProtocolExceptionInvalidData.GetType: TProtocolException.TExceptionType;
1111begin
1112 result := TExceptionType.INVALID_DATA;
1113end;
1114
1115class function TProtocolExceptionNegativeSize.GetType: TProtocolException.TExceptionType;
1116begin
1117 result := TExceptionType.NEGATIVE_SIZE;
1118end;
1119
1120class function TProtocolExceptionSizeLimit.GetType: TProtocolException.TExceptionType;
1121begin
1122 result := TExceptionType.SIZE_LIMIT;
1123end;
1124
1125class function TProtocolExceptionBadVersion.GetType: TProtocolException.TExceptionType;
1126begin
1127 result := TExceptionType.BAD_VERSION;
1128end;
1129
1130class function TProtocolExceptionNotImplemented.GetType: TProtocolException.TExceptionType;
1131begin
1132 result := TExceptionType.NOT_IMPLEMENTED;
1133end;
1134
1135class function TProtocolExceptionDepthLimit.GetType: TProtocolException.TExceptionType;
1136begin
1137 result := TExceptionType.DEPTH_LIMIT;
1138end;
1139
Jens Geyerd5436f52014-10-03 19:50:38 +02001140{ TBinaryProtocolImpl.TFactory }
1141
Jens Geyerfad7fd32019-11-09 23:24:52 +01001142constructor TBinaryProtocolImpl.TFactory.Create( const aStrictRead, aStrictWrite: Boolean);
Jens Geyerd5436f52014-10-03 19:50:38 +02001143begin
1144 inherited Create;
1145 FStrictRead := AStrictRead;
1146 FStrictWrite := AStrictWrite;
1147end;
1148
Jens Geyerd5436f52014-10-03 19:50:38 +02001149function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
1150begin
1151 Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite);
1152end;
1153
1154
1155{ TProtocolDecorator }
1156
1157constructor TProtocolDecorator.Create( const aProtocol : IProtocol);
1158begin
1159 ASSERT( aProtocol <> nil);
1160 inherited Create( aProtocol.Transport);
1161 FWrappedProtocol := aProtocol;
1162end;
1163
1164
Jens Geyer17c3ad92017-09-05 20:31:27 +02001165procedure TProtocolDecorator.WriteMessageBegin( const msg: TThriftMessage);
Jens Geyerd5436f52014-10-03 19:50:38 +02001166begin
1167 FWrappedProtocol.WriteMessageBegin( msg);
1168end;
1169
1170
1171procedure TProtocolDecorator.WriteMessageEnd;
1172begin
1173 FWrappedProtocol.WriteMessageEnd;
1174end;
1175
1176
Jens Geyer17c3ad92017-09-05 20:31:27 +02001177procedure TProtocolDecorator.WriteStructBegin( const struc: TThriftStruct);
Jens Geyerd5436f52014-10-03 19:50:38 +02001178begin
1179 FWrappedProtocol.WriteStructBegin( struc);
1180end;
1181
1182
1183procedure TProtocolDecorator.WriteStructEnd;
1184begin
1185 FWrappedProtocol.WriteStructEnd;
1186end;
1187
1188
Jens Geyer17c3ad92017-09-05 20:31:27 +02001189procedure TProtocolDecorator.WriteFieldBegin( const field: TThriftField);
Jens Geyerd5436f52014-10-03 19:50:38 +02001190begin
1191 FWrappedProtocol.WriteFieldBegin( field);
1192end;
1193
1194
1195procedure TProtocolDecorator.WriteFieldEnd;
1196begin
1197 FWrappedProtocol.WriteFieldEnd;
1198end;
1199
1200
1201procedure TProtocolDecorator.WriteFieldStop;
1202begin
1203 FWrappedProtocol.WriteFieldStop;
1204end;
1205
1206
Jens Geyer17c3ad92017-09-05 20:31:27 +02001207procedure TProtocolDecorator.WriteMapBegin( const map: TThriftMap);
Jens Geyerd5436f52014-10-03 19:50:38 +02001208begin
1209 FWrappedProtocol.WriteMapBegin( map);
1210end;
1211
1212
1213procedure TProtocolDecorator.WriteMapEnd;
1214begin
1215 FWrappedProtocol.WriteMapEnd;
1216end;
1217
1218
Jens Geyer17c3ad92017-09-05 20:31:27 +02001219procedure TProtocolDecorator.WriteListBegin( const list: TThriftList);
Jens Geyerd5436f52014-10-03 19:50:38 +02001220begin
1221 FWrappedProtocol.WriteListBegin( list);
1222end;
1223
1224
1225procedure TProtocolDecorator.WriteListEnd();
1226begin
1227 FWrappedProtocol.WriteListEnd();
1228end;
1229
1230
Jens Geyer17c3ad92017-09-05 20:31:27 +02001231procedure TProtocolDecorator.WriteSetBegin( const set_: TThriftSet );
Jens Geyerd5436f52014-10-03 19:50:38 +02001232begin
1233 FWrappedProtocol.WriteSetBegin( set_);
1234end;
1235
1236
1237procedure TProtocolDecorator.WriteSetEnd();
1238begin
1239 FWrappedProtocol.WriteSetEnd();
1240end;
1241
1242
1243procedure TProtocolDecorator.WriteBool( b: Boolean);
1244begin
1245 FWrappedProtocol.WriteBool( b);
1246end;
1247
1248
1249procedure TProtocolDecorator.WriteByte( b: ShortInt);
1250begin
1251 FWrappedProtocol.WriteByte( b);
1252end;
1253
1254
1255procedure TProtocolDecorator.WriteI16( i16: SmallInt);
1256begin
1257 FWrappedProtocol.WriteI16( i16);
1258end;
1259
1260
1261procedure TProtocolDecorator.WriteI32( i32: Integer);
1262begin
1263 FWrappedProtocol.WriteI32( i32);
1264end;
1265
1266
1267procedure TProtocolDecorator.WriteI64( const i64: Int64);
1268begin
1269 FWrappedProtocol.WriteI64( i64);
1270end;
1271
1272
1273procedure TProtocolDecorator.WriteDouble( const d: Double);
1274begin
1275 FWrappedProtocol.WriteDouble( d);
1276end;
1277
1278
1279procedure TProtocolDecorator.WriteString( const s: string );
1280begin
1281 FWrappedProtocol.WriteString( s);
1282end;
1283
1284
1285procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString);
1286begin
1287 FWrappedProtocol.WriteAnsiString( s);
1288end;
1289
1290
1291procedure TProtocolDecorator.WriteBinary( const b: TBytes);
1292begin
1293 FWrappedProtocol.WriteBinary( b);
1294end;
1295
1296
Jens Geyer17c3ad92017-09-05 20:31:27 +02001297function TProtocolDecorator.ReadMessageBegin: TThriftMessage;
Jens Geyerd5436f52014-10-03 19:50:38 +02001298begin
1299 result := FWrappedProtocol.ReadMessageBegin;
1300end;
1301
1302
1303procedure TProtocolDecorator.ReadMessageEnd();
1304begin
1305 FWrappedProtocol.ReadMessageEnd();
1306end;
1307
1308
Jens Geyer17c3ad92017-09-05 20:31:27 +02001309function TProtocolDecorator.ReadStructBegin: TThriftStruct;
Jens Geyerd5436f52014-10-03 19:50:38 +02001310begin
1311 result := FWrappedProtocol.ReadStructBegin;
1312end;
1313
1314
1315procedure TProtocolDecorator.ReadStructEnd;
1316begin
1317 FWrappedProtocol.ReadStructEnd;
1318end;
1319
1320
Jens Geyer17c3ad92017-09-05 20:31:27 +02001321function TProtocolDecorator.ReadFieldBegin: TThriftField;
Jens Geyerd5436f52014-10-03 19:50:38 +02001322begin
1323 result := FWrappedProtocol.ReadFieldBegin;
1324end;
1325
1326
1327procedure TProtocolDecorator.ReadFieldEnd();
1328begin
1329 FWrappedProtocol.ReadFieldEnd();
1330end;
1331
1332
Jens Geyer17c3ad92017-09-05 20:31:27 +02001333function TProtocolDecorator.ReadMapBegin: TThriftMap;
Jens Geyerd5436f52014-10-03 19:50:38 +02001334begin
1335 result := FWrappedProtocol.ReadMapBegin;
1336end;
1337
1338
1339procedure TProtocolDecorator.ReadMapEnd();
1340begin
1341 FWrappedProtocol.ReadMapEnd();
1342end;
1343
1344
Jens Geyer17c3ad92017-09-05 20:31:27 +02001345function TProtocolDecorator.ReadListBegin: TThriftList;
Jens Geyerd5436f52014-10-03 19:50:38 +02001346begin
1347 result := FWrappedProtocol.ReadListBegin;
1348end;
1349
1350
1351procedure TProtocolDecorator.ReadListEnd();
1352begin
1353 FWrappedProtocol.ReadListEnd();
1354end;
1355
1356
Jens Geyer17c3ad92017-09-05 20:31:27 +02001357function TProtocolDecorator.ReadSetBegin: TThriftSet;
Jens Geyerd5436f52014-10-03 19:50:38 +02001358begin
1359 result := FWrappedProtocol.ReadSetBegin;
1360end;
1361
1362
1363procedure TProtocolDecorator.ReadSetEnd();
1364begin
1365 FWrappedProtocol.ReadSetEnd();
1366end;
1367
1368
1369function TProtocolDecorator.ReadBool: Boolean;
1370begin
1371 result := FWrappedProtocol.ReadBool;
1372end;
1373
1374
1375function TProtocolDecorator.ReadByte: ShortInt;
1376begin
1377 result := FWrappedProtocol.ReadByte;
1378end;
1379
1380
1381function TProtocolDecorator.ReadI16: SmallInt;
1382begin
1383 result := FWrappedProtocol.ReadI16;
1384end;
1385
1386
1387function TProtocolDecorator.ReadI32: Integer;
1388begin
1389 result := FWrappedProtocol.ReadI32;
1390end;
1391
1392
1393function TProtocolDecorator.ReadI64: Int64;
1394begin
1395 result := FWrappedProtocol.ReadI64;
1396end;
1397
1398
1399function TProtocolDecorator.ReadDouble:Double;
1400begin
1401 result := FWrappedProtocol.ReadDouble;
1402end;
1403
1404
1405function TProtocolDecorator.ReadBinary: TBytes;
1406begin
1407 result := FWrappedProtocol.ReadBinary;
1408end;
1409
1410
1411function TProtocolDecorator.ReadString: string;
1412begin
1413 result := FWrappedProtocol.ReadString;
1414end;
1415
1416
1417function TProtocolDecorator.ReadAnsiString: AnsiString;
1418begin
1419 result := FWrappedProtocol.ReadAnsiString;
1420end;
1421
1422
Jens Geyer41f47af2019-11-09 23:24:52 +01001423function TProtocolDecorator.GetMinSerializedSize( const aType : TType) : Integer;
1424begin
1425 result := FWrappedProtocol.GetMinSerializedSize(aType);
1426end;
1427
1428
Jens Geyer17c3ad92017-09-05 20:31:27 +02001429{ Init helper functions }
1430
1431procedure Init( var rec : TThriftMessage; const AName: string; const AMessageType: TMessageType; const ASeqID: Integer);
1432begin
1433 rec.Name := AName;
1434 rec.Type_ := AMessageType;
1435 rec.SeqID := ASeqID;
1436end;
1437
1438
1439procedure Init( var rec : TThriftStruct; const AName: string = '');
1440begin
1441 rec.Name := AName;
1442end;
1443
1444
1445procedure Init( var rec : TThriftField; const AName: string; const AType: TType; const AID: SmallInt);
1446begin
1447 rec.Name := AName;
1448 rec.Type_ := AType;
1449 rec.Id := AId;
1450end;
1451
1452
1453procedure Init( var rec : TThriftMap; const AKeyType, AValueType: TType; const ACount: Integer);
1454begin
1455 rec.ValueType := AValueType;
1456 rec.KeyType := AKeyType;
1457 rec.Count := ACount;
1458end;
1459
1460
1461procedure Init( var rec : TThriftSet; const AElementType: TType; const ACount: Integer);
1462begin
1463 rec.Count := ACount;
1464 rec.ElementType := AElementType;
1465end;
1466
1467
1468procedure Init( var rec : TThriftList; const AElementType: TType; const ACount: Integer);
1469begin
1470 rec.Count := ACount;
1471 rec.ElementType := AElementType;
1472end;
1473
1474
1475
Jens Geyerd5436f52014-10-03 19:50:38 +02001476end.
1477