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