1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.facebook.thrift.protocol;
18 
19 import com.facebook.thrift.TException;
20 import com.facebook.thrift.meta_data.FieldMetaData;
21 import java.util.Map;
22 
23 /**
24  * <code>TProtocolDecorator</code> forwards all requests to an enclosed <code>TProtocol</code>
25  * instance, providing a way to author concise concrete decorator subclasses. While it has no
26  * abstract methods, it is marked abstract as a reminder that by itself, it does not modify the
27  * behaviour of the enclosed <code>TProtocol</code>.
28  *
29  * <p>
30  *
31  * <p>See p.175 of Design Patterns (by Gamma et al.)
32  *
33  * @see org.apache.thrift.protocol.TMultiplexedProtocol
34  */
35 public abstract class TProtocolDecorator extends TProtocol {
36 
37   private final TProtocol concreteProtocol;
38 
39   /**
40    * Encloses the specified protocol.
41    *
42    * @param protocol All operations will be forward to this protocol. Must be non-null.
43    */
TProtocolDecorator(TProtocol protocol)44   public TProtocolDecorator(TProtocol protocol) {
45     super(protocol.getTransport());
46     concreteProtocol = protocol;
47   }
48 
writeMessageBegin(TMessage tMessage)49   public void writeMessageBegin(TMessage tMessage) throws TException {
50     concreteProtocol.writeMessageBegin(tMessage);
51   }
52 
writeMessageEnd()53   public void writeMessageEnd() throws TException {
54     concreteProtocol.writeMessageEnd();
55   }
56 
writeStructBegin(TStruct tStruct)57   public void writeStructBegin(TStruct tStruct) throws TException {
58     concreteProtocol.writeStructBegin(tStruct);
59   }
60 
writeStructEnd()61   public void writeStructEnd() throws TException {
62     concreteProtocol.writeStructEnd();
63   }
64 
writeFieldBegin(TField tField)65   public void writeFieldBegin(TField tField) throws TException {
66     concreteProtocol.writeFieldBegin(tField);
67   }
68 
writeFieldEnd()69   public void writeFieldEnd() throws TException {
70     concreteProtocol.writeFieldEnd();
71   }
72 
writeFieldStop()73   public void writeFieldStop() throws TException {
74     concreteProtocol.writeFieldStop();
75   }
76 
writeMapBegin(TMap tMap)77   public void writeMapBegin(TMap tMap) throws TException {
78     concreteProtocol.writeMapBegin(tMap);
79   }
80 
writeMapEnd()81   public void writeMapEnd() throws TException {
82     concreteProtocol.writeMapEnd();
83   }
84 
writeListBegin(TList tList)85   public void writeListBegin(TList tList) throws TException {
86     concreteProtocol.writeListBegin(tList);
87   }
88 
writeListEnd()89   public void writeListEnd() throws TException {
90     concreteProtocol.writeListEnd();
91   }
92 
writeSetBegin(TSet tSet)93   public void writeSetBegin(TSet tSet) throws TException {
94     concreteProtocol.writeSetBegin(tSet);
95   }
96 
writeSetEnd()97   public void writeSetEnd() throws TException {
98     concreteProtocol.writeSetEnd();
99   }
100 
writeBool(boolean b)101   public void writeBool(boolean b) throws TException {
102     concreteProtocol.writeBool(b);
103   }
104 
writeByte(byte b)105   public void writeByte(byte b) throws TException {
106     concreteProtocol.writeByte(b);
107   }
108 
writeI16(short i)109   public void writeI16(short i) throws TException {
110     concreteProtocol.writeI16(i);
111   }
112 
writeI32(int i)113   public void writeI32(int i) throws TException {
114     concreteProtocol.writeI32(i);
115   }
116 
writeI64(long l)117   public void writeI64(long l) throws TException {
118     concreteProtocol.writeI64(l);
119   }
120 
writeFloat(float v)121   public void writeFloat(float v) throws TException {
122     concreteProtocol.writeFloat(v);
123   }
124 
writeDouble(double v)125   public void writeDouble(double v) throws TException {
126     concreteProtocol.writeDouble(v);
127   }
128 
writeString(String s)129   public void writeString(String s) throws TException {
130     concreteProtocol.writeString(s);
131   }
132 
writeBinary(byte[] buf)133   public void writeBinary(byte[] buf) throws TException {
134     concreteProtocol.writeBinary(buf);
135   }
136 
readMessageBegin()137   public TMessage readMessageBegin() throws TException {
138     return concreteProtocol.readMessageBegin();
139   }
140 
readMessageEnd()141   public void readMessageEnd() throws TException {
142     concreteProtocol.readMessageEnd();
143   }
144 
readStructBegin(Map<Integer, FieldMetaData> m)145   public TStruct readStructBegin(Map<Integer, FieldMetaData> m) throws TException {
146     return concreteProtocol.readStructBegin(m);
147   }
148 
readStructEnd()149   public void readStructEnd() throws TException {
150     concreteProtocol.readStructEnd();
151   }
152 
readFieldBegin()153   public TField readFieldBegin() throws TException {
154     return concreteProtocol.readFieldBegin();
155   }
156 
readFieldEnd()157   public void readFieldEnd() throws TException {
158     concreteProtocol.readFieldEnd();
159   }
160 
readMapBegin()161   public TMap readMapBegin() throws TException {
162     return concreteProtocol.readMapBegin();
163   }
164 
readMapEnd()165   public void readMapEnd() throws TException {
166     concreteProtocol.readMapEnd();
167   }
168 
readListBegin()169   public TList readListBegin() throws TException {
170     return concreteProtocol.readListBegin();
171   }
172 
readListEnd()173   public void readListEnd() throws TException {
174     concreteProtocol.readListEnd();
175   }
176 
readSetBegin()177   public TSet readSetBegin() throws TException {
178     return concreteProtocol.readSetBegin();
179   }
180 
readSetEnd()181   public void readSetEnd() throws TException {
182     concreteProtocol.readSetEnd();
183   }
184 
readBool()185   public boolean readBool() throws TException {
186     return concreteProtocol.readBool();
187   }
188 
readByte()189   public byte readByte() throws TException {
190     return concreteProtocol.readByte();
191   }
192 
readI16()193   public short readI16() throws TException {
194     return concreteProtocol.readI16();
195   }
196 
readI32()197   public int readI32() throws TException {
198     return concreteProtocol.readI32();
199   }
200 
readI64()201   public long readI64() throws TException {
202     return concreteProtocol.readI64();
203   }
204 
readFloat()205   public float readFloat() throws TException {
206     return concreteProtocol.readFloat();
207   }
208 
readDouble()209   public double readDouble() throws TException {
210     return concreteProtocol.readDouble();
211   }
212 
readString()213   public String readString() throws TException {
214     return concreteProtocol.readString();
215   }
216 
readBinary()217   public byte[] readBinary() throws TException {
218     return concreteProtocol.readBinary();
219   }
220 
221   @Override
typeMinimumSize(byte type)222   protected int typeMinimumSize(byte type) {
223     return concreteProtocol.typeMinimumSize(type);
224   }
225 }
226