blob: b08458aa33ffd7f9779644c7fa3a2367ec91d1b9 [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;
373 FReadLength : Integer;
374 FCheckReadLength : Boolean;
375
376 private
377 function ReadAll( var buf: TBytes; off: Integer; len: Integer ): Integer;
378 function ReadStringBody( size: Integer): string;
379 procedure CheckReadLength( len: Integer );
380 public
381
382 type
383 TFactory = class( TInterfacedObject, IProtocolFactory)
384 protected
385 FStrictRead : Boolean;
386 FStrictWrite : Boolean;
387 public
Roger Meier333bbf32012-01-08 21:51:08 +0000388 function GetProtocol( const trans: ITransport): IProtocol;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000389 constructor Create( AStrictRead, AStrictWrite: Boolean ); overload;
390 constructor Create; overload;
391 end;
392
Roger Meier333bbf32012-01-08 21:51:08 +0000393 constructor Create( const trans: ITransport); overload;
394 constructor Create( const trans: ITransport; strictRead: Boolean; strictWrite: Boolean); overload;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000395
Roger Meier333bbf32012-01-08 21:51:08 +0000396 procedure WriteMessageBegin( const msg: IMessage); override;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000397 procedure WriteMessageEnd; override;
Roger Meier333bbf32012-01-08 21:51:08 +0000398 procedure WriteStructBegin( const struc: IStruct); override;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000399 procedure WriteStructEnd; override;
Roger Meier333bbf32012-01-08 21:51:08 +0000400 procedure WriteFieldBegin( const field: IField); override;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000401 procedure WriteFieldEnd; override;
402 procedure WriteFieldStop; override;
Roger Meier333bbf32012-01-08 21:51:08 +0000403 procedure WriteMapBegin( const map: IMap); override;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000404 procedure WriteMapEnd; override;
Roger Meier333bbf32012-01-08 21:51:08 +0000405 procedure WriteListBegin( const list: IList); override;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000406 procedure WriteListEnd(); override;
Roger Meier333bbf32012-01-08 21:51:08 +0000407 procedure WriteSetBegin( const set_: ISet ); override;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000408 procedure WriteSetEnd(); override;
409 procedure WriteBool( b: Boolean); override;
410 procedure WriteByte( b: ShortInt); override;
411 procedure WriteI16( i16: SmallInt); override;
412 procedure WriteI32( i32: Integer); override;
Roger Meier333bbf32012-01-08 21:51:08 +0000413 procedure WriteI64( const i64: Int64); override;
414 procedure WriteDouble( const d: Double); override;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000415 procedure WriteBinary( const b: TBytes); override;
416
417 function ReadMessageBegin: IMessage; override;
418 procedure ReadMessageEnd(); override;
419 function ReadStructBegin: IStruct; override;
420 procedure ReadStructEnd; override;
421 function ReadFieldBegin: IField; override;
422 procedure ReadFieldEnd(); override;
423 function ReadMapBegin: IMap; override;
424 procedure ReadMapEnd(); override;
425 function ReadListBegin: IList; override;
426 procedure ReadListEnd(); override;
427 function ReadSetBegin: ISet; override;
428 procedure ReadSetEnd(); override;
429 function ReadBool: Boolean; override;
430 function ReadByte: ShortInt; override;
431 function ReadI16: SmallInt; override;
432 function ReadI32: Integer; override;
433 function ReadI64: Int64; override;
434 function ReadDouble:Double; override;
435 function ReadBinary: TBytes; override;
436
437 procedure SetReadLength( readLength: Integer );
438 end;
439
Jens Geyer8a701962013-03-25 01:28:12 +0200440
441 { TProtocolDecorator forwards all requests to an enclosed TProtocol instance,
442 providing a way to author concise concrete decorator subclasses. The decorator
443 does not (and should not) modify the behaviour of the enclosed TProtocol
444
445 See p.175 of Design Patterns (by Gamma et al.)
446 }
447 TProtocolDecorator = class( TProtocolImpl)
448 private
449 FWrappedProtocol : IProtocol;
450
451 public
452 // Encloses the specified protocol.
453 // All operations will be forward to the given protocol. Must be non-null.
454 constructor Create( const aProtocol : IProtocol);
455
456 procedure WriteMessageBegin( const msg: IMessage); override;
457 procedure WriteMessageEnd; override;
458 procedure WriteStructBegin( const struc: IStruct); override;
459 procedure WriteStructEnd; override;
460 procedure WriteFieldBegin( const field: IField); override;
461 procedure WriteFieldEnd; override;
462 procedure WriteFieldStop; override;
463 procedure WriteMapBegin( const map: IMap); override;
464 procedure WriteMapEnd; override;
465 procedure WriteListBegin( const list: IList); override;
466 procedure WriteListEnd(); override;
467 procedure WriteSetBegin( const set_: ISet ); override;
468 procedure WriteSetEnd(); override;
469 procedure WriteBool( b: Boolean); override;
470 procedure WriteByte( b: ShortInt); override;
471 procedure WriteI16( i16: SmallInt); override;
472 procedure WriteI32( i32: Integer); override;
473 procedure WriteI64( const i64: Int64); override;
474 procedure WriteDouble( const d: Double); override;
475 procedure WriteString( const s: string ); override;
476 procedure WriteAnsiString( const s: AnsiString); override;
477 procedure WriteBinary( const b: TBytes); override;
478
479 function ReadMessageBegin: IMessage; override;
480 procedure ReadMessageEnd(); override;
481 function ReadStructBegin: IStruct; override;
482 procedure ReadStructEnd; override;
483 function ReadFieldBegin: IField; override;
484 procedure ReadFieldEnd(); override;
485 function ReadMapBegin: IMap; override;
486 procedure ReadMapEnd(); override;
487 function ReadListBegin: IList; override;
488 procedure ReadListEnd(); override;
489 function ReadSetBegin: ISet; override;
490 procedure ReadSetEnd(); override;
491 function ReadBool: Boolean; override;
492 function ReadByte: ShortInt; override;
493 function ReadI16: SmallInt; override;
494 function ReadI32: Integer; override;
495 function ReadI64: Int64; override;
496 function ReadDouble:Double; override;
497 function ReadBinary: TBytes; override;
498 function ReadString: string; override;
499 function ReadAnsiString: AnsiString; override;
500 end;
501
502
Jake Farrell7ae13e12011-10-18 14:35:26 +0000503implementation
504
Roger Meier333bbf32012-01-08 21:51:08 +0000505function ConvertInt64ToDouble( const n: Int64): Double;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000506begin
507 ASSERT( SizeOf(n) = SizeOf(Result));
508 System.Move( n, Result, SizeOf(Result));
509end;
510
Roger Meier333bbf32012-01-08 21:51:08 +0000511function ConvertDoubleToInt64( const d: Double): Int64;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000512begin
513 ASSERT( SizeOf(d) = SizeOf(Result));
514 System.Move( d, Result, SizeOf(Result));
515end;
516
517{ TFieldImpl }
518
519constructor TFieldImpl.Create(const AName: string; const AType: TType;
520 AId: SmallInt);
521begin
522 FName := AName;
523 FType := AType;
524 FId := AId;
525end;
526
527constructor TFieldImpl.Create;
528begin
529 FName := '';
530 FType := Low(TType);
531 FId := 0;
532end;
533
534function TFieldImpl.GetId: SmallInt;
535begin
536 Result := FId;
537end;
538
539function TFieldImpl.GetName: string;
540begin
541 Result := FName;
542end;
543
544function TFieldImpl.GetType: TType;
545begin
546 Result := FType;
547end;
548
549procedure TFieldImpl.SetId(Value: SmallInt);
550begin
551 FId := Value;
552end;
553
554procedure TFieldImpl.SetName(const Value: string);
555begin
556 FName := Value;
557end;
558
559procedure TFieldImpl.SetType(Value: TType);
560begin
561 FType := Value;
562end;
563
564{ TProtocolImpl }
565
566constructor TProtocolImpl.Create(trans: ITransport);
567begin
568 inherited Create;
569 FTrans := trans;
570end;
571
572function TProtocolImpl.GetTransport: ITransport;
573begin
574 Result := FTrans;
575end;
576
577function TProtocolImpl.ReadAnsiString: AnsiString;
578var
579 b : TBytes;
580 len : Integer;
581begin
582 Result := '';
583 b := ReadBinary;
584 len := Length( b );
585 if len > 0 then
586 begin
587 SetLength( Result, len);
588 System.Move( b[0], Pointer(Result)^, len );
589 end;
590end;
591
592function TProtocolImpl.ReadString: string;
593begin
594 Result := TEncoding.UTF8.GetString( ReadBinary );
595end;
596
597procedure TProtocolImpl.WriteAnsiString(const s: AnsiString);
598var
599 b : TBytes;
600 len : Integer;
601begin
602 len := Length(s);
603 SetLength( b, len);
604 if len > 0 then
605 begin
606 System.Move( Pointer(s)^, b[0], len );
607 end;
608 WriteBinary( b );
609end;
610
611procedure TProtocolImpl.WriteString(const s: string);
612var
613 b : TBytes;
614begin
615 b := TEncoding.UTF8.GetBytes(s);
616 WriteBinary( b );
617end;
618
619{ TProtocolUtil }
620
621class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType);
Jake Farrell6cd63ec2012-08-29 02:04:35 +0000622var field : IField;
623 map : IMap;
624 set_ : ISet;
625 list : IList;
626 i : Integer;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000627begin
Jake Farrell6cd63ec2012-08-29 02:04:35 +0000628 case type_ of
629 // simple types
630 TType.Bool_ : prot.ReadBool();
631 TType.Byte_ : prot.ReadByte();
632 TType.I16 : prot.ReadI16();
633 TType.I32 : prot.ReadI32();
634 TType.I64 : prot.ReadI64();
635 TType.Double_ : prot.ReadDouble();
636 TType.String_ : prot.ReadBinary();// Don't try to decode the string, just skip it.
Jake Farrell7ae13e12011-10-18 14:35:26 +0000637
Jake Farrell6cd63ec2012-08-29 02:04:35 +0000638 // structured types
639 TType.Struct : begin
640 prot.ReadStructBegin();
641 while TRUE do begin
642 field := prot.ReadFieldBegin();
643 if (field.Type_ = TType.Stop) then Break;
644 Skip(prot, field.Type_);
645 prot.ReadFieldEnd();
646 end;
647 prot.ReadStructEnd();
648 end;
649
650 TType.Map : begin
651 map := prot.ReadMapBegin();
652 for i := 0 to map.Count-1 do begin
653 Skip(prot, map.KeyType);
654 Skip(prot, map.ValueType);
655 end;
656 prot.ReadMapEnd();
657 end;
658
659 TType.Set_ : begin
660 set_ := prot.ReadSetBegin();
661 for i := 0 to set_.Count-1
662 do Skip( prot, set_.ElementType);
663 prot.ReadSetEnd();
664 end;
665
666 TType.List : begin
667 list := prot.ReadListBegin();
668 for i := 0 to list.Count-1
669 do Skip( prot, list.ElementType);
670 prot.ReadListEnd();
671 end;
672
673 else
674 ASSERT( FALSE); // any new types?
675 end;
Jake Farrell7ae13e12011-10-18 14:35:26 +0000676end;
677
678{ TStructImpl }
679
680constructor TStructImpl.Create(const AName: string);
681begin
682 inherited Create;
683 FName := AName;
684end;
685
686function TStructImpl.GetName: string;
687begin
688 Result := FName;
689end;
690
691procedure TStructImpl.SetName(const Value: string);
692begin
693 FName := Value;
694end;
695
696{ TMapImpl }
697
698constructor TMapImpl.Create(AValueType, AKeyType: TType; ACount: Integer);
699begin
700 inherited Create;
701 FValueType := AValueType;
702 FKeyType := AKeyType;
703 FCount := ACount;
704end;
705
706constructor TMapImpl.Create;
707begin
708
709end;
710
711function TMapImpl.GetCount: Integer;
712begin
713 Result := FCount;
714end;
715
716function TMapImpl.GetKeyType: TType;
717begin
718 Result := FKeyType;
719end;
720
721function TMapImpl.GetValueType: TType;
722begin
723 Result := FValueType;
724end;
725
726procedure TMapImpl.SetCount(Value: Integer);
727begin
728 FCount := Value;
729end;
730
731procedure TMapImpl.SetKeyType(Value: TType);
732begin
733 FKeyType := Value;
734end;
735
736procedure TMapImpl.SetValueType(Value: TType);
737begin
738 FValueType := Value;
739end;
740
741{ IMessage }
742
743constructor TMessageImpl.Create(AName: string; AMessageType: TMessageType;
744 ASeqID: Integer);
745begin
746 inherited Create;
747 FName := AName;
748 FMessageType := AMessageType;
749 FSeqID := ASeqID;
750end;
751
752constructor TMessageImpl.Create;
753begin
754 inherited;
755end;
756
757function TMessageImpl.GetName: string;
758begin
759 Result := FName;
760end;
761
762function TMessageImpl.GetSeqID: Integer;
763begin
764 Result := FSeqID;
765end;
766
767function TMessageImpl.GetType: TMessageType;
768begin
769 Result := FMessageType;
770end;
771
772procedure TMessageImpl.SetName(const Value: string);
773begin
774 FName := Value;
775end;
776
777procedure TMessageImpl.SetSeqID(Value: Integer);
778begin
779 FSeqID := Value;
780end;
781
782procedure TMessageImpl.SetType(Value: TMessageType);
783begin
784 FMessageType := Value;
785end;
786
787{ ISet }
788
789constructor TSetImpl.Create( AElementType: TType; ACount: Integer);
790begin
791 inherited Create;
792 FCount := ACount;
793 FElementType := AElementType;
794end;
795
796constructor TSetImpl.Create;
797begin
798
799end;
800
801function TSetImpl.GetCount: Integer;
802begin
803 Result := FCount;
804end;
805
806function TSetImpl.GetElementType: TType;
807begin
808 Result := FElementType;
809end;
810
811procedure TSetImpl.SetCount(Value: Integer);
812begin
813 FCount := Value;
814end;
815
816procedure TSetImpl.SetElementType(Value: TType);
817begin
818 FElementType := Value;
819end;
820
821{ IList }
822
823constructor TListImpl.Create( AElementType: TType; ACount: Integer);
824begin
825 inherited Create;
826 FCount := ACount;
827 FElementType := AElementType;
828end;
829
830constructor TListImpl.Create;
831begin
832
833end;
834
835function TListImpl.GetCount: Integer;
836begin
837 Result := FCount;
838end;
839
840function TListImpl.GetElementType: TType;
841begin
842 Result := FElementType;
843end;
844
845procedure TListImpl.SetCount(Value: Integer);
846begin
847 FCount := Value;
848end;
849
850procedure TListImpl.SetElementType(Value: TType);
851begin
852 FElementType := Value;
853end;
854
855{ TBinaryProtocolImpl }
856
Roger Meier333bbf32012-01-08 21:51:08 +0000857constructor TBinaryProtocolImpl.Create( const trans: ITransport);
Jake Farrell7ae13e12011-10-18 14:35:26 +0000858begin
859 Create( trans, False, True);
860end;
861
862procedure TBinaryProtocolImpl.CheckReadLength(len: Integer);
863begin
864 if FCheckReadLength then
865 begin
866 Dec( FReadLength, len);
867 if FReadLength < 0 then
868 begin
869 raise Exception.Create( 'Message length exceeded: ' + IntToStr( len ) );
870 end;
871 end;
872end;
873
Roger Meier333bbf32012-01-08 21:51:08 +0000874constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead,
Jake Farrell7ae13e12011-10-18 14:35:26 +0000875 strictWrite: Boolean);
876begin
877 inherited Create( trans );
878 FStrictRead := strictRead;
879 FStrictWrite := strictWrite;
880end;
881
882function TBinaryProtocolImpl.ReadAll( var buf: TBytes; off,
883 len: Integer): Integer;
884begin
885 CheckReadLength( len );
886 Result := FTrans.ReadAll( buf, off, len );
887end;
888
889function TBinaryProtocolImpl.ReadBinary: TBytes;
890var
891 size : Integer;
892 buf : TBytes;
893begin
894 size := ReadI32;
895 CheckReadLength( size );
896 SetLength( buf, size );
897 FTrans.ReadAll( buf, 0, size);
898 Result := buf;
899end;
900
901function TBinaryProtocolImpl.ReadBool: Boolean;
902begin
903 Result := ReadByte = 1;
904end;
905
906function TBinaryProtocolImpl.ReadByte: ShortInt;
907var
908 bin : TBytes;
909begin
910 SetLength( bin, 1);
911 ReadAll( bin, 0, 1 );
912 Result := ShortInt( bin[0]);
913end;
914
915function TBinaryProtocolImpl.ReadDouble: Double;
916begin
917 Result := ConvertInt64ToDouble( ReadI64 )
918end;
919
920function TBinaryProtocolImpl.ReadFieldBegin: IField;
921var
922 field : IField;
923begin
924 field := TFieldImpl.Create;
925 field.Type_ := TType( ReadByte);
926 if ( field.Type_ <> TType.Stop ) then
927 begin
928 field.Id := ReadI16;
929 end;
930 Result := field;
931end;
932
933procedure TBinaryProtocolImpl.ReadFieldEnd;
934begin
935
936end;
937
938function TBinaryProtocolImpl.ReadI16: SmallInt;
939var
940 i16in : TBytes;
941begin
942 SetLength( i16in, 2 );
943 ReadAll( i16in, 0, 2);
944 Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF));
945end;
946
947function TBinaryProtocolImpl.ReadI32: Integer;
948var
949 i32in : TBytes;
950begin
951 SetLength( i32in, 4 );
952 ReadAll( i32in, 0, 4);
953
954 Result := Integer(
955 ((i32in[0] and $FF) shl 24) or
956 ((i32in[1] and $FF) shl 16) or
957 ((i32in[2] and $FF) shl 8) or
958 (i32in[3] and $FF));
959
960end;
961
962function TBinaryProtocolImpl.ReadI64: Int64;
963var
964 i64in : TBytes;
965begin
966 SetLength( i64in, 8);
967 ReadAll( i64in, 0, 8);
968 Result :=
969 (Int64( i64in[0] and $FF) shl 56) or
970 (Int64( i64in[1] and $FF) shl 48) or
971 (Int64( i64in[2] and $FF) shl 40) or
972 (Int64( i64in[3] and $FF) shl 32) or
973 (Int64( i64in[4] and $FF) shl 24) or
974 (Int64( i64in[5] and $FF) shl 16) or
975 (Int64( i64in[6] and $FF) shl 8) or
976 (Int64( i64in[7] and $FF));
977end;
978
979function TBinaryProtocolImpl.ReadListBegin: IList;
980var
981 list : IList;
982begin
983 list := TListImpl.Create;
984 list.ElementType := TType( ReadByte );
985 list.Count := ReadI32;
986 Result := list;
987end;
988
989procedure TBinaryProtocolImpl.ReadListEnd;
990begin
991
992end;
993
994function TBinaryProtocolImpl.ReadMapBegin: IMap;
995var
996 map : IMap;
997begin
998 map := TMapImpl.Create;
999 map.KeyType := TType( ReadByte );
1000 map.ValueType := TType( ReadByte );
1001 map.Count := ReadI32;
1002 Result := map;
1003end;
1004
1005procedure TBinaryProtocolImpl.ReadMapEnd;
1006begin
1007
1008end;
1009
1010function TBinaryProtocolImpl.ReadMessageBegin: IMessage;
1011var
1012 size : Integer;
1013 version : Integer;
1014 message : IMessage;
1015begin
1016 message := TMessageImpl.Create;
1017 size := ReadI32;
1018 if (size < 0) then
1019 begin
1020 version := size and Integer( VERSION_MASK);
1021 if ( version <> Integer( VERSION_1)) then
1022 begin
1023 raise TProtocolException.Create(TProtocolException.BAD_VERSION, 'Bad version in ReadMessageBegin: ' + IntToStr(version) );
1024 end;
1025 message.Type_ := TMessageType( size and $000000ff);
1026 message.Name := ReadString;
1027 message.SeqID := ReadI32;
1028 end else
1029 begin
1030 if FStrictRead then
1031 begin
1032 raise TProtocolException.Create( TProtocolException.BAD_VERSION, 'Missing version in readMessageBegin, old client?' );
1033 end;
1034 message.Name := ReadStringBody( size );
1035 message.Type_ := TMessageType( ReadByte );
1036 message.SeqID := ReadI32;
1037 end;
1038 Result := message;
1039end;
1040
1041procedure TBinaryProtocolImpl.ReadMessageEnd;
1042begin
1043 inherited;
1044
1045end;
1046
1047function TBinaryProtocolImpl.ReadSetBegin: ISet;
1048var
1049 set_ : ISet;
1050begin
1051 set_ := TSetImpl.Create;
1052 set_.ElementType := TType( ReadByte );
1053 set_.Count := ReadI32;
1054 Result := set_;
1055end;
1056
1057procedure TBinaryProtocolImpl.ReadSetEnd;
1058begin
1059
1060end;
1061
1062function TBinaryProtocolImpl.ReadStringBody( size: Integer): string;
1063var
1064 buf : TBytes;
1065begin
1066 CheckReadLength( size );
1067 SetLength( buf, size );
1068 FTrans.ReadAll( buf, 0, size );
1069 Result := TEncoding.UTF8.GetString( buf);
1070end;
1071
1072function TBinaryProtocolImpl.ReadStructBegin: IStruct;
1073begin
1074 Result := TStructImpl.Create('');
1075end;
1076
1077procedure TBinaryProtocolImpl.ReadStructEnd;
1078begin
1079 inherited;
1080
1081end;
1082
1083procedure TBinaryProtocolImpl.SetReadLength(readLength: Integer);
1084begin
1085 FReadLength := readLength;
1086 FCheckReadLength := True;
1087end;
1088
1089procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);
Jake Farrell9c6773a2012-03-22 02:40:45 +00001090var iLen : Integer;
Jake Farrell7ae13e12011-10-18 14:35:26 +00001091begin
Jake Farrell9c6773a2012-03-22 02:40:45 +00001092 iLen := Length(b);
1093 WriteI32( iLen);
1094 if iLen > 0 then FTrans.Write(b, 0, iLen);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001095end;
1096
1097procedure TBinaryProtocolImpl.WriteBool(b: Boolean);
1098begin
1099 if b then
1100 begin
1101 WriteByte( 1 );
1102 end else
1103 begin
1104 WriteByte( 0 );
1105 end;
1106end;
1107
1108procedure TBinaryProtocolImpl.WriteByte(b: ShortInt);
1109var
1110 a : TBytes;
1111begin
1112 SetLength( a, 1);
1113 a[0] := Byte( b );
1114 FTrans.Write( a, 0, 1 );
1115end;
1116
Roger Meier333bbf32012-01-08 21:51:08 +00001117procedure TBinaryProtocolImpl.WriteDouble( const d: Double);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001118begin
1119 WriteI64(ConvertDoubleToInt64(d));
1120end;
1121
Roger Meier333bbf32012-01-08 21:51:08 +00001122procedure TBinaryProtocolImpl.WriteFieldBegin( const field: IField);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001123begin
1124 WriteByte(ShortInt(field.Type_));
1125 WriteI16(field.ID);
1126end;
1127
1128procedure TBinaryProtocolImpl.WriteFieldEnd;
1129begin
1130
1131end;
1132
1133procedure TBinaryProtocolImpl.WriteFieldStop;
1134begin
1135 WriteByte(ShortInt(TType.Stop));
1136end;
1137
1138procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt);
1139var
1140 i16out : TBytes;
1141begin
1142 SetLength( i16out, 2);
1143 i16out[0] := Byte($FF and (i16 shr 8));
1144 i16out[1] := Byte($FF and i16);
1145 FTrans.Write( i16out );
1146end;
1147
1148procedure TBinaryProtocolImpl.WriteI32(i32: Integer);
1149var
1150 i32out : TBytes;
1151begin
1152 SetLength( i32out, 4);
1153 i32out[0] := Byte($FF and (i32 shr 24));
1154 i32out[1] := Byte($FF and (i32 shr 16));
1155 i32out[2] := Byte($FF and (i32 shr 8));
1156 i32out[3] := Byte($FF and i32);
1157 FTrans.Write( i32out, 0, 4);
1158end;
1159
Roger Meier333bbf32012-01-08 21:51:08 +00001160procedure TBinaryProtocolImpl.WriteI64( const i64: Int64);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001161var
1162 i64out : TBytes;
1163begin
1164 SetLength( i64out, 8);
1165 i64out[0] := Byte($FF and (i64 shr 56));
1166 i64out[1] := Byte($FF and (i64 shr 48));
1167 i64out[2] := Byte($FF and (i64 shr 40));
1168 i64out[3] := Byte($FF and (i64 shr 32));
1169 i64out[4] := Byte($FF and (i64 shr 24));
1170 i64out[5] := Byte($FF and (i64 shr 16));
1171 i64out[6] := Byte($FF and (i64 shr 8));
1172 i64out[7] := Byte($FF and i64);
1173 FTrans.Write( i64out, 0, 8);
1174end;
1175
Roger Meier333bbf32012-01-08 21:51:08 +00001176procedure TBinaryProtocolImpl.WriteListBegin( const list: IList);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001177begin
1178 WriteByte(ShortInt(list.ElementType));
1179 WriteI32(list.Count);
1180end;
1181
1182procedure TBinaryProtocolImpl.WriteListEnd;
1183begin
1184
1185end;
1186
Roger Meier333bbf32012-01-08 21:51:08 +00001187procedure TBinaryProtocolImpl.WriteMapBegin( const map: IMap);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001188begin
1189 WriteByte(ShortInt(map.KeyType));
1190 WriteByte(ShortInt(map.ValueType));
1191 WriteI32(map.Count);
1192end;
1193
1194procedure TBinaryProtocolImpl.WriteMapEnd;
1195begin
1196
1197end;
1198
Roger Meier333bbf32012-01-08 21:51:08 +00001199procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: IMessage);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001200var
1201 version : Cardinal;
1202begin
1203 if FStrictWrite then
1204 begin
Roger Meier333bbf32012-01-08 21:51:08 +00001205 version := VERSION_1 or Cardinal( msg.Type_);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001206 WriteI32( Integer( version) );
Roger Meier333bbf32012-01-08 21:51:08 +00001207 WriteString( msg.Name);
Jake Farrell6cd63ec2012-08-29 02:04:35 +00001208 WriteI32( msg.SeqID);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001209 end else
1210 begin
Roger Meier333bbf32012-01-08 21:51:08 +00001211 WriteString( msg.Name);
1212 WriteByte(ShortInt( msg.Type_));
1213 WriteI32( msg.SeqID);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001214 end;
1215end;
1216
1217procedure TBinaryProtocolImpl.WriteMessageEnd;
1218begin
1219
1220end;
1221
Roger Meier333bbf32012-01-08 21:51:08 +00001222procedure TBinaryProtocolImpl.WriteSetBegin( const set_: ISet);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001223begin
1224 WriteByte(ShortInt(set_.ElementType));
1225 WriteI32(set_.Count);
1226end;
1227
1228procedure TBinaryProtocolImpl.WriteSetEnd;
1229begin
1230
1231end;
1232
Roger Meier333bbf32012-01-08 21:51:08 +00001233procedure TBinaryProtocolImpl.WriteStructBegin( const struc: IStruct);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001234begin
1235
1236end;
1237
1238procedure TBinaryProtocolImpl.WriteStructEnd;
1239begin
1240
1241end;
1242
1243{ TProtocolException }
1244
1245constructor TProtocolException.Create;
1246begin
1247 inherited Create('');
1248 FType := UNKNOWN;
1249end;
1250
1251constructor TProtocolException.Create(type_: Integer);
1252begin
1253 inherited Create('');
1254 FType := type_;
1255end;
1256
1257constructor TProtocolException.Create(type_: Integer; const msg: string);
1258begin
1259 inherited Create( msg );
1260 FType := type_;
1261end;
1262
1263{ TThriftStringBuilder }
1264
1265function TThriftStringBuilder.Append(const Value: TBytes): TStringBuilder;
1266begin
1267 Result := Append( string( RawByteString(Value)) );
1268end;
1269
1270function TThriftStringBuilder.Append(
1271 const Value: IThriftContainer): TStringBuilder;
1272begin
1273 Result := Append( Value.ToString );
1274end;
1275
1276{ TBinaryProtocolImpl.TFactory }
1277
1278constructor TBinaryProtocolImpl.TFactory.Create(AStrictRead, AStrictWrite: Boolean);
1279begin
1280 FStrictRead := AStrictRead;
1281 FStrictWrite := AStrictWrite;
1282end;
1283
1284constructor TBinaryProtocolImpl.TFactory.Create;
1285begin
1286 Create( False, True )
1287end;
1288
Roger Meier333bbf32012-01-08 21:51:08 +00001289function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
Jake Farrell7ae13e12011-10-18 14:35:26 +00001290begin
Jens Geyer5cb0d222013-03-07 20:44:22 +01001291 Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite);
Jake Farrell7ae13e12011-10-18 14:35:26 +00001292end;
1293
Jens Geyer8a701962013-03-25 01:28:12 +02001294
1295{ TProtocolDecorator }
1296
1297constructor TProtocolDecorator.Create( const aProtocol : IProtocol);
1298begin
1299 ASSERT( aProtocol <> nil);
1300 inherited Create( aProtocol.Transport);
1301 FWrappedProtocol := aProtocol;
1302end;
1303
1304
1305procedure TProtocolDecorator.WriteMessageBegin( const msg: IMessage);
1306begin
1307 FWrappedProtocol.WriteMessageBegin( msg);
1308end;
1309
1310
1311procedure TProtocolDecorator.WriteMessageEnd;
1312begin
1313 FWrappedProtocol.WriteMessageEnd;
1314end;
1315
1316
1317procedure TProtocolDecorator.WriteStructBegin( const struc: IStruct);
1318begin
1319 FWrappedProtocol.WriteStructBegin( struc);
1320end;
1321
1322
1323procedure TProtocolDecorator.WriteStructEnd;
1324begin
1325 FWrappedProtocol.WriteStructEnd;
1326end;
1327
1328
1329procedure TProtocolDecorator.WriteFieldBegin( const field: IField);
1330begin
1331 FWrappedProtocol.WriteFieldBegin( field);
1332end;
1333
1334
1335procedure TProtocolDecorator.WriteFieldEnd;
1336begin
1337 FWrappedProtocol.WriteFieldEnd;
1338end;
1339
1340
1341procedure TProtocolDecorator.WriteFieldStop;
1342begin
1343 FWrappedProtocol.WriteFieldStop;
1344end;
1345
1346
1347procedure TProtocolDecorator.WriteMapBegin( const map: IMap);
1348begin
1349 FWrappedProtocol.WriteMapBegin( map);
1350end;
1351
1352
1353procedure TProtocolDecorator.WriteMapEnd;
1354begin
1355 FWrappedProtocol.WriteMapEnd;
1356end;
1357
1358
1359procedure TProtocolDecorator.WriteListBegin( const list: IList);
1360begin
1361 FWrappedProtocol.WriteListBegin( list);
1362end;
1363
1364
1365procedure TProtocolDecorator.WriteListEnd();
1366begin
1367 FWrappedProtocol.WriteListEnd();
1368end;
1369
1370
1371procedure TProtocolDecorator.WriteSetBegin( const set_: ISet );
1372begin
1373 FWrappedProtocol.WriteSetBegin( set_);
1374end;
1375
1376
1377procedure TProtocolDecorator.WriteSetEnd();
1378begin
1379 FWrappedProtocol.WriteSetEnd();
1380end;
1381
1382
1383procedure TProtocolDecorator.WriteBool( b: Boolean);
1384begin
1385 FWrappedProtocol.WriteBool( b);
1386end;
1387
1388
1389procedure TProtocolDecorator.WriteByte( b: ShortInt);
1390begin
1391 FWrappedProtocol.WriteByte( b);
1392end;
1393
1394
1395procedure TProtocolDecorator.WriteI16( i16: SmallInt);
1396begin
1397 FWrappedProtocol.WriteI16( i16);
1398end;
1399
1400
1401procedure TProtocolDecorator.WriteI32( i32: Integer);
1402begin
1403 FWrappedProtocol.WriteI32( i32);
1404end;
1405
1406
1407procedure TProtocolDecorator.WriteI64( const i64: Int64);
1408begin
1409 FWrappedProtocol.WriteI64( i64);
1410end;
1411
1412
1413procedure TProtocolDecorator.WriteDouble( const d: Double);
1414begin
1415 FWrappedProtocol.WriteDouble( d);
1416end;
1417
1418
1419procedure TProtocolDecorator.WriteString( const s: string );
1420begin
1421 FWrappedProtocol.WriteString( s);
1422end;
1423
1424
1425procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString);
1426begin
1427 FWrappedProtocol.WriteAnsiString( s);
1428end;
1429
1430
1431procedure TProtocolDecorator.WriteBinary( const b: TBytes);
1432begin
1433 FWrappedProtocol.WriteBinary( b);
1434end;
1435
1436
1437function TProtocolDecorator.ReadMessageBegin: IMessage;
1438begin
1439 result := FWrappedProtocol.ReadMessageBegin;
1440end;
1441
1442
1443procedure TProtocolDecorator.ReadMessageEnd();
1444begin
1445 FWrappedProtocol.ReadMessageEnd();
1446end;
1447
1448
1449function TProtocolDecorator.ReadStructBegin: IStruct;
1450begin
1451 result := FWrappedProtocol.ReadStructBegin;
1452end;
1453
1454
1455procedure TProtocolDecorator.ReadStructEnd;
1456begin
1457 FWrappedProtocol.ReadStructEnd;
1458end;
1459
1460
1461function TProtocolDecorator.ReadFieldBegin: IField;
1462begin
1463 result := FWrappedProtocol.ReadFieldBegin;
1464end;
1465
1466
1467procedure TProtocolDecorator.ReadFieldEnd();
1468begin
1469 FWrappedProtocol.ReadFieldEnd();
1470end;
1471
1472
1473function TProtocolDecorator.ReadMapBegin: IMap;
1474begin
1475 result := FWrappedProtocol.ReadMapBegin;
1476end;
1477
1478
1479procedure TProtocolDecorator.ReadMapEnd();
1480begin
1481 FWrappedProtocol.ReadMapEnd();
1482end;
1483
1484
1485function TProtocolDecorator.ReadListBegin: IList;
1486begin
1487 result := FWrappedProtocol.ReadListBegin;
1488end;
1489
1490
1491procedure TProtocolDecorator.ReadListEnd();
1492begin
1493 FWrappedProtocol.ReadListEnd();
1494end;
1495
1496
1497function TProtocolDecorator.ReadSetBegin: ISet;
1498begin
1499 result := FWrappedProtocol.ReadSetBegin;
1500end;
1501
1502
1503procedure TProtocolDecorator.ReadSetEnd();
1504begin
1505 FWrappedProtocol.ReadSetEnd();
1506end;
1507
1508
1509function TProtocolDecorator.ReadBool: Boolean;
1510begin
1511 result := FWrappedProtocol.ReadBool;
1512end;
1513
1514
1515function TProtocolDecorator.ReadByte: ShortInt;
1516begin
1517 result := FWrappedProtocol.ReadByte;
1518end;
1519
1520
1521function TProtocolDecorator.ReadI16: SmallInt;
1522begin
1523 result := FWrappedProtocol.ReadI16;
1524end;
1525
1526
1527function TProtocolDecorator.ReadI32: Integer;
1528begin
1529 result := FWrappedProtocol.ReadI32;
1530end;
1531
1532
1533function TProtocolDecorator.ReadI64: Int64;
1534begin
1535 result := FWrappedProtocol.ReadI64;
1536end;
1537
1538
1539function TProtocolDecorator.ReadDouble:Double;
1540begin
1541 result := FWrappedProtocol.ReadDouble;
1542end;
1543
1544
1545function TProtocolDecorator.ReadBinary: TBytes;
1546begin
1547 result := FWrappedProtocol.ReadBinary;
1548end;
1549
1550
1551function TProtocolDecorator.ReadString: string;
1552begin
1553 result := FWrappedProtocol.ReadString;
1554end;
1555
1556
1557function TProtocolDecorator.ReadAnsiString: AnsiString;
1558begin
1559 result := FWrappedProtocol.ReadAnsiString;
1560end;
1561
1562
1563
Jake Farrell7ae13e12011-10-18 14:35:26 +00001564end.
1565