class_docstr: Splits a repeated message field on a proto.
class_docstr_tok: ["Splits","a","repeated","message","field","on","a","proto","."]
docstr: Splits the proto, and returns the size of the chunks created.
docstr_tok: ["Splits","the","proto",",","and","returns","the","size","of","the","chunks","created","."]
code: def build_chunks(self) -> int:
      """Splits the proto, and returns the size of the chunks created."""
      proto = self._proto
  
      total_size_diff = 0
  
      field, field_desc = util.get_field(proto, self.repeated_field)
      if not util.is_repeated(field_desc) and field_desc.message_type:
          raise ValueError(
              "RepeatedMessageSplitter can only be used on repeated fields. "
              f"Got proto={type(proto)}, field='{field_desc.name}'"
          )
  
      # List of indices at which to split the repeated field. For example, [3, 5]
      # means that the field list is split into: [:3], [3:5], [5:]
      repeated_msg_split = []
      # Should be the same length as the list above. Contains new protos to hold
      # the elements that are split from the original proto.
      # From the [3, 5] example above, the messages in this list contain nodes
      # [3:5] and [5:]
      repeated_msg_graphs = []
      # Track the total size of the current node split.
      total_size = 0
  
      # Linearly iterate through all nodes. It may be possible to optimize this
      # further by making best guesses as to where to split the nodes, since
      # most nodes (aside from constants) are relatively small.
      for n, ele in enumerate(field):
          size = ele.ByteSize()
  
          for splitter_cls in self.message_splitters:
              splitter = splitter_cls(
                  ele,
                  size,
                  parent_splitter=self,
                  fields_in_parent=self.repeated_field + [n],
              )
              size_diff = splitter.build_chunks()
              total_size_diff += size_diff
              size -= size_diff
  
          # Create a new GraphDef chunk if the current list of nodes is too large.
          if total_size + size >= constants.max_size():
              new_msg = type(self._proto)()
              repeated_msg_split.append(n)
              repeated_msg_graphs.append(new_msg)
              self.add_chunk(new_msg, [])
  
              if len(repeated_msg_split) >= 1:
                  total_size_diff += total_size
  
              total_size = 0
  
          total_size += size
  
      if repeated_msg_split:
          # Finish writing repeated chunks.
          start = repeated_msg_split[0]
          for end, msg in zip(
              itertools.chain.from_iterable(
                  [repeated_msg_split[1:], [None]]
              ),
              repeated_msg_graphs,
          ):
              _split_repeated_field(
                  proto, msg, self.repeated_field, start, end
              )
              start = end
          del field[repeated_msg_split[0] :]
  
      return total_size_diff
  
imports: from collections.abc import Sequence
  import itertools
  from typing import Optional, Type
  from google.protobuf import message
  from tensorflow.core.framework import graph_pb2
  from tensorflow.core.framework import node_def_pb2
  from tensorflow.python.framework import tensor_util
  from tensorflow.tools.proto_splitter import constants
  from tensorflow.tools.proto_splitter import split
  from tensorflow.tools.proto_splitter import util
label_desc: Use image node_id 2 for calling the RepeatedMessageSplitter obj's underlying member method code with example usage: obj.build_chunks() and returns: total_size_diff