MCPcopy Create free account
hub / github.com/ampproject/amphtml / MessageKey

Class MessageKey

validator/validator_gen_js.py:77–97  ·  view source on GitHub ↗

A hashable key for a proto message capturing its type and content. Messages of the same type (we use the short type name here, e.g. AttrSpec) that serialize to the same byte string are considered the same.

Source from the content-addressed store, hash-verified

75
76
77class MessageKey(object):
78 """A hashable key for a proto message capturing its type and content.
79
80 Messages of the same type (we use the short type name here, e.g. AttrSpec)
81 that serialize to the same byte string are considered the same.
82 """
83
84 def __init__(self, proto_message):
85 self.type_name = proto_message.DESCRIPTOR.name
86 # While it's not strictly necessary to use a digest here, we do so
87 # to avoid carrying around the whole serialized string all the time.
88 self.digest = hashlib.sha1(proto_message.SerializeToString()).hexdigest()
89
90 def __hash__(self):
91 return hash((self.type_name, self.digest))
92
93 def __eq__(self, other):
94 return (self.type_name, self.digest) == (other.type_name, other.digest)
95
96 def __ne__(self, other):
97 return not self == other
98
99
100class MessageRegistry(object):

Callers 6

RegisterTagSpecMethod · 0.85
RegisterAttrListMethod · 0.85
MaybePrintMessageValueFunction · 0.85
InternOrReferenceFunction · 0.85
PrintObjectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected