Stringify a protocol buffer object. Inputs: obj: a protocol buffer object, or a Pycaffe2 object that has a Proto() function. Outputs: string: the output protobuf string. Raises: AttributeError: if the passed in object does not have the right attribute.
(obj)
| 146 | |
| 147 | |
| 148 | def StringifyProto(obj): |
| 149 | """Stringify a protocol buffer object. |
| 150 | |
| 151 | Inputs: |
| 152 | obj: a protocol buffer object, or a Pycaffe2 object that has a Proto() |
| 153 | function. |
| 154 | Outputs: |
| 155 | string: the output protobuf string. |
| 156 | Raises: |
| 157 | AttributeError: if the passed in object does not have the right attribute. |
| 158 | """ |
| 159 | if isinstance(obj, basestring): |
| 160 | return obj |
| 161 | else: |
| 162 | if isinstance(obj, Message): |
| 163 | # First, see if this object is a protocol buffer, which we can |
| 164 | # simply serialize with the SerializeToString() call. |
| 165 | return obj.SerializeToString() |
| 166 | elif hasattr(obj, 'Proto'): |
| 167 | return obj.Proto().SerializeToString() |
| 168 | else: |
| 169 | raise ValueError("Unexpected argument to StringifyProto of type " + |
| 170 | type(obj).__name__) |
| 171 | |
| 172 | |
| 173 | def ResetWorkspace(root_folder=None): |
no test coverage detected
searching dependent graphs…