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