| 15043 | |
| 15044 | @functools.total_ordering |
| 15045 | class StructHashEx(object): |
| 15046 | __slots__ = "f1", "f2", |
| 15047 | |
| 15048 | def __init__(self, f1=None, f2=None): |
| 15049 | if f1 is None: |
| 15050 | f1 = dict() |
| 15051 | if f2 is None: |
| 15052 | f2 = dict() |
| 15053 | self.f1 = f1 |
| 15054 | self.f2 = f2 |
| 15055 | |
| 15056 | # Struct shallow copy |
| 15057 | def copy(self, other): |
| 15058 | self.f1 = other.f1 |
| 15059 | self.f2 = other.f2 |
| 15060 | return self |
| 15061 | |
| 15062 | # Struct deep clone |
| 15063 | def clone(self): |
| 15064 | # Serialize the struct to the FBE stream |
| 15065 | writer = StructHashExModel(fbe.WriteBuffer()) |
| 15066 | writer.serialize(self) |
| 15067 | |
| 15068 | # Deserialize the struct from the FBE stream |
| 15069 | reader = StructHashExModel(fbe.ReadBuffer()) |
| 15070 | reader.attach_buffer(writer.buffer) |
| 15071 | return reader.deserialize()[0] |
| 15072 | |
| 15073 | def __eq__(self, other): |
| 15074 | if not isinstance(self, other.__class__): |
| 15075 | return NotImplemented |
| 15076 | return True |
| 15077 | |
| 15078 | def __lt__(self, other): |
| 15079 | if not isinstance(self, other.__class__): |
| 15080 | return NotImplemented |
| 15081 | return False |
| 15082 | |
| 15083 | @property |
| 15084 | def __key__(self): |
| 15085 | return () |
| 15086 | |
| 15087 | def __hash__(self): |
| 15088 | return hash(self.__key__) |
| 15089 | |
| 15090 | def __format__(self, format_spec): |
| 15091 | return self.__str__() |
| 15092 | |
| 15093 | def __str__(self): |
| 15094 | sb = list() |
| 15095 | sb.append("StructHashEx(") |
| 15096 | sb.append("f1=") |
| 15097 | if self.f1 is not None: |
| 15098 | first = True |
| 15099 | sb.append("[" + str(len(self.f1)) + "][{") |
| 15100 | for key, value in self.f1.items(): |
| 15101 | sb.append("" if first else ",") |
| 15102 | sb.append(str(key)) |
no outgoing calls