Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.#from thrift.Thrift import *class TProtocolException(TException):"""Custom Protocol Exception class"""UNKNOWN = 0INVALID_DATA = 1NEGATIVE_SIZE = 2SIZE_LIMIT = 3BAD_VERSION = 4def __init__(self, type=UNKNOWN, message=None):TException.__init__(self, message)self.type = typeclass TProtocolBase:"""Base class for Thrift protocol driver."""def __init__(self, trans):self.trans = transdef writeMessageBegin(self, name, type, seqid):passdef writeMessageEnd(self):passdef writeStructBegin(self, name):passdef writeStructEnd(self):passdef writeFieldBegin(self, name, type, id):passdef writeFieldEnd(self):passdef writeFieldStop(self):passdef writeMapBegin(self, ktype, vtype, size):passdef writeMapEnd(self):passdef writeListBegin(self, etype, size):passdef writeListEnd(self):passdef writeSetBegin(self, etype, size):passdef writeSetEnd(self):passdef writeBool(self, bool):passdef writeByte(self, byte):passdef writeI16(self, i16):passdef writeI32(self, i32):passdef writeI64(self, i64):passdef writeDouble(self, dub):passdef writeString(self, str):passdef readMessageBegin(self):passdef readMessageEnd(self):passdef readStructBegin(self):passdef readStructEnd(self):passdef readFieldBegin(self):passdef readFieldEnd(self):passdef readMapBegin(self):passdef readMapEnd(self):passdef readListBegin(self):passdef readListEnd(self):passdef readSetBegin(self):passdef readSetEnd(self):passdef readBool(self):passdef readByte(self):passdef readI16(self):passdef readI32(self):passdef readI64(self):passdef readDouble(self):passdef readString(self):passdef skip(self, type):if type == TType.STOP:returnelif type == TType.BOOL:self.readBool()elif type == TType.BYTE:self.readByte()elif type == TType.I16:self.readI16()elif type == TType.I32:self.readI32()elif type == TType.I64:self.readI64()elif type == TType.DOUBLE:self.readDouble()elif type == TType.STRING:self.readString()elif type == TType.STRUCT:name = self.readStructBegin()while True:(name, type, id) = self.readFieldBegin()if type == TType.STOP:breakself.skip(type)self.readFieldEnd()self.readStructEnd()elif type == TType.MAP:(ktype, vtype, size) = self.readMapBegin()for i in range(size):self.skip(ktype)self.skip(vtype)self.readMapEnd()elif type == TType.SET:(etype, size) = self.readSetBegin()for i in range(size):self.skip(etype)self.readSetEnd()elif type == TType.LIST:(etype, size) = self.readListBegin()for i in range(size):self.skip(etype)self.readListEnd()class TProtocolFactory:def getProtocol(self, trans):pass