/ src / python / txtai / serialize / factory.py
factory.py
 1  """
 2  Factory module
 3  """
 4  
 5  from .messagepack import MessagePack
 6  from .pickle import Pickle
 7  
 8  
 9  class SerializeFactory:
10      """
11      Methods to create data serializers.
12      """
13  
14      @staticmethod
15      def create(method=None, **kwargs):
16          """
17          Creates a new Serialize instance.
18  
19          Args:
20              method: serialization method
21              kwargs: additional keyword arguments to pass to serialize instance
22          """
23  
24          # Pickle serialization
25          if method == "pickle":
26              return Pickle(**kwargs)
27  
28          # Default serialization
29          return MessagePack(**kwargs)