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