MCPcopy Index your code
hub / github.com/pytorch/pytorch / TryReadProtoWithClass

Function TryReadProtoWithClass

caffe2/python/utils.py:197–216  ·  view source on GitHub ↗

Reads a protobuffer with the given proto class. Inputs: cls: a protobuffer class. s: a string of either binary or text protobuffer content. Outputs: proto: the protobuffer of cls Throws: google.protobuf.message.DecodeError: if we cannot decode the message.

(cls, s)

Source from the content-addressed store, hash-verified

195
196
197def TryReadProtoWithClass(cls, s):
198 """Reads a protobuffer with the given proto class.
199
200 Inputs:
201 cls: a protobuffer class.
202 s: a string of either binary or text protobuffer content.
203
204 Outputs:
205 proto: the protobuffer of cls
206
207 Throws:
208 google.protobuf.message.DecodeError: if we cannot decode the message.
209 """
210 obj = cls()
211 try:
212 text_format.Parse(s, obj)
213 return obj
214 except (text_format.ParseError, UnicodeDecodeError):
215 obj.ParseFromString(s)
216 return obj
217
218
219def GetContentFromProto(obj, function_map):

Callers 2

ConvertProtoToBinaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…