Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 1 | class TType: |
| 2 | STOP = 0 |
| 3 | VOID = 1 |
| 4 | BOOL = 2 |
| 5 | BYTE = 3 |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 6 | I08 = 3 |
| 7 | DOUBLE = 4 |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 8 | I16 = 6 |
| 9 | I32 = 8 |
| 10 | I64 = 10 |
| 11 | STRING = 11 |
| 12 | UTF7 = 11 |
| 13 | STRUCT = 12 |
| 14 | MAP = 13 |
| 15 | SET = 14 |
| 16 | LIST = 15 |
| 17 | UTF8 = 16 |
| 18 | UTF16 = 17 |
| 19 | |
| 20 | class TMessageType: |
| 21 | CALL = 1 |
| 22 | REPLY = 2 |
| 23 | |
| 24 | class TProtocolBase: |
| 25 | |
| 26 | """Base class for Thrift protocol driver.""" |
| 27 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 28 | def __init__(self, itrans, otrans=None): |
| 29 | self.itrans = self.otrans = itrans |
| 30 | if otrans != None: |
| 31 | self.otrans = otrans |
| 32 | |
| 33 | def writeMessageBegin(self, name, type, seqid): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 34 | pass |
| 35 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 36 | def writeMessageEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 37 | pass |
| 38 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 39 | def writeStructBegin(self, name): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 40 | pass |
| 41 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 42 | def writeStructEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 43 | pass |
| 44 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 45 | def writeFieldBegin(self, name, type, id): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 46 | pass |
| 47 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 48 | def writeFieldEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 49 | pass |
| 50 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 51 | def writeFieldStop(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 52 | pass |
| 53 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 54 | def writeMapBegin(self, ktype, vtype, size): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 55 | pass |
| 56 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 57 | def writeMapEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 58 | pass |
| 59 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 60 | def writeListBegin(self, etype, size): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 61 | pass |
| 62 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 63 | def writeListEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 64 | pass |
| 65 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 66 | def writeSetBegin(self, etype, size): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 67 | pass |
| 68 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 69 | def writeSetEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 70 | pass |
| 71 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 72 | def writeBool(self, bool): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 73 | pass |
| 74 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 75 | def writeByte(self, byte): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 76 | pass |
| 77 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 78 | def writeI16(self, i16): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 79 | pass |
| 80 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 81 | def writeI32(self, i32): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 82 | pass |
| 83 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 84 | def writeI64(self, i64): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 85 | pass |
| 86 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 87 | def writeDouble(self, dub): |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 88 | pass |
| 89 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 90 | def writeString(self, str): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 91 | pass |
| 92 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 93 | def readMessageBegin(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 94 | pass |
| 95 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 96 | def readMessageEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 97 | pass |
| 98 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 99 | def readStructBegin(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 100 | pass |
| 101 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 102 | def readStructEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 103 | pass |
| 104 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 105 | def readFieldBegin(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 106 | pass |
| 107 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 108 | def readFieldEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 109 | pass |
| 110 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 111 | def readMapBegin(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 112 | pass |
| 113 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 114 | def readMapEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 115 | pass |
| 116 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 117 | def readListBegin(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 118 | pass |
| 119 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 120 | def readListEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 121 | pass |
| 122 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 123 | def readSetBegin(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 124 | pass |
| 125 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 126 | def readSetEnd(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 127 | pass |
| 128 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 129 | def readBool(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 130 | pass |
| 131 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 132 | def readByte(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 133 | pass |
| 134 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 135 | def readI16(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 136 | pass |
| 137 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 138 | def readI32(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 139 | pass |
| 140 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 141 | def readI64(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 142 | pass |
| 143 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 144 | def readDouble(self): |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 145 | pass |
| 146 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 147 | def readString(self): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 148 | pass |
| 149 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 150 | def skip(self, type): |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 151 | if type == TType.STOP: |
| 152 | return |
| 153 | elif type == TType.BOOL: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 154 | self.readBool() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 155 | elif type == TType.BYTE: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 156 | self.readByte() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 157 | elif type == TType.I16: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 158 | self.readI16() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 159 | elif type == TType.I32: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 160 | self.readI32() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 161 | elif type == TType.I64: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 162 | self.readI64() |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 163 | elif type == TType.DOUBLE: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 164 | self.readDouble() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 165 | elif type == TType.STRING: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 166 | self.readString() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 167 | elif type == TType.STRUCT: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 168 | name = self.readStructBegin() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 169 | while True: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 170 | (name, type, id) = self.readFieldBegin() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 171 | if type == TType.STOP: |
| 172 | break |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 173 | self.skip(type) |
| 174 | self.readFieldEnd() |
| 175 | self.readStructEnd() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 176 | elif type == TType.MAP: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 177 | (ktype, vtype, size) = self.readMapBegin() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 178 | for i in range(size): |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 179 | self.skip(ktype) |
| 180 | self.skip(vtype) |
| 181 | self.readMapEnd() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 182 | elif type == TType.SET: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 183 | (etype, size) = self.readSetBegin() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 184 | for i in range(size): |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 185 | self.skip(etype) |
| 186 | self.readSetEnd() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 187 | elif type == TType.LIST: |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 188 | (etype, size) = self.readListBegin() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 189 | for i in range(size): |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 190 | self.skip(etype) |
| 191 | self.readListEnd() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 192 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame^] | 193 | class TProtocolFactory: |
| 194 | def getIOProtocols(self, itrans, otrans): |
| 195 | pass |