blob: e88f1cfa98b3d36e217ffd7dc3a7692afebcf188 [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
Jake Farrell7ae13e12011-10-18 14:35:26 +0000500implementation
501
Roger Meier333bbf32012-01-08 21:51:08 +0000502function ConvertInt64ToDouble( const n: Int64): Double;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000503begin
504 ASSERT( SizeOf(n) = SizeOf(Result));
505 System.Move( n, Result, SizeOf(Result));
506end;
507
Roger Meier333bbf32012-01-08 21:51:08 +0000508function ConvertDoubleToInt64( const d: Double): Int64;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000509begin
510 ASSERT( SizeOf(d) = SizeOf(Result));
511 System.Move( d, Result, SizeOf(Result));
512end;
513
514{ TFieldImpl }
515
516constructor TFieldImpl.Create(const AName: string; const AType: TType;
517 AId: SmallInt);
518begin
Jens Geyer718f6ee2013-09-06 21:02:34 +0200519 inherited Create;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000520 FName := AName;
521 FType := AType;
522 FId := AId;
523end;
524
525constructor TFieldImpl.Create;
526begin
Jens Geyer718f6ee2013-09-06 21:02:34 +0200527 inherited Create;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000528 FName := '';
529 FType := Low(TType);
530 FId := 0;
531end;
532
533function TFieldImpl.GetId: SmallInt;
534begin
535 Result := FId;
536end;
537
538function TFieldImpl.GetName: string;
539begin
540 Result := FName;
541end;
542
543function TFieldImpl.GetType: TType;
544begin
545 Result := FType;
546end;
547
548procedure TFieldImpl.SetId(Value: SmallInt);
549begin
550 FId := Value;
551end;
552
553procedure TFieldImpl.SetName(const Value: string);
554begin
555 FName := Value;
556end;
557
558procedure TFieldImpl.SetType(Value: TType);
559begin
560 FType := Value;
561end;
562
563{ TProtocolImpl }
564
565constructor TProtocolImpl.Create(trans: ITransport);
566begin
567 inherited Create;
568 FTrans := trans;
569end;
570
571function TProtocolImpl.GetTransport: ITransport;
572begin
573 Result := FTrans;
574end;
575
576function TProtocolImpl.ReadAnsiString: AnsiString;
577var
578 b : TBytes;
579 len : Integer;
580begin
581 Result := '';
582 b := ReadBinary;
583 len := Length( b );
584 if len > 0 then
585 begin
586 SetLength( Result, len);
587 System.Move( b[0], Pointer(Result)^, len );
588 end;
589end;
590
591function TProtocolImpl.ReadString: string;
592begin
593 Result := TEncoding.UTF8.GetString( ReadBinary );
594end;
595
596procedure TProtocolImpl.WriteAnsiString(const s: AnsiString);
597var
598 b : TBytes;
599 len : Integer;
600begin
601 len := Length(s);
602 SetLength( b, len);
603 if len > 0 then
604 begin
605 System.Move( Pointer(s)^, b[0], len );
606 end;
607 WriteBinary( b );
608end;
609
610procedure TProtocolImpl.WriteString(const s: string);
611var
612 b : TBytes;
613begin
614 b := TEncoding.UTF8.GetBytes(s);
615 WriteBinary( b );
616end;
617
618{ TProtocolUtil }
619
620class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType);
Jake Farrell6cd63ec2012-08-29 02:04:35 +0000621var field : IField;
622 map : IMap;
623 set_ : ISet;
624 list : IList;
625 i : Integer;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000626begin
Jake Farrell6cd63ec2012-08-29 02:04:35 +0000627 case type_ of
628 // simple types
629 TType.Bool_ : prot.ReadBool();
630 TType.Byte_ : prot.ReadByte();
631 TType.I16 : prot.ReadI16();
632 TType.I32 : prot.ReadI32();
633 TType.I64 : prot.ReadI64();
634 TType.Double_ : prot.ReadDouble();
635 TType.String_ : prot.ReadBinary();// Don't try to decode the string, just skip it.
Jake Farrell7ae13e12011-10-18 14:35:26 +0000636
Jake Farrell6cd63ec2012-08-29 02:04:35 +0000637 // structured types
638 TType.Struct : begin
639 prot.ReadStructBegin();
640 while TRUE do begin
641 field := prot.ReadFieldBegin();
642 if (field.Type_ = TType.Stop) then Break;
643 Skip(prot, field.Type_);
644 prot.ReadFieldEnd();
645 end;
646 prot.ReadStructEnd();
647 end;
648
649 TType.Map : begin
650 map := prot.ReadMapBegin();
651 for i := 0 to map.Count-1 do begin
652 Skip(prot, map.KeyType);
653 Skip(prot, map.ValueType);
654 end;
655 prot.ReadMapEnd();
656 end;
657
658 TType.Set_ : begin
659 set_ := prot.ReadSetBegin();
660 for i := 0 to set_.Count-1
661 do Skip( prot, set_.ElementType);
662 prot.ReadSetEnd();
663 end;
664
665 TType.List : begin
666 list := prot.ReadListBegin();
667 for i := 0 to list.Count-1
668 do Skip( prot, list.ElementType);
669 prot.ReadListEnd();
670 end;
671
672 else
673 ASSERT( FALSE); // any new types?
674 end;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000675end;
676
677{ TStructImpl }
678
679constructor TStructImpl.Create(const AName: string);
680begin
681 inherited Create;
682 FName := AName;
683end;
684
685function TStructImpl.GetName: string;
686begin
687 Result := FName;
688end;
689
690procedure TStructImpl.SetName(const Value: string);
691begin
692 FName := Value;
693end;
694
695{ TMapImpl }
696
697constructor TMapImpl.Create(AValueType, AKeyType: TType; ACount: Integer);
698begin
699 inherited Create;
700 FValueType := AValueType;
701 FKeyType := AKeyType;
702 FCount := ACount;
703end;
704
705constructor TMapImpl.Create;
706begin
Jens Geyer718f6ee2013-09-06 21:02:34 +0200707 inherited Create;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000708end;
709
710function TMapImpl.GetCount: Integer;
711begin
712 Result := FCount;
713end;
714
715function TMapImpl.GetKeyType: TType;
716begin
717 Result := FKeyType;
718end;
719
720function TMapImpl.GetValueType: TType;
721begin
722 Result := FValueType;
723end;
724
725procedure TMapImpl.SetCount(Value: Integer);
726begin
727 FCount := Value;
728end;
729
730procedure TMapImpl.SetKeyType(Value: TType);
731begin
732 FKeyType := Value;
733end;
734
735procedure TMapImpl.SetValueType(Value: TType);
736begin
737 FValueType := Value;
738end;
739
740{ IMessage }
741
742constructor TMessageImpl.Create(AName: string; AMessageType: TMessageType;
743 ASeqID: Integer);
744begin
745 inherited Create;
746 FName := AName;
747 FMessageType := AMessageType;
748 FSeqID := ASeqID;
749end;
750
751constructor TMessageImpl.Create;
752begin
753 inherited;
754end;
755
756function TMessageImpl.GetName: string;
757begin
758 Result := FName;
759end;
760
761function TMessageImpl.GetSeqID: Integer;
762begin
763 Result := FSeqID;
764end;
765
766function TMessageImpl.GetType: TMessageType;
767begin
768 Result := FMessageType;
769end;
770
771procedure TMessageImpl.SetName(const Value: string);
772begin
773 FName := Value;
774end;
775
776procedure TMessageImpl.SetSeqID(Value: Integer);
777begin
778 FSeqID := Value;
779end;
780
781procedure TMessageImpl.SetType(Value: TMessageType);
782begin
783 FMessageType := Value;
784end;
785
786{ ISet }
787
788constructor TSetImpl.Create( AElementType: TType; ACount: Integer);
789begin
790 inherited Create;
791 FCount := ACount;
792 FElementType := AElementType;
793end;
794
795constructor TSetImpl.Create;
796begin
Jens Geyer718f6ee2013-09-06 21:02:34 +0200797 inherited Create;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000798end;
799
800function TSetImpl.GetCount: Integer;
801begin
802 Result := FCount;
803end;
804
805function TSetImpl.GetElementType: TType;
806begin
807 Result := FElementType;
808end;
809
810procedure TSetImpl.SetCount(Value: Integer);
811begin
812 FCount := Value;
813end;
814
815procedure TSetImpl.SetElementType(Value: TType);
816begin
817 FElementType := Value;
818end;
819
820{ IList }
821
822constructor TListImpl.Create( AElementType: TType; ACount: Integer);
823begin
824 inherited Create;
825 FCount := ACount;
826 FElementType := AElementType;
827end;
828
829constructor TListImpl.Create;
830begin
Jens Geyer718f6ee2013-09-06 21:02:34 +0200831 inherited Create;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000832end;
833
834function TListImpl.GetCount: Integer;
835begin
836 Result := FCount;
837end;
838
839function TListImpl.GetElementType: TType;
840begin
841 Result := FElementType;
842end;
843
844procedure TListImpl.SetCount(Value: Integer);
845begin
846 FCount := Value;
847end;
848
849procedure TListImpl.SetElementType(Value: TType);
850begin
851 FElementType := Value;
852end;
853
854{ TBinaryProtocolImpl }
855
Roger Meier333bbf32012-01-08 21:51:08 +0000856constructor TBinaryProtocolImpl.Create( const trans: ITransport);
Jake Farrell7ae13e12011-10-18 14:35:26 +0000857begin
Jens Geyer718f6ee2013-09-06 21:02:34 +0200858 //no inherited
Jake Farrell7ae13e12011-10-18 14:35:26 +0000859 Create( trans, False, True);
860end;
861
Roger Meier333bbf32012-01-08 21:51:08 +0000862constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead,
Jake Farrell7ae13e12011-10-18 14:35:26 +0000863 strictWrite: Boolean);
864begin
865 inherited Create( trans );
866 FStrictRead := strictRead;
867 FStrictWrite := strictWrite;
868end;
869
870function TBinaryProtocolImpl.ReadAll( var buf: TBytes; off,
871 len: Integer): Integer;
872begin
Jake Farrell7ae13e12011-10-18 14:35:26 +0000873 Result := FTrans.ReadAll( buf, off, len );
874end;
875
876function TBinaryProtocolImpl.ReadBinary: TBytes;
877var
878 size : Integer;
879 buf : TBytes;
880begin
881 size := ReadI32;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000882 SetLength( buf, size );
883 FTrans.ReadAll( buf, 0, size);
884 Result := buf;
885end;
886
887function TBinaryProtocolImpl.ReadBool: Boolean;
888begin
889 Result := ReadByte = 1;
890end;
891
892function TBinaryProtocolImpl.ReadByte: ShortInt;
893var
894 bin : TBytes;
895begin
896 SetLength( bin, 1);
897 ReadAll( bin, 0, 1 );
898 Result := ShortInt( bin[0]);
899end;
900
901function TBinaryProtocolImpl.ReadDouble: Double;
902begin
903 Result := ConvertInt64ToDouble( ReadI64 )
904end;
905
906function TBinaryProtocolImpl.ReadFieldBegin: IField;
907var
908 field : IField;
909begin
910 field := TFieldImpl.Create;
911 field.Type_ := TType( ReadByte);
912 if ( field.Type_ <> TType.Stop ) then
913 begin
914 field.Id := ReadI16;
915 end;
916 Result := field;
917end;
918
919procedure TBinaryProtocolImpl.ReadFieldEnd;
920begin
921
922end;
923
924function TBinaryProtocolImpl.ReadI16: SmallInt;
925var
926 i16in : TBytes;
927begin
928 SetLength( i16in, 2 );
929 ReadAll( i16in, 0, 2);
930 Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF));
931end;
932
933function TBinaryProtocolImpl.ReadI32: Integer;
934var
935 i32in : TBytes;
936begin
937 SetLength( i32in, 4 );
938 ReadAll( i32in, 0, 4);
939
940 Result := Integer(
941 ((i32in[0] and $FF) shl 24) or
942 ((i32in[1] and $FF) shl 16) or
943 ((i32in[2] and $FF) shl 8) or
944 (i32in[3] and $FF));
945
946end;
947
948function TBinaryProtocolImpl.ReadI64: Int64;
949var
950 i64in : TBytes;
951begin
952 SetLength( i64in, 8);
953 ReadAll( i64in, 0, 8);
954 Result :=
955 (Int64( i64in[0] and $FF) shl 56) or
956 (Int64( i64in[1] and $FF) shl 48) or
957 (Int64( i64in[2] and $FF) shl 40) or
958 (Int64( i64in[3] and $FF) shl 32) or
959 (Int64( i64in[4] and $FF) shl 24) or
960 (Int64( i64in[5] and $FF) shl 16) or
961 (Int64( i64in[6] and $FF) shl 8) or
962 (Int64( i64in[7] and $FF));
963end;
964
965function TBinaryProtocolImpl.ReadListBegin: IList;
966var
967 list : IList;
968begin
969 list := TListImpl.Create;
970 list.ElementType := TType( ReadByte );
971 list.Count := ReadI32;
972 Result := list;
973end;
974
975procedure TBinaryProtocolImpl.ReadListEnd;
976begin
977
978end;
979
980function TBinaryProtocolImpl.ReadMapBegin: IMap;
981var
982 map : IMap;
983begin
984 map := TMapImpl.Create;
985 map.KeyType := TType( ReadByte );
986 map.ValueType := TType( ReadByte );
987 map.Count := ReadI32;
988 Result := map;
989end;
990
991procedure TBinaryProtocolImpl.ReadMapEnd;
992begin
993
994end;
995
996function TBinaryProtocolImpl.ReadMessageBegin: IMessage;
997var
998 size : Integer;
999 version : Integer;
1000 message : IMessage;
1001begin
1002 message := TMessageImpl.Create;
1003 size := ReadI32;
1004 if (size < 0) then
1005 begin
1006 version := size and Integer( VERSION_MASK);
1007 if ( version <> Integer( VERSION_1)) then
1008 begin
1009 raise TProtocolException.Create(TProtocolException.BAD_VERSION, 'Bad version in ReadMessageBegin: ' + IntToStr(version) );
1010 end;
1011 message.Type_ := TMessageType( size and $000000ff);
1012 message.Name := ReadString;
1013 message.SeqID := ReadI32;
1014 end else
1015 begin
1016 if FStrictRead then
1017 begin
1018 raise TProtocolException.Create( TProtocolException.BAD_VERSION, 'Missing version in readMessageBegin, old client?' );
1019 end;
1020 message.Name := ReadStringBody( size );
1021 message.Type_ := TMessageType( ReadByte );
1022 message.SeqID := ReadI32;
1023 end;
1024 Result := message;
1025end;
1026
1027procedure TBinaryProtocolImpl.ReadMessageEnd;
1028begin
1029 inherited;
1030
1031end;
1032
1033function TBinaryProtocolImpl.ReadSetBegin: ISet;
1034var
1035 set_ : ISet;
1036begin
1037 set_ := TSetImpl.Create;
1038 set_.ElementType := TType( ReadByte );
1039 set_.Count := ReadI32;
1040 Result := set_;
1041end;
1042
1043procedure TBinaryProtocolImpl.ReadSetEnd;
1044begin
1045
1046end;
1047
1048function TBinaryProtocolImpl.ReadStringBody( size: Integer): string;
1049var
1050 buf : TBytes;
1051begin
Jake Farrell7ae13e12011-10-18 14:35:26 +00001052 SetLength( buf, size );
1053 FTrans.ReadAll( buf, 0, size );
1054 Result := TEncoding.UTF8.GetString( buf);
1055end;
1056
1057function TBinaryProtocolImpl.ReadStructBegin: IStruct;
1058begin
1059 Result := TStructImpl.Create('');
1060end;
1061
1062procedure TBinaryProtocolImpl.ReadStructEnd;
1063begin
1064 inherited;
1065
1066end;
1067
Jake Farrell7ae13e12011-10-18 14:35:26 +00001068procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);
Jake Farrell9c6773a2012-03-22 02:40:45 +00001069var iLen : Integer;
Jake Farrell7ae13e12011-10-18 14:35:26 +00001070begin
Jake Farrell9c6773a2012-03-22 02:40:45 +00001071 iLen := Length(b);
1072 WriteI32( iLen);
1073 if iLen > 0 then FTrans.Write(b, 0, iLen);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001074end;
1075
1076procedure TBinaryProtocolImpl.WriteBool(b: Boolean);
1077begin
1078 if b then
1079 begin
1080 WriteByte( 1 );
1081 end else
1082 begin
1083 WriteByte( 0 );
1084 end;
1085end;
1086
1087procedure TBinaryProtocolImpl.WriteByte(b: ShortInt);
1088var
1089 a : TBytes;
1090begin
1091 SetLength( a, 1);
1092 a[0] := Byte( b );
1093 FTrans.Write( a, 0, 1 );
1094end;
1095
Roger Meier333bbf32012-01-08 21:51:08 +00001096procedure TBinaryProtocolImpl.WriteDouble( const d: Double);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001097begin
1098 WriteI64(ConvertDoubleToInt64(d));
1099end;
1100
Roger Meier333bbf32012-01-08 21:51:08 +00001101procedure TBinaryProtocolImpl.WriteFieldBegin( const field: IField);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001102begin
1103 WriteByte(ShortInt(field.Type_));
1104 WriteI16(field.ID);
1105end;
1106
1107procedure TBinaryProtocolImpl.WriteFieldEnd;
1108begin
1109
1110end;
1111
1112procedure TBinaryProtocolImpl.WriteFieldStop;
1113begin
1114 WriteByte(ShortInt(TType.Stop));
1115end;
1116
1117procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt);
1118var
1119 i16out : TBytes;
1120begin
1121 SetLength( i16out, 2);
1122 i16out[0] := Byte($FF and (i16 shr 8));
1123 i16out[1] := Byte($FF and i16);
1124 FTrans.Write( i16out );
1125end;
1126
1127procedure TBinaryProtocolImpl.WriteI32(i32: Integer);
1128var
1129 i32out : TBytes;
1130begin
1131 SetLength( i32out, 4);
1132 i32out[0] := Byte($FF and (i32 shr 24));
1133 i32out[1] := Byte($FF and (i32 shr 16));
1134 i32out[2] := Byte($FF and (i32 shr 8));
1135 i32out[3] := Byte($FF and i32);
1136 FTrans.Write( i32out, 0, 4);
1137end;
1138
Roger Meier333bbf32012-01-08 21:51:08 +00001139procedure TBinaryProtocolImpl.WriteI64( const i64: Int64);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001140var
1141 i64out : TBytes;
1142begin
1143 SetLength( i64out, 8);
1144 i64out[0] := Byte($FF and (i64 shr 56));
1145 i64out[1] := Byte($FF and (i64 shr 48));
1146 i64out[2] := Byte($FF and (i64 shr 40));
1147 i64out[3] := Byte($FF and (i64 shr 32));
1148 i64out[4] := Byte($FF and (i64 shr 24));
1149 i64out[5] := Byte($FF and (i64 shr 16));
1150 i64out[6] := Byte($FF and (i64 shr 8));
1151 i64out[7] := Byte($FF and i64);
1152 FTrans.Write( i64out, 0, 8);
1153end;
1154
Roger Meier333bbf32012-01-08 21:51:08 +00001155procedure TBinaryProtocolImpl.WriteListBegin( const list: IList);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001156begin
1157 WriteByte(ShortInt(list.ElementType));
1158 WriteI32(list.Count);
1159end;
1160
1161procedure TBinaryProtocolImpl.WriteListEnd;
1162begin
1163
1164end;
1165
Roger Meier333bbf32012-01-08 21:51:08 +00001166procedure TBinaryProtocolImpl.WriteMapBegin( const map: IMap);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001167begin
1168 WriteByte(ShortInt(map.KeyType));
1169 WriteByte(ShortInt(map.ValueType));
1170 WriteI32(map.Count);
1171end;
1172
1173procedure TBinaryProtocolImpl.WriteMapEnd;
1174begin
1175
1176end;
1177
Roger Meier333bbf32012-01-08 21:51:08 +00001178procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: IMessage);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001179var
1180 version : Cardinal;
1181begin
1182 if FStrictWrite then
1183 begin
Roger Meier333bbf32012-01-08 21:51:08 +00001184 version := VERSION_1 or Cardinal( msg.Type_);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001185 WriteI32( Integer( version) );
Roger Meier333bbf32012-01-08 21:51:08 +00001186 WriteString( msg.Name);
Jake Farrell6cd63ec2012-08-29 02:04:35 +00001187 WriteI32( msg.SeqID);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001188 end else
1189 begin
Roger Meier333bbf32012-01-08 21:51:08 +00001190 WriteString( msg.Name);
1191 WriteByte(ShortInt( msg.Type_));
1192 WriteI32( msg.SeqID);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001193 end;
1194end;
1195
1196procedure TBinaryProtocolImpl.WriteMessageEnd;
1197begin
1198
1199end;
1200
Roger Meier333bbf32012-01-08 21:51:08 +00001201procedure TBinaryProtocolImpl.WriteSetBegin( const set_: ISet);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001202begin
1203 WriteByte(ShortInt(set_.ElementType));
1204 WriteI32(set_.Count);
1205end;
1206
1207procedure TBinaryProtocolImpl.WriteSetEnd;
1208begin
1209
1210end;
1211
Roger Meier333bbf32012-01-08 21:51:08 +00001212procedure TBinaryProtocolImpl.WriteStructBegin( const struc: IStruct);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001213begin
1214
1215end;
1216
1217procedure TBinaryProtocolImpl.WriteStructEnd;
1218begin
1219
1220end;
1221
1222{ TProtocolException }
1223
1224constructor TProtocolException.Create;
1225begin
1226 inherited Create('');
1227 FType := UNKNOWN;
1228end;
1229
1230constructor TProtocolException.Create(type_: Integer);
1231begin
1232 inherited Create('');
1233 FType := type_;
1234end;
1235
1236constructor TProtocolException.Create(type_: Integer; const msg: string);
1237begin
1238 inherited Create( msg );
1239 FType := type_;
1240end;
1241
1242{ TThriftStringBuilder }
1243
1244function TThriftStringBuilder.Append(const Value: TBytes): TStringBuilder;
1245begin
1246 Result := Append( string( RawByteString(Value)) );
1247end;
1248
1249function TThriftStringBuilder.Append(
1250 const Value: IThriftContainer): TStringBuilder;
1251begin
1252 Result := Append( Value.ToString );
1253end;
1254
1255{ TBinaryProtocolImpl.TFactory }
1256
1257constructor TBinaryProtocolImpl.TFactory.Create(AStrictRead, AStrictWrite: Boolean);
1258begin
Jens Geyer718f6ee2013-09-06 21:02:34 +02001259 inherited Create;
Jake Farrell7ae13e12011-10-18 14:35:26 +00001260 FStrictRead := AStrictRead;
1261 FStrictWrite := AStrictWrite;
1262end;
1263
1264constructor TBinaryProtocolImpl.TFactory.Create;
1265begin
Jens Geyer718f6ee2013-09-06 21:02:34 +02001266 //no inherited;
Jake Farrell7ae13e12011-10-18 14:35:26 +00001267 Create( False, True )
1268end;
1269
Roger Meier333bbf32012-01-08 21:51:08 +00001270function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
Jake Farrell7ae13e12011-10-18 14:35:26 +00001271begin
Jens Geyer5cb0d222013-03-07 20:44:22 +01001272 Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001273end;
1274
Jens Geyer8a701962013-03-25 01:28:12 +02001275
1276{ TProtocolDecorator }
1277
1278constructor TProtocolDecorator.Create( const aProtocol : IProtocol);
1279begin
1280 ASSERT( aProtocol <> nil);
1281 inherited Create( aProtocol.Transport);
1282 FWrappedProtocol := aProtocol;
1283end;
1284
1285
1286procedure TProtocolDecorator.WriteMessageBegin( const msg: IMessage);
1287begin
1288 FWrappedProtocol.WriteMessageBegin( msg);
1289end;
1290
1291
1292procedure TProtocolDecorator.WriteMessageEnd;
1293begin
1294 FWrappedProtocol.WriteMessageEnd;
1295end;
1296
1297
1298procedure TProtocolDecorator.WriteStructBegin( const struc: IStruct);
1299begin
1300 FWrappedProtocol.WriteStructBegin( struc);
1301end;
1302
1303
1304procedure TProtocolDecorator.WriteStructEnd;
1305begin
1306 FWrappedProtocol.WriteStructEnd;
1307end;
1308
1309
1310procedure TProtocolDecorator.WriteFieldBegin( const field: IField);
1311begin
1312 FWrappedProtocol.WriteFieldBegin( field);
1313end;
1314
1315
1316procedure TProtocolDecorator.WriteFieldEnd;
1317begin
1318 FWrappedProtocol.WriteFieldEnd;
1319end;
1320
1321
1322procedure TProtocolDecorator.WriteFieldStop;
1323begin
1324 FWrappedProtocol.WriteFieldStop;
1325end;
1326
1327
1328procedure TProtocolDecorator.WriteMapBegin( const map: IMap);
1329begin
1330 FWrappedProtocol.WriteMapBegin( map);
1331end;
1332
1333
1334procedure TProtocolDecorator.WriteMapEnd;
1335begin
1336 FWrappedProtocol.WriteMapEnd;
1337end;
1338
1339
1340procedure TProtocolDecorator.WriteListBegin( const list: IList);
1341begin
1342 FWrappedProtocol.WriteListBegin( list);
1343end;
1344
1345
1346procedure TProtocolDecorator.WriteListEnd();
1347begin
1348 FWrappedProtocol.WriteListEnd();
1349end;
1350
1351
1352procedure TProtocolDecorator.WriteSetBegin( const set_: ISet );
1353begin
1354 FWrappedProtocol.WriteSetBegin( set_);
1355end;
1356
1357
1358procedure TProtocolDecorator.WriteSetEnd();
1359begin
1360 FWrappedProtocol.WriteSetEnd();
1361end;
1362
1363
1364procedure TProtocolDecorator.WriteBool( b: Boolean);
1365begin
1366 FWrappedProtocol.WriteBool( b);
1367end;
1368
1369
1370procedure TProtocolDecorator.WriteByte( b: ShortInt);
1371begin
1372 FWrappedProtocol.WriteByte( b);
1373end;
1374
1375
1376procedure TProtocolDecorator.WriteI16( i16: SmallInt);
1377begin
1378 FWrappedProtocol.WriteI16( i16);
1379end;
1380
1381
1382procedure TProtocolDecorator.WriteI32( i32: Integer);
1383begin
1384 FWrappedProtocol.WriteI32( i32);
1385end;
1386
1387
1388procedure TProtocolDecorator.WriteI64( const i64: Int64);
1389begin
1390 FWrappedProtocol.WriteI64( i64);
1391end;
1392
1393
1394procedure TProtocolDecorator.WriteDouble( const d: Double);
1395begin
1396 FWrappedProtocol.WriteDouble( d);
1397end;
1398
1399
1400procedure TProtocolDecorator.WriteString( const s: string );
1401begin
1402 FWrappedProtocol.WriteString( s);
1403end;
1404
1405
1406procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString);
1407begin
1408 FWrappedProtocol.WriteAnsiString( s);
1409end;
1410
1411
1412procedure TProtocolDecorator.WriteBinary( const b: TBytes);
1413begin
1414 FWrappedProtocol.WriteBinary( b);
1415end;
1416
1417
1418function TProtocolDecorator.ReadMessageBegin: IMessage;
1419begin
1420 result := FWrappedProtocol.ReadMessageBegin;
1421end;
1422
1423
1424procedure TProtocolDecorator.ReadMessageEnd();
1425begin
1426 FWrappedProtocol.ReadMessageEnd();
1427end;
1428
1429
1430function TProtocolDecorator.ReadStructBegin: IStruct;
1431begin
1432 result := FWrappedProtocol.ReadStructBegin;
1433end;
1434
1435
1436procedure TProtocolDecorator.ReadStructEnd;
1437begin
1438 FWrappedProtocol.ReadStructEnd;
1439end;
1440
1441
1442function TProtocolDecorator.ReadFieldBegin: IField;
1443begin
1444 result := FWrappedProtocol.ReadFieldBegin;
1445end;
1446
1447
1448procedure TProtocolDecorator.ReadFieldEnd();
1449begin
1450 FWrappedProtocol.ReadFieldEnd();
1451end;
1452
1453
1454function TProtocolDecorator.ReadMapBegin: IMap;
1455begin
1456 result := FWrappedProtocol.ReadMapBegin;
1457end;
1458
1459
1460procedure TProtocolDecorator.ReadMapEnd();
1461begin
1462 FWrappedProtocol.ReadMapEnd();
1463end;
1464
1465
1466function TProtocolDecorator.ReadListBegin: IList;
1467begin
1468 result := FWrappedProtocol.ReadListBegin;
1469end;
1470
1471
1472procedure TProtocolDecorator.ReadListEnd();
1473begin
1474 FWrappedProtocol.ReadListEnd();
1475end;
1476
1477
1478function TProtocolDecorator.ReadSetBegin: ISet;
1479begin
1480 result := FWrappedProtocol.ReadSetBegin;
1481end;
1482
1483
1484procedure TProtocolDecorator.ReadSetEnd();
1485begin
1486 FWrappedProtocol.ReadSetEnd();
1487end;
1488
1489
1490function TProtocolDecorator.ReadBool: Boolean;
1491begin
1492 result := FWrappedProtocol.ReadBool;
1493end;
1494
1495
1496function TProtocolDecorator.ReadByte: ShortInt;
1497begin
1498 result := FWrappedProtocol.ReadByte;
1499end;
1500
1501
1502function TProtocolDecorator.ReadI16: SmallInt;
1503begin
1504 result := FWrappedProtocol.ReadI16;
1505end;
1506
1507
1508function TProtocolDecorator.ReadI32: Integer;
1509begin
1510 result := FWrappedProtocol.ReadI32;
1511end;
1512
1513
1514function TProtocolDecorator.ReadI64: Int64;
1515begin
1516 result := FWrappedProtocol.ReadI64;
1517end;
1518
1519
1520function TProtocolDecorator.ReadDouble:Double;
1521begin
1522 result := FWrappedProtocol.ReadDouble;
1523end;
1524
1525
1526function TProtocolDecorator.ReadBinary: TBytes;
1527begin
1528 result := FWrappedProtocol.ReadBinary;
1529end;
1530
1531
1532function TProtocolDecorator.ReadString: string;
1533begin
1534 result := FWrappedProtocol.ReadString;
1535end;
1536
1537
1538function TProtocolDecorator.ReadAnsiString: AnsiString;
1539begin
1540 result := FWrappedProtocol.ReadAnsiString;
1541end;
1542
1543
1544
Jake Farrell7ae13e12011-10-18 14:35:26 +00001545end.
1546