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