1 (*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *)
19
20 {$SCOPEDENUMS ON}
21
22 unit Thrift.Protocol;
23
24 interface
25
26 uses
27 Classes,
28 SysUtils,
29 Contnrs,
30 Thrift.Exception,
31 Thrift.Stream,
32 Thrift.Utils,
33 Thrift.Collections,
34 Thrift.Configuration,
35 Thrift.Transport;
36
37 type
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
62 const
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
71 type
72 IProtocol = interface;
73
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
107 IProtocolFactory = interface
108 ['{7CD64A10-4E9F-4E99-93BF-708A31F4A67B}']
GetProtocolnull109 function GetProtocol( const trans: ITransport): IProtocol;
110 end;
111
112 TProtocolException = class abstract( TException)
113 public
114 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 );
123 strict protected
124 constructor HiddenCreate(const Msg: string);
GetTypenull125 class function GetType: TExceptionType; virtual; abstract;
126 public
127 // purposefully hide inherited constructor
128 class function Create(const Msg: string): TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)';
Createnull129 class function Create: TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)';
Createnull130 class function Create( aType: TExceptionType): TProtocolException; overload; deprecated 'Use specialized TProtocolException types (or regenerate from IDL)';
Createnull131 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;
133 end;
134
135 // Needed to remove deprecation warning
136 TProtocolExceptionSpecialized = class abstract (TProtocolException)
137 public
138 constructor Create(const Msg: string);
139 end;
140
141 TProtocolExceptionUnknown = class (TProtocolExceptionSpecialized)
142 strict protected
GetTypenull143 class function GetType: TProtocolException.TExceptionType; override;
144 end;
145
146 TProtocolExceptionInvalidData = class (TProtocolExceptionSpecialized)
147 strict protected
GetTypenull148 class function GetType: TProtocolException.TExceptionType; override;
149 end;
150
151 TProtocolExceptionNegativeSize = class (TProtocolExceptionSpecialized)
152 strict protected
GetTypenull153 class function GetType: TProtocolException.TExceptionType; override;
154 end;
155
156 TProtocolExceptionSizeLimit = class (TProtocolExceptionSpecialized)
157 strict protected
GetTypenull158 class function GetType: TProtocolException.TExceptionType; override;
159 end;
160
161 TProtocolExceptionBadVersion = class (TProtocolExceptionSpecialized)
162 strict protected
GetTypenull163 class function GetType: TProtocolException.TExceptionType; override;
164 end;
165
166 TProtocolExceptionNotImplemented = class (TProtocolExceptionSpecialized)
167 strict protected
GetTypenull168 class function GetType: TProtocolException.TExceptionType; override;
169 end;
170
171 TProtocolExceptionDepthLimit = class (TProtocolExceptionSpecialized)
172 strict protected
GetTypenull173 class function GetType: TProtocolException.TExceptionType; override;
174 end;
175
176
177
178 TProtocolUtil = class
179 public
180 class procedure Skip( prot: IProtocol; type_: TType);
181 end;
182
183 IProtocolRecursionTracker = interface
184 ['{29CA033F-BB56-49B1-9EE3-31B1E82FC7A5}']
185 // no members yet
186 end;
187
188 TProtocolRecursionTrackerImpl = class abstract( TInterfacedObject, IProtocolRecursionTracker)
189 strict protected
190 FProtocol : IProtocol;
191 public
192 constructor Create( prot : IProtocol);
193 destructor Destroy; override;
194 end;
195
196 IProtocol = interface
197 ['{F0040D99-937F-400D-9932-AF04F665899F}']
GetTransportnull198 function GetTransport: ITransport;
199 procedure WriteMessageBegin( const msg: TThriftMessage);
200 procedure WriteMessageEnd;
201 procedure WriteStructBegin( const struc: TThriftStruct);
202 procedure WriteStructEnd;
203 procedure WriteFieldBegin( const field: TThriftField);
204 procedure WriteFieldEnd;
205 procedure WriteFieldStop;
206 procedure WriteMapBegin( const map: TThriftMap);
207 procedure WriteMapEnd;
208 procedure WriteListBegin( const list: TThriftList);
209 procedure WriteListEnd();
210 procedure WriteSetBegin( const set_: TThriftSet );
211 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
ReadMessageBeginnull222 function ReadMessageBegin: TThriftMessage;
223 procedure ReadMessageEnd();
ReadStructBeginnull224 function ReadStructBegin: TThriftStruct;
225 procedure ReadStructEnd;
ReadFieldBeginnull226 function ReadFieldBegin: TThriftField;
227 procedure ReadFieldEnd();
ReadMapBeginnull228 function ReadMapBegin: TThriftMap;
229 procedure ReadMapEnd();
ReadListBeginnull230 function ReadListBegin: TThriftList;
231 procedure ReadListEnd();
ReadSetBeginnull232 function ReadSetBegin: TThriftSet;
233 procedure ReadSetEnd();
ReadBoolnull234 function ReadBool: Boolean;
ReadBytenull235 function ReadByte: ShortInt;
ReadI16null236 function ReadI16: SmallInt;
ReadI32null237 function ReadI32: Integer;
ReadI64null238 function ReadI64: Int64;
ReadDoublenull239 function ReadDouble:Double;
ReadBinarynull240 function ReadBinary: TBytes;
ReadStringnull241 function ReadString: string;
ReadAnsiStringnull242 function ReadAnsiString: AnsiString;
243
NextRecursionLevelnull244 function NextRecursionLevel : IProtocolRecursionTracker;
245 procedure IncrementRecursionDepth;
246 procedure DecrementRecursionDepth;
GetMinSerializedSizenull247 function GetMinSerializedSize( const aType : TType) : Integer;
248
249 property Transport: ITransport read GetTransport;
Configurationnull250 function Configuration : IThriftConfiguration;
251 end;
252
253 TProtocolImpl = class abstract( TInterfacedObject, IProtocol)
254 strict protected
255 FTrans : ITransport;
256 FRecursionLimit : Integer;
257 FRecursionDepth : Integer;
258
NextRecursionLevelnull259 function NextRecursionLevel : IProtocolRecursionTracker;
260 procedure IncrementRecursionDepth;
261 procedure DecrementRecursionDepth;
262
GetMinSerializedSizenull263 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;
GetTransportnull269 function GetTransport: ITransport;
Configurationnull270 function Configuration : IThriftConfiguration;
271
272 procedure WriteMessageBegin( const msg: TThriftMessage); virtual; abstract;
273 procedure WriteMessageEnd; virtual; abstract;
274 procedure WriteStructBegin( const struc: TThriftStruct); virtual; abstract;
275 procedure WriteStructEnd; virtual; abstract;
276 procedure WriteFieldBegin( const field: TThriftField); virtual; abstract;
277 procedure WriteFieldEnd; virtual; abstract;
278 procedure WriteFieldStop; virtual; abstract;
279 procedure WriteMapBegin( const map: TThriftMap); virtual; abstract;
280 procedure WriteMapEnd; virtual; abstract;
281 procedure WriteListBegin( const list: TThriftList); virtual; abstract;
282 procedure WriteListEnd(); virtual; abstract;
283 procedure WriteSetBegin( const set_: TThriftSet ); virtual; abstract;
284 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
ReadMessageBeginnull295 function ReadMessageBegin: TThriftMessage; virtual; abstract;
296 procedure ReadMessageEnd(); virtual; abstract;
ReadStructBeginnull297 function ReadStructBegin: TThriftStruct; virtual; abstract;
298 procedure ReadStructEnd; virtual; abstract;
ReadFieldBeginnull299 function ReadFieldBegin: TThriftField; virtual; abstract;
300 procedure ReadFieldEnd(); virtual; abstract;
ReadMapBeginnull301 function ReadMapBegin: TThriftMap; virtual; abstract;
302 procedure ReadMapEnd(); virtual; abstract;
ReadListBeginnull303 function ReadListBegin: TThriftList; virtual; abstract;
304 procedure ReadListEnd(); virtual; abstract;
ReadSetBeginnull305 function ReadSetBegin: TThriftSet; virtual; abstract;
306 procedure ReadSetEnd(); virtual; abstract;
ReadBoolnull307 function ReadBool: Boolean; virtual; abstract;
ReadBytenull308 function ReadByte: ShortInt; virtual; abstract;
ReadI16null309 function ReadI16: SmallInt; virtual; abstract;
ReadI32null310 function ReadI32: Integer; virtual; abstract;
ReadI64null311 function ReadI64: Int64; virtual; abstract;
ReadDoublenull312 function ReadDouble:Double; virtual; abstract;
ReadBinarynull313 function ReadBinary: TBytes; virtual; abstract;
ReadStringnull314 function ReadString: string; virtual;
ReadAnsiStringnull315 function ReadAnsiString: AnsiString; virtual;
316
317 property Transport: ITransport read GetTransport;
318
319 public
320 constructor Create( const aTransport : ITransport);
321 end;
322
323 IBase = interface( ISupportsToString)
324 ['{AFF6CECA-5200-4540-950E-9B89E0C1C00C}']
325 procedure Read( const iprot: IProtocol);
326 procedure Write( const iprot: IProtocol);
327 end;
328
329
330 TBinaryProtocolImpl = class( TProtocolImpl )
331 strict protected
332 const
333 VERSION_MASK : Cardinal = $ffff0000;
334 VERSION_1 : Cardinal = $80010000;
335 strict protected
336 FStrictRead : Boolean;
337 FStrictWrite : Boolean;
GetMinSerializedSizenull338 function GetMinSerializedSize( const aType : TType) : Integer; override;
339
340 strict private
ReadAllnull341 function ReadAll( const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer ): Integer; inline;
ReadStringBodynull342 function ReadStringBody( size: Integer): string;
343
344 public
345 type
346 TFactory = class( TInterfacedObject, IProtocolFactory)
347 strict protected
348 FStrictRead : Boolean;
349 FStrictWrite : Boolean;
GetProtocolnull350 function GetProtocol( const trans: ITransport): IProtocol;
351 public
352 constructor Create( const aStrictRead : Boolean = FALSE; const aStrictWrite: Boolean = TRUE); reintroduce;
353 end;
354
355 constructor Create( const trans: ITransport; strictRead: Boolean = FALSE; strictWrite: Boolean = TRUE); reintroduce;
356
357 procedure WriteMessageBegin( const msg: TThriftMessage); override;
358 procedure WriteMessageEnd; override;
359 procedure WriteStructBegin( const struc: TThriftStruct); override;
360 procedure WriteStructEnd; override;
361 procedure WriteFieldBegin( const field: TThriftField); override;
362 procedure WriteFieldEnd; override;
363 procedure WriteFieldStop; override;
364 procedure WriteMapBegin( const map: TThriftMap); override;
365 procedure WriteMapEnd; override;
366 procedure WriteListBegin( const list: TThriftList); override;
367 procedure WriteListEnd(); override;
368 procedure WriteSetBegin( const set_: TThriftSet ); override;
369 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
ReadMessageBeginnull378 function ReadMessageBegin: TThriftMessage; override;
379 procedure ReadMessageEnd(); override;
ReadStructBeginnull380 function ReadStructBegin: TThriftStruct; override;
381 procedure ReadStructEnd; override;
ReadFieldBeginnull382 function ReadFieldBegin: TThriftField; override;
383 procedure ReadFieldEnd(); override;
ReadMapBeginnull384 function ReadMapBegin: TThriftMap; override;
385 procedure ReadMapEnd(); override;
ReadListBeginnull386 function ReadListBegin: TThriftList; override;
387 procedure ReadListEnd(); override;
ReadSetBeginnull388 function ReadSetBegin: TThriftSet; override;
389 procedure ReadSetEnd(); override;
ReadBoolnull390 function ReadBool: Boolean; override;
ReadBytenull391 function ReadByte: ShortInt; override;
ReadI16null392 function ReadI16: SmallInt; override;
ReadI32null393 function ReadI32: Integer; override;
ReadI64null394 function ReadI64: Int64; override;
ReadDoublenull395 function ReadDouble:Double; override;
ReadBinarynull396 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)
408 strict private
409 FWrappedProtocol : IProtocol;
410
411 strict protected
GetMinSerializedSizenull412 function GetMinSerializedSize( const aType : TType) : Integer; override;
413
414 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
419 procedure WriteMessageBegin( const msg: TThriftMessage); override;
420 procedure WriteMessageEnd; override;
421 procedure WriteStructBegin( const struc: TThriftStruct); override;
422 procedure WriteStructEnd; override;
423 procedure WriteFieldBegin( const field: TThriftField); override;
424 procedure WriteFieldEnd; override;
425 procedure WriteFieldStop; override;
426 procedure WriteMapBegin( const map: TThriftMap); override;
427 procedure WriteMapEnd; override;
428 procedure WriteListBegin( const list: TThriftList); override;
429 procedure WriteListEnd(); override;
430 procedure WriteSetBegin( const set_: TThriftSet ); override;
431 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
ReadMessageBeginnull442 function ReadMessageBegin: TThriftMessage; override;
443 procedure ReadMessageEnd(); override;
ReadStructBeginnull444 function ReadStructBegin: TThriftStruct; override;
445 procedure ReadStructEnd; override;
ReadFieldBeginnull446 function ReadFieldBegin: TThriftField; override;
447 procedure ReadFieldEnd(); override;
ReadMapBeginnull448 function ReadMapBegin: TThriftMap; override;
449 procedure ReadMapEnd(); override;
ReadListBeginnull450 function ReadListBegin: TThriftList; override;
451 procedure ReadListEnd(); override;
ReadSetBeginnull452 function ReadSetBegin: TThriftSet; override;
453 procedure ReadSetEnd(); override;
ReadBoolnull454 function ReadBool: Boolean; override;
ReadBytenull455 function ReadByte: ShortInt; override;
ReadI16null456 function ReadI16: SmallInt; override;
ReadI32null457 function ReadI32: Integer; override;
ReadI64null458 function ReadI64: Int64; override;
ReadDoublenull459 function ReadDouble:Double; override;
ReadBinarynull460 function ReadBinary: TBytes; override;
ReadStringnull461 function ReadString: string; override;
ReadAnsiStringnull462 function ReadAnsiString: AnsiString; override;
463 end;
464
465
466 type
467 IRequestEvents = interface
468 ['{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;
callnull477 // 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);
invocationnull490 // 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}']
Processnull499 function Process( const iprot :IProtocol; const oprot: IProtocol; const events : IProcessorEvents = nil): Boolean;
500 end;
501
502
503 procedure Init( var rec : TThriftMessage; const AName: string = ''; const AMessageType: TMessageType = Low(TMessageType); const ASeqID: Integer = 0); overload; inline;
504 procedure Init( var rec : TThriftStruct; const AName: string = ''); overload; inline;
505 procedure Init( var rec : TThriftField; const AName: string = ''; const AType: TType = Low(TType); const AID: SmallInt = 0); overload; inline;
506 procedure Init( var rec : TThriftMap; const AKeyType: TType = Low(TType); const AValueType: TType = Low(TType); const ACount: Integer = 0); overload; inline;
507 procedure Init( var rec : TThriftSet; const AElementType: TType = Low(TType); const ACount: Integer = 0); overload; inline;
508 procedure Init( var rec : TThriftList; const AElementType: TType = Low(TType); const ACount: Integer = 0); overload; inline;
509
510
511 implementation
512
ConvertInt64ToDoublenull513 function ConvertInt64ToDouble( const n: Int64): Double; inline;
514 begin
515 ASSERT( SizeOf(n) = SizeOf(Result));
516 System.Move( n, Result, SizeOf(Result));
517 end;
518
ConvertDoubleToInt64null519 function ConvertDoubleToInt64( const d: Double): Int64; inline;
520 begin
521 ASSERT( SizeOf(d) = SizeOf(Result));
522 System.Move( d, Result, SizeOf(Result));
523 end;
524
525
526
527 { TProtocolRecursionTrackerImpl }
528
529 constructor TProtocolRecursionTrackerImpl.Create( prot : IProtocol);
530 begin
531 inherited Create;
532
533 // storing the pointer *after* the (successful) increment is important here
534 prot.IncrementRecursionDepth;
535 FProtocol := prot;
536 end;
537
538 destructor TProtocolRecursionTrackerImpl.Destroy;
539 begin
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;
549 end;
550
551 { TProtocolImpl }
552
553 constructor TProtocolImpl.Create( const aTransport : ITransport);
554 begin
555 inherited Create;
556 FTrans := aTransport;
557 FRecursionLimit := aTransport.Configuration.RecursionLimit;
558 FRecursionDepth := 0;
559 end;
560
TProtocolImpl.NextRecursionLevelnull561 function TProtocolImpl.NextRecursionLevel : IProtocolRecursionTracker;
562 begin
563 result := TProtocolRecursionTrackerImpl.Create(Self);
564 end;
565
566 procedure TProtocolImpl.IncrementRecursionDepth;
567 begin
568 if FRecursionDepth < FRecursionLimit
569 then Inc(FRecursionDepth)
570 else raise TProtocolExceptionDepthLimit.Create('Depth limit exceeded');
571 end;
572
573 procedure TProtocolImpl.DecrementRecursionDepth;
574 begin
575 Dec(FRecursionDepth)
576 end;
577
GetTransportnull578 function TProtocolImpl.GetTransport: ITransport;
579 begin
580 Result := FTrans;
581 end;
582
TProtocolImpl.Configurationnull583 function TProtocolImpl.Configuration : IThriftConfiguration;
584 begin
585 Result := FTrans.Configuration;
586 end;
587
588 procedure TProtocolImpl.Reset;
589 begin
590 FTrans.ResetConsumedMessageSize;
591 end;
592
ReadAnsiStringnull593 function TProtocolImpl.ReadAnsiString: AnsiString;
594 var
595 b : TBytes;
596 len : Integer;
597 begin
598 Result := '';
599 b := ReadBinary;
600 len := Length( b );
601 if len > 0 then begin
602 SetLength( Result, len);
603 System.Move( b[0], Pointer(Result)^, len );
604 end;
605 end;
606
ReadStringnull607 function TProtocolImpl.ReadString: string;
608 begin
609 Result := TEncoding.UTF8.GetString( ReadBinary );
610 end;
611
612 procedure TProtocolImpl.WriteAnsiString(const s: AnsiString);
613 var
614 b : TBytes;
615 len : Integer;
616 begin
617 len := Length(s);
618 SetLength( b, len);
619 if len > 0 then begin
620 System.Move( Pointer(s)^, b[0], len );
621 end;
622 WriteBinary( b );
623 end;
624
625 procedure TProtocolImpl.WriteString(const s: string);
626 var
627 b : TBytes;
628 begin
629 b := TEncoding.UTF8.GetBytes(s);
630 WriteBinary( b );
631 end;
632
633
634 procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftList);
635 begin
636 FTrans.CheckReadBytesAvailable( value.Count * GetMinSerializedSize(value.ElementType));
637 end;
638
639
640 procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftSet);
641 begin
642 FTrans.CheckReadBytesAvailable( value.Count * GetMinSerializedSize(value.ElementType));
643 end;
644
645
646 procedure TProtocolImpl.CheckReadBytesAvailable( const value : TThriftMap);
647 var nPairSize : Integer;
648 begin
649 nPairSize := GetMinSerializedSize(value.KeyType) + GetMinSerializedSize(value.ValueType);
650 FTrans.CheckReadBytesAvailable( value.Count * nPairSize);
651 end;
652
653 { TProtocolUtil }
654
655 class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType);
656 var field : TThriftField;
657 map : TThriftMap;
658 set_ : TThriftSet;
659 list : TThriftList;
660 i : Integer;
661 tracker : IProtocolRecursionTracker;
662 begin
663 tracker := prot.NextRecursionLevel;
664 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
710 raise TProtocolExceptionInvalidData.Create('Unexpected type '+IntToStr(Ord(type_)));
711 end;
712 end;
713
714
715 { TBinaryProtocolImpl }
716
717 constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead, strictWrite: Boolean);
718 begin
719 inherited Create( trans);
720 FStrictRead := strictRead;
721 FStrictWrite := strictWrite;
722 end;
723
ReadAllnull724 function TBinaryProtocolImpl.ReadAll( const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer ): Integer;
725 begin
726 Result := FTrans.ReadAll( pBuf, buflen, off, len );
727 end;
728
ReadBinarynull729 function TBinaryProtocolImpl.ReadBinary: TBytes;
730 var
731 size : Integer;
732 buf : TBytes;
733 begin
734 size := ReadI32;
735 FTrans.CheckReadBytesAvailable( size);
736 SetLength( buf, size);
737 FTrans.ReadAll( buf, 0, size);
738 Result := buf;
739 end;
740
ReadBoolnull741 function TBinaryProtocolImpl.ReadBool: Boolean;
742 begin
743 Result := (ReadByte = 1);
744 end;
745
ReadBytenull746 function TBinaryProtocolImpl.ReadByte: ShortInt;
747 begin
748 ReadAll( @result, SizeOf(result), 0, 1);
749 end;
750
ReadDoublenull751 function TBinaryProtocolImpl.ReadDouble: Double;
752 begin
753 Result := ConvertInt64ToDouble( ReadI64 )
754 end;
755
ReadFieldBeginnull756 function TBinaryProtocolImpl.ReadFieldBegin: TThriftField;
757 begin
758 Init( result, '', TType( ReadByte), 0);
759 if ( result.Type_ <> TType.Stop ) then begin
760 result.Id := ReadI16;
761 end;
762 end;
763
764 procedure TBinaryProtocolImpl.ReadFieldEnd;
765 begin
766
767 end;
768
ReadI16null769 function TBinaryProtocolImpl.ReadI16: SmallInt;
770 var i16in : packed array[0..1] of Byte;
771 begin
772 ReadAll( @i16in, Sizeof(i16in), 0, 2);
773 Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF));
774 end;
775
ReadI32null776 function TBinaryProtocolImpl.ReadI32: Integer;
777 var i32in : packed array[0..3] of Byte;
778 begin
779 ReadAll( @i32in, SizeOf(i32in), 0, 4);
780
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
787 end;
788
ReadI64null789 function TBinaryProtocolImpl.ReadI64: Int64;
790 var i64in : packed array[0..7] of Byte;
791 begin
792 ReadAll( @i64in, SizeOf(i64in), 0, 8);
793 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));
802 end;
803
ReadListBeginnull804 function TBinaryProtocolImpl.ReadListBegin: TThriftList;
805 begin
806 result.ElementType := TType(ReadByte);
807 result.Count := ReadI32;
808 CheckReadBytesAvailable(result);
809 end;
810
811 procedure TBinaryProtocolImpl.ReadListEnd;
812 begin
813
814 end;
815
ReadMapBeginnull816 function TBinaryProtocolImpl.ReadMapBegin: TThriftMap;
817 begin
818 result.KeyType := TType(ReadByte);
819 result.ValueType := TType(ReadByte);
820 result.Count := ReadI32;
821 CheckReadBytesAvailable(result);
822 end;
823
824 procedure TBinaryProtocolImpl.ReadMapEnd;
825 begin
826
827 end;
828
ReadMessageBeginnull829 function TBinaryProtocolImpl.ReadMessageBegin: TThriftMessage;
830 var
831 size : Integer;
832 version : Integer;
833 begin
834 Reset;
835 Init( result);
836 size := ReadI32;
837 if (size < 0) then begin
838 version := size and Integer( VERSION_MASK);
839 if ( version <> Integer( VERSION_1)) then begin
840 raise TProtocolExceptionBadVersion.Create('Bad version in ReadMessageBegin: ' + IntToStr(version) );
841 end;
842 result.Type_ := TMessageType( size and $000000ff);
843 result.Name := ReadString;
844 result.SeqID := ReadI32;
845 end
846 else begin
847 if FStrictRead then begin
848 raise TProtocolExceptionBadVersion.Create('Missing version in readMessageBegin, old client?' );
849 end;
850 result.Name := ReadStringBody( size );
851 result.Type_ := TMessageType( ReadByte );
852 result.SeqID := ReadI32;
853 end;
854 end;
855
856 procedure TBinaryProtocolImpl.ReadMessageEnd;
857 begin
858 inherited;
859
860 end;
861
ReadSetBeginnull862 function TBinaryProtocolImpl.ReadSetBegin: TThriftSet;
863 begin
864 result.ElementType := TType(ReadByte);
865 result.Count := ReadI32;
866 CheckReadBytesAvailable(result);
867 end;
868
869 procedure TBinaryProtocolImpl.ReadSetEnd;
870 begin
871
872 end;
873
ReadStringBodynull874 function TBinaryProtocolImpl.ReadStringBody( size: Integer): string;
875 var buf : TBytes;
876 begin
877 FTrans.CheckReadBytesAvailable( size);
878 SetLength( buf, size);
879 FTrans.ReadAll( buf, 0, size );
880 Result := TEncoding.UTF8.GetString( buf);
881 end;
882
ReadStructBeginnull883 function TBinaryProtocolImpl.ReadStructBegin: TThriftStruct;
884 begin
885 Init( Result);
886 end;
887
888 procedure TBinaryProtocolImpl.ReadStructEnd;
889 begin
890 inherited;
891
892 end;
893
894 procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);
895 var iLen : Integer;
896 begin
897 iLen := Length(b);
898 WriteI32( iLen);
899 if iLen > 0 then FTrans.Write(b, 0, iLen);
900 end;
901
902 procedure TBinaryProtocolImpl.WriteBool(b: Boolean);
903 begin
904 if b then begin
905 WriteByte( 1 );
906 end else begin
907 WriteByte( 0 );
908 end;
909 end;
910
911 procedure TBinaryProtocolImpl.WriteByte(b: ShortInt);
912 begin
913 FTrans.Write( @b, 0, 1);
914 end;
915
916 procedure TBinaryProtocolImpl.WriteDouble( const d: Double);
917 begin
918 WriteI64(ConvertDoubleToInt64(d));
919 end;
920
921 procedure TBinaryProtocolImpl.WriteFieldBegin( const field: TThriftField);
922 begin
923 WriteByte(ShortInt(field.Type_));
924 WriteI16(field.ID);
925 end;
926
927 procedure TBinaryProtocolImpl.WriteFieldEnd;
928 begin
929
930 end;
931
932 procedure TBinaryProtocolImpl.WriteFieldStop;
933 begin
934 WriteByte(ShortInt(TType.Stop));
935 end;
936
937 procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt);
938 var i16out : packed array[0..1] of Byte;
939 begin
940 i16out[0] := Byte($FF and (i16 shr 8));
941 i16out[1] := Byte($FF and i16);
942 FTrans.Write( @i16out, 0, 2);
943 end;
944
945 procedure TBinaryProtocolImpl.WriteI32(i32: Integer);
946 var i32out : packed array[0..3] of Byte;
947 begin
948 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);
952 FTrans.Write( @i32out, 0, 4);
953 end;
954
955 procedure TBinaryProtocolImpl.WriteI64( const i64: Int64);
956 var i64out : packed array[0..7] of Byte;
957 begin
958 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);
966 FTrans.Write( @i64out, 0, 8);
967 end;
968
969 procedure TBinaryProtocolImpl.WriteListBegin( const list: TThriftList);
970 begin
971 WriteByte(ShortInt(list.ElementType));
972 WriteI32(list.Count);
973 end;
974
975 procedure TBinaryProtocolImpl.WriteListEnd;
976 begin
977
978 end;
979
980 procedure TBinaryProtocolImpl.WriteMapBegin( const map: TThriftMap);
981 begin
982 WriteByte(ShortInt(map.KeyType));
983 WriteByte(ShortInt(map.ValueType));
984 WriteI32(map.Count);
985 end;
986
987 procedure TBinaryProtocolImpl.WriteMapEnd;
988 begin
989
990 end;
991
992 procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: TThriftMessage);
993 var version : Cardinal;
994 begin
995 Reset;
996 if FStrictWrite then begin
997 version := VERSION_1 or Cardinal( msg.Type_);
998 WriteI32( Integer( version) );
999 WriteString( msg.Name);
1000 WriteI32( msg.SeqID);
1001 end else begin
1002 WriteString( msg.Name);
1003 WriteByte(ShortInt( msg.Type_));
1004 WriteI32( msg.SeqID);
1005 end;
1006 end;
1007
1008 procedure TBinaryProtocolImpl.WriteMessageEnd;
1009 begin
1010
1011 end;
1012
1013 procedure TBinaryProtocolImpl.WriteSetBegin( const set_: TThriftSet);
1014 begin
1015 WriteByte(ShortInt(set_.ElementType));
1016 WriteI32(set_.Count);
1017 end;
1018
1019 procedure TBinaryProtocolImpl.WriteSetEnd;
1020 begin
1021
1022 end;
1023
1024 procedure TBinaryProtocolImpl.WriteStructBegin( const struc: TThriftStruct);
1025 begin
1026
1027 end;
1028
1029 procedure TBinaryProtocolImpl.WriteStructEnd;
1030 begin
1031
1032 end;
1033
GetMinSerializedSizenull1034 function TBinaryProtocolImpl.GetMinSerializedSize( const aType : TType) : Integer;
1035 // Return the minimum number of bytes a type will consume on the wire
1036 begin
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;
1054 end;
1055
1056
1057 { TProtocolException }
1058
1059 constructor TProtocolException.HiddenCreate(const Msg: string);
1060 begin
1061 inherited Create(Msg);
1062 end;
1063
1064 class function TProtocolException.Create(const Msg: string): TProtocolException;
1065 begin
1066 Result := TProtocolExceptionUnknown.Create(Msg);
1067 end;
1068
1069 class function TProtocolException.Create: TProtocolException;
1070 begin
1071 Result := TProtocolExceptionUnknown.Create('');
1072 end;
1073
1074 class function TProtocolException.Create(aType: TExceptionType): TProtocolException;
1075 begin
1076 {$WARN SYMBOL_DEPRECATED OFF}
1077 Result := Create(aType, '');
1078 {$WARN SYMBOL_DEPRECATED DEFAULT}
1079 end;
1080
1081 class function TProtocolException.Create(aType: TExceptionType; const msg: string): TProtocolException;
1082 begin
1083 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);
1090 else
1091 ASSERT( TExceptionType.UNKNOWN = aType);
1092 Result := TProtocolExceptionUnknown.Create(msg);
1093 end;
1094 end;
1095
1096 { TProtocolExceptionSpecialized }
1097
1098 constructor TProtocolExceptionSpecialized.Create(const Msg: string);
1099 begin
1100 inherited HiddenCreate(Msg);
1101 end;
1102
1103 { specialized TProtocolExceptions }
1104
1105 class function TProtocolExceptionUnknown.GetType: TProtocolException.TExceptionType;
1106 begin
1107 result := TExceptionType.UNKNOWN;
1108 end;
1109
1110 class function TProtocolExceptionInvalidData.GetType: TProtocolException.TExceptionType;
1111 begin
1112 result := TExceptionType.INVALID_DATA;
1113 end;
1114
1115 class function TProtocolExceptionNegativeSize.GetType: TProtocolException.TExceptionType;
1116 begin
1117 result := TExceptionType.NEGATIVE_SIZE;
1118 end;
1119
1120 class function TProtocolExceptionSizeLimit.GetType: TProtocolException.TExceptionType;
1121 begin
1122 result := TExceptionType.SIZE_LIMIT;
1123 end;
1124
1125 class function TProtocolExceptionBadVersion.GetType: TProtocolException.TExceptionType;
1126 begin
1127 result := TExceptionType.BAD_VERSION;
1128 end;
1129
1130 class function TProtocolExceptionNotImplemented.GetType: TProtocolException.TExceptionType;
1131 begin
1132 result := TExceptionType.NOT_IMPLEMENTED;
1133 end;
1134
1135 class function TProtocolExceptionDepthLimit.GetType: TProtocolException.TExceptionType;
1136 begin
1137 result := TExceptionType.DEPTH_LIMIT;
1138 end;
1139
1140 { TBinaryProtocolImpl.TFactory }
1141
1142 constructor TBinaryProtocolImpl.TFactory.Create( const aStrictRead, aStrictWrite: Boolean);
1143 begin
1144 inherited Create;
1145 FStrictRead := AStrictRead;
1146 FStrictWrite := AStrictWrite;
1147 end;
1148
TFactorynull1149 function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
1150 begin
1151 Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite);
1152 end;
1153
1154
1155 { TProtocolDecorator }
1156
1157 constructor TProtocolDecorator.Create( const aProtocol : IProtocol);
1158 begin
1159 ASSERT( aProtocol <> nil);
1160 inherited Create( aProtocol.Transport);
1161 FWrappedProtocol := aProtocol;
1162 end;
1163
1164
1165 procedure TProtocolDecorator.WriteMessageBegin( const msg: TThriftMessage);
1166 begin
1167 FWrappedProtocol.WriteMessageBegin( msg);
1168 end;
1169
1170
1171 procedure TProtocolDecorator.WriteMessageEnd;
1172 begin
1173 FWrappedProtocol.WriteMessageEnd;
1174 end;
1175
1176
1177 procedure TProtocolDecorator.WriteStructBegin( const struc: TThriftStruct);
1178 begin
1179 FWrappedProtocol.WriteStructBegin( struc);
1180 end;
1181
1182
1183 procedure TProtocolDecorator.WriteStructEnd;
1184 begin
1185 FWrappedProtocol.WriteStructEnd;
1186 end;
1187
1188
1189 procedure TProtocolDecorator.WriteFieldBegin( const field: TThriftField);
1190 begin
1191 FWrappedProtocol.WriteFieldBegin( field);
1192 end;
1193
1194
1195 procedure TProtocolDecorator.WriteFieldEnd;
1196 begin
1197 FWrappedProtocol.WriteFieldEnd;
1198 end;
1199
1200
1201 procedure TProtocolDecorator.WriteFieldStop;
1202 begin
1203 FWrappedProtocol.WriteFieldStop;
1204 end;
1205
1206
1207 procedure TProtocolDecorator.WriteMapBegin( const map: TThriftMap);
1208 begin
1209 FWrappedProtocol.WriteMapBegin( map);
1210 end;
1211
1212
1213 procedure TProtocolDecorator.WriteMapEnd;
1214 begin
1215 FWrappedProtocol.WriteMapEnd;
1216 end;
1217
1218
1219 procedure TProtocolDecorator.WriteListBegin( const list: TThriftList);
1220 begin
1221 FWrappedProtocol.WriteListBegin( list);
1222 end;
1223
1224
1225 procedure TProtocolDecorator.WriteListEnd();
1226 begin
1227 FWrappedProtocol.WriteListEnd();
1228 end;
1229
1230
1231 procedure TProtocolDecorator.WriteSetBegin( const set_: TThriftSet );
1232 begin
1233 FWrappedProtocol.WriteSetBegin( set_);
1234 end;
1235
1236
1237 procedure TProtocolDecorator.WriteSetEnd();
1238 begin
1239 FWrappedProtocol.WriteSetEnd();
1240 end;
1241
1242
1243 procedure TProtocolDecorator.WriteBool( b: Boolean);
1244 begin
1245 FWrappedProtocol.WriteBool( b);
1246 end;
1247
1248
1249 procedure TProtocolDecorator.WriteByte( b: ShortInt);
1250 begin
1251 FWrappedProtocol.WriteByte( b);
1252 end;
1253
1254
1255 procedure TProtocolDecorator.WriteI16( i16: SmallInt);
1256 begin
1257 FWrappedProtocol.WriteI16( i16);
1258 end;
1259
1260
1261 procedure TProtocolDecorator.WriteI32( i32: Integer);
1262 begin
1263 FWrappedProtocol.WriteI32( i32);
1264 end;
1265
1266
1267 procedure TProtocolDecorator.WriteI64( const i64: Int64);
1268 begin
1269 FWrappedProtocol.WriteI64( i64);
1270 end;
1271
1272
1273 procedure TProtocolDecorator.WriteDouble( const d: Double);
1274 begin
1275 FWrappedProtocol.WriteDouble( d);
1276 end;
1277
1278
1279 procedure TProtocolDecorator.WriteString( const s: string );
1280 begin
1281 FWrappedProtocol.WriteString( s);
1282 end;
1283
1284
1285 procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString);
1286 begin
1287 FWrappedProtocol.WriteAnsiString( s);
1288 end;
1289
1290
1291 procedure TProtocolDecorator.WriteBinary( const b: TBytes);
1292 begin
1293 FWrappedProtocol.WriteBinary( b);
1294 end;
1295
1296
ReadMessageBeginnull1297 function TProtocolDecorator.ReadMessageBegin: TThriftMessage;
1298 begin
1299 result := FWrappedProtocol.ReadMessageBegin;
1300 end;
1301
1302
1303 procedure TProtocolDecorator.ReadMessageEnd();
1304 begin
1305 FWrappedProtocol.ReadMessageEnd();
1306 end;
1307
1308
ReadStructBeginnull1309 function TProtocolDecorator.ReadStructBegin: TThriftStruct;
1310 begin
1311 result := FWrappedProtocol.ReadStructBegin;
1312 end;
1313
1314
1315 procedure TProtocolDecorator.ReadStructEnd;
1316 begin
1317 FWrappedProtocol.ReadStructEnd;
1318 end;
1319
1320
ReadFieldBeginnull1321 function TProtocolDecorator.ReadFieldBegin: TThriftField;
1322 begin
1323 result := FWrappedProtocol.ReadFieldBegin;
1324 end;
1325
1326
1327 procedure TProtocolDecorator.ReadFieldEnd();
1328 begin
1329 FWrappedProtocol.ReadFieldEnd();
1330 end;
1331
1332
ReadMapBeginnull1333 function TProtocolDecorator.ReadMapBegin: TThriftMap;
1334 begin
1335 result := FWrappedProtocol.ReadMapBegin;
1336 end;
1337
1338
1339 procedure TProtocolDecorator.ReadMapEnd();
1340 begin
1341 FWrappedProtocol.ReadMapEnd();
1342 end;
1343
1344
ReadListBeginnull1345 function TProtocolDecorator.ReadListBegin: TThriftList;
1346 begin
1347 result := FWrappedProtocol.ReadListBegin;
1348 end;
1349
1350
1351 procedure TProtocolDecorator.ReadListEnd();
1352 begin
1353 FWrappedProtocol.ReadListEnd();
1354 end;
1355
1356
ReadSetBeginnull1357 function TProtocolDecorator.ReadSetBegin: TThriftSet;
1358 begin
1359 result := FWrappedProtocol.ReadSetBegin;
1360 end;
1361
1362
1363 procedure TProtocolDecorator.ReadSetEnd();
1364 begin
1365 FWrappedProtocol.ReadSetEnd();
1366 end;
1367
1368
ReadBoolnull1369 function TProtocolDecorator.ReadBool: Boolean;
1370 begin
1371 result := FWrappedProtocol.ReadBool;
1372 end;
1373
1374
ReadBytenull1375 function TProtocolDecorator.ReadByte: ShortInt;
1376 begin
1377 result := FWrappedProtocol.ReadByte;
1378 end;
1379
1380
ReadI16null1381 function TProtocolDecorator.ReadI16: SmallInt;
1382 begin
1383 result := FWrappedProtocol.ReadI16;
1384 end;
1385
1386
ReadI32null1387 function TProtocolDecorator.ReadI32: Integer;
1388 begin
1389 result := FWrappedProtocol.ReadI32;
1390 end;
1391
1392
ReadI64null1393 function TProtocolDecorator.ReadI64: Int64;
1394 begin
1395 result := FWrappedProtocol.ReadI64;
1396 end;
1397
1398
ReadDoublenull1399 function TProtocolDecorator.ReadDouble:Double;
1400 begin
1401 result := FWrappedProtocol.ReadDouble;
1402 end;
1403
1404
ReadBinarynull1405 function TProtocolDecorator.ReadBinary: TBytes;
1406 begin
1407 result := FWrappedProtocol.ReadBinary;
1408 end;
1409
1410
ReadStringnull1411 function TProtocolDecorator.ReadString: string;
1412 begin
1413 result := FWrappedProtocol.ReadString;
1414 end;
1415
1416
ReadAnsiStringnull1417 function TProtocolDecorator.ReadAnsiString: AnsiString;
1418 begin
1419 result := FWrappedProtocol.ReadAnsiString;
1420 end;
1421
1422
GetMinSerializedSizenull1423 function TProtocolDecorator.GetMinSerializedSize( const aType : TType) : Integer;
1424 begin
1425 result := FWrappedProtocol.GetMinSerializedSize(aType);
1426 end;
1427
1428
1429 { Init helper functions }
1430
1431 procedure Init( var rec : TThriftMessage; const AName: string; const AMessageType: TMessageType; const ASeqID: Integer);
1432 begin
1433 rec.Name := AName;
1434 rec.Type_ := AMessageType;
1435 rec.SeqID := ASeqID;
1436 end;
1437
1438
1439 procedure Init( var rec : TThriftStruct; const AName: string = '');
1440 begin
1441 rec.Name := AName;
1442 end;
1443
1444
1445 procedure Init( var rec : TThriftField; const AName: string; const AType: TType; const AID: SmallInt);
1446 begin
1447 rec.Name := AName;
1448 rec.Type_ := AType;
1449 rec.Id := AId;
1450 end;
1451
1452
1453 procedure Init( var rec : TThriftMap; const AKeyType, AValueType: TType; const ACount: Integer);
1454 begin
1455 rec.ValueType := AValueType;
1456 rec.KeyType := AKeyType;
1457 rec.Count := ACount;
1458 end;
1459
1460
1461 procedure Init( var rec : TThriftSet; const AElementType: TType; const ACount: Integer);
1462 begin
1463 rec.Count := ACount;
1464 rec.ElementType := AElementType;
1465 end;
1466
1467
1468 procedure Init( var rec : TThriftList; const AElementType: TType; const ACount: Integer);
1469 begin
1470 rec.Count := ACount;
1471 rec.ElementType := AElementType;
1472 end;
1473
1474
1475
1476 end.
1477
1478