@@ -2430,6 +2430,47 @@ def raw_mod2m(self, m):
24302430 def output (self ):
24312431 print_reg_plains (self )
24322432
2433+ @classmethod
2434+ @set_instruction_type
2435+ def read_from_file (cls , start , n_items = 1 , crash_if_missing = True , size = 1 ):
2436+ """ Read shares from
2437+ ``Persistence/Transactions-[gf2n-]P<playerno>.data``. See :ref:`this
2438+ section <persistence>` for details on the data format.
2439+
2440+ :param start: starting position in number of shares from beginning (int/regint/cint)
2441+ :param n_items: number of items (int)
2442+ :param crash_if_missing: crash if file not found (default)
2443+ :param size: vector size (int)
2444+ :returns: destination for final position, -1 for eof reached, or -2 for file not found (regint)
2445+ :returns: list of shares
2446+ """
2447+ shares = [cls (size = size ) for i in range (n_items )]
2448+ stop = regint ()
2449+ readsharesfromfile (regint .conv (start ), stop , * shares )
2450+ if crash_if_missing :
2451+ library .runtime_error_if (stop == - 2 , 'Persistence not found' )
2452+ return stop , shares
2453+
2454+ @classmethod
2455+ @set_instruction_type
2456+ def write_to_file (cls , shares , position = None ):
2457+ """ Write shares to ``Persistence/Transactions-[gf2n-]P<playerno>.data``
2458+ (appending at the end). See :ref:`this section <persistence>`
2459+ for details on the data format.
2460+
2461+ :param shares: (list or iterable of shares)
2462+ :param position: start position (int/regint/cint),
2463+ defaults to end of file
2464+ """
2465+ if isinstance (shares , cls ):
2466+ shares = [shares ]
2467+ for share in shares :
2468+ assert isinstance (share , cls )
2469+ assert share .size == shares [0 ].size
2470+ if position is None :
2471+ position = - 1
2472+ writesharestofile (regint .conv (position ), * shares )
2473+
24332474class sint (_secret , _int ):
24342475 """
24352476 Secret integer in the protocol-specific domain. It supports
@@ -2699,45 +2740,6 @@ def write_shares_to_socket(cls, client_id, values,
26992740 """
27002741 writesocketshare (client_id , message_type , values [0 ].size , * values )
27012742
2702- @classmethod
2703- def read_from_file (cls , start , n_items = 1 , crash_if_missing = True , size = 1 ):
2704- """ Read shares from
2705- ``Persistence/Transactions-P<playerno>.data``. See :ref:`this
2706- section <persistence>` for details on the data format.
2707-
2708- :param start: starting position in number of shares from beginning (int/regint/cint)
2709- :param n_items: number of items (int)
2710- :param crash_if_missing: crash if file not found (default)
2711- :param size: vector size (int)
2712- :returns: destination for final position, -1 for eof reached, or -2 for file not found (regint)
2713- :returns: list of shares
2714- """
2715- shares = [cls (size = size ) for i in range (n_items )]
2716- stop = regint ()
2717- readsharesfromfile (regint .conv (start ), stop , * shares )
2718- if crash_if_missing :
2719- library .runtime_error_if (stop == - 2 , 'Persistence not found' )
2720- return stop , shares
2721-
2722- @staticmethod
2723- def write_to_file (shares , position = None ):
2724- """ Write shares to ``Persistence/Transactions-P<playerno>.data``
2725- (appending at the end). See :ref:`this section <persistence>`
2726- for details on the data format.
2727-
2728- :param shares: (list or iterable of sint)
2729- :param position: start position (int/regint/cint),
2730- defaults to end of file
2731- """
2732- if isinstance (shares , sint ):
2733- shares = [shares ]
2734- for share in shares :
2735- assert isinstance (share , sint )
2736- assert share .size == shares [0 ].size
2737- if position is None :
2738- position = - 1
2739- writesharestofile (regint .conv (position ), * shares )
2740-
27412743 @vectorized_classmethod
27422744 def load_mem (cls , address , mem_type = None ):
27432745 """ Load from memory by public address. """
0 commit comments