class_docstr: Serialize and deserialize protobuf message.
class_docstr_tok: ["Serialize","and","deserialize","protobuf","message","."]
code: def serialize_proto(self, proto: _Proto) -> bytes:
      if hasattr(proto, "SerializeToString") and callable(
          proto.SerializeToString
      ):
          try:
              result = proto.SerializeToString()
          except ValueError as e:
              if proto.ByteSize() >= onnx.checker.MAXIMUM_PROTOBUF:
                  raise ValueError(
                      "The proto size is larger than the 2 GB limit. "
                      "Please use save_as_external_data to save tensors separately from the model file."
                  ) from e
              raise
          return result  # type: ignore
      raise TypeError(
          f"No SerializeToString method is detected.\ntype is {type(proto)}"
      )
  
imports: from __future__ import annotations
  import warnings
  import typing
  from typing import Any, Collection, Optional, Protocol, TypeVar
  import google.protobuf.json_format
  import google.protobuf.message
  import google.protobuf.text_format
  import onnx
label_desc: Use image node_id 1 for calling the _ProtobufSerializer obj's underlying member method code with example usage: obj.serialize_proto(proto) and returns: result