Method
readStruct
(self, obj, thrift_spec, is_immutable=False)
Source from the content-addressed store, hash-verified
| 318 | return results |
| 319 | |
| 320 | def readStruct(self, obj, thrift_spec, is_immutable=False): |
| 321 | if is_immutable: |
| 322 | fields = {} |
| 323 | self.readStructBegin() |
| 324 | while True: |
| 325 | (fname, ftype, fid) = self.readFieldBegin() |
| 326 | if ftype == TType.STOP: |
| 327 | break |
| 328 | try: |
| 329 | field = thrift_spec[fid] |
| 330 | except IndexError: |
| 331 | self.skip(ftype) |
| 332 | else: |
| 333 | if field is not None and ftype == field[1]: |
| 334 | fname = field[2] |
| 335 | fspec = field[3] |
| 336 | val = self.readFieldByTType(ftype, fspec) |
| 337 | if is_immutable: |
| 338 | fields[fname] = val |
| 339 | else: |
| 340 | setattr(obj, fname, val) |
| 341 | else: |
| 342 | self.skip(ftype) |
| 343 | self.readFieldEnd() |
| 344 | self.readStructEnd() |
| 345 | if is_immutable: |
| 346 | return obj(**fields) |
| 347 | |
| 348 | def writeContainerStruct(self, val, spec): |
| 349 | val.write(self) |