@@ -2373,16 +2373,123 @@ class PtxtArray
23732373 // this is here for consistency with Ctxt class
23742374 void negate () { helib::negate (ea, pa); }
23752375
2376+ /* *
2377+ * @brief Function to serialize `this` `PtxtArray`.
2378+ * @param os Output `std::ostream`.
2379+ * @note `PtxtArray` `context` is not serialized, see note of `readJSON`.
2380+ *
2381+ * The output stream will be a JSON where the `PtxtArray` content will be
2382+ * serialized in the `slots` field.\n
2383+ * Each slot of `PtxtArray` will be serialized in an element of such list by
2384+ * the JSON serializer function determined by the scheme.\n
2385+ * For example if we have a plaintext `pa` such that `pa[0]=slot0`,
2386+ * `pa[1]=slot1`, `pa[2]=slot2`, and `pa[i]=0` for `i>2`, it will be
2387+ * serialized as '['slot0', 'slot1', 'slot2', `0`, `0` ...]'.
2388+ **/
23762389 void writeToJSON (std::ostream& os) const ;
23772390
2391+ /* *
2392+ * @brief Function to serialize `this` `PtxtArray`.
2393+ * @return The `JsonWrapper` containing the serialization.
2394+ * @note `PtxtArray` `context` is not serialized, see note of `readJSON`.
2395+ *
2396+ * The output JsonWrapper will be a JSON where the `PtxtArray` content will
2397+ * be serialized in the `slots` field.\n
2398+ * Each slot of `PtxtArray` will be serialized in an element of such list by
2399+ * the JSON serializer function determined by the scheme.\n
2400+ * For example if we have a plaintext `pa` such that `pa[0]=slot0`,
2401+ * `pa[1]=slot1`, `pa[2]=slot2`, and `pa[i]=0` for `i>2`, it will be
2402+ * serialized as '['slot0', 'slot1', 'slot2', `0`, `0`, ...]'.
2403+ **/
23782404 JsonWrapper writeToJSON () const ;
23792405
2406+ /* *
2407+ * @brief Function to deserialize and return a `PtxtArray` from a JSON
2408+ * stream.
2409+ * @param is Input `std::istream`.
2410+ * @throws IOError if the stream is badly formatted (i.e. it does not contain
2411+ * a valid JSON).
2412+ * @code
2413+ * PtxtArray my_pa = PtxtArray::readFromJSON(std::cin, context);
2414+ * @endcode
2415+ *
2416+ * The input stream has to contain a valid typed JSON value.\n
2417+ * Each element of the content list will be deserialized as a slot of the type
2418+ * determined by the scheme.\n
2419+ * If the number of tokens in the slot list is less than the number of slots,
2420+ * the remaining slots will be padded by 0.\n
2421+ * For example a slot list '['slot0', 'slot1', 'slot2']' will be deserialized
2422+ * as a plaintext `pa` where `pa[0]=slot0`, `pa[1]=slot1`, `pa[2]=slot2`, and
2423+ * `pa[i]=0` for `i>2`.
2424+ **/
23802425 static PtxtArray readFromJSON (std::istream& is, const Context& context);
23812426
2427+ /* *
2428+ * @brief Function to deserialize and return a `PtxtArray` from a
2429+ * `JsonWrapper` object.
2430+ * @param jw `JsonWrapper` containing the serialized object.
2431+ * @throws IOError if the `JsonWrapper` object does not contains a valid
2432+ * serialization of a `PtxtArray`.
2433+ * @code
2434+ * PtxtArray my_pa = PtxtArray::readFromJSON(..., context);
2435+ * @endcode
2436+ *
2437+ * The `JsonWrapper` must contain a valid `PtxtArray` serialization.\n
2438+ * Each element of the content list will be deserialized as a slot of the
2439+ * type determined by the scheme.\n
2440+ * If the number of tokens in the slot list is less than the number of slots,
2441+ * the remaining slots will be padded by 0.\n
2442+ * For example a slot list '['slot0', 'slot1', 'slot2']' will be deserialized
2443+ * as a plaintext `pa` where `pa[0]=slot0`, `pa[1]=slot1`, `pa[2]=slot2` and
2444+ * `pa[i]=0` for `i>2`.
2445+ **/
23822446 static PtxtArray readFromJSON (const JsonWrapper& jw, const Context& context);
23832447
2448+ /* *
2449+ * @brief In-place function to deserialize a `PtxtArray` from a JSON stream.
2450+ * @param is Input `std::istream`.
2451+ * @throws IOError if the stream is badly formatted (i.e. it does not contain
2452+ * a valid JSON).
2453+ * @note `this` must be constructed with an appropriate context @b BEFORE
2454+ * calling this function. For example,
2455+ * @code
2456+ * PtxtArray my_pa(context);
2457+ * my_pa.readJSON(std::cin);
2458+ * @endcode
2459+ *
2460+ * The input stream has to contain a valid typed JSON value.\n
2461+ * Each element of the content list will be deserialized as a slot of the type
2462+ * determined by the scheme.\n
2463+ * If the number of tokens in the slot list is less than the number of slots,
2464+ * the remaining slots will be padded by 0.\n
2465+ * For example a slot list '['slot0', 'slot1', 'slot2']' will be deserialized
2466+ * as a plaintext `pa` where `pa[0]=slot0`, `pa[1]=slot1`, `pa[2]=slot2`, and
2467+ * `pa[i]=0` for `i>2`.
2468+ **/
23842469 void readJSON (std::istream& is);
23852470
2471+ /* *
2472+ * @brief In-place function to deserialize a `PtxtArray` from a `JsonWrapper`
2473+ * object.
2474+ * @param jw `JsonWrapper` containing the serialized object.
2475+ * @throws IOError if the `JsonWrapper` object does not contain a valid
2476+ * serialization of a `PtxtArray`.
2477+ * @note `this` must be constructed with an appropriate context @b BEFORE
2478+ * calling this function. For example,
2479+ * @code
2480+ * PtxtArray my_pa(context);
2481+ * my_pa.readJSON(...);
2482+ * @endcode
2483+ *
2484+ * The `JsonWrapper` must contain a valid `PtxtArray` serialization.\n
2485+ * Each element of the content list will be deserialized as a slot of the
2486+ * type determined by the scheme.\n
2487+ * If the number of tokens in the slot list is less than the number of slots,
2488+ * the remaining slots will be padded by 0.\n
2489+ * For example a slot list '['slot0', 'slot1', 'slot2']' will be deserialized
2490+ * as a plaintext `pa` where `pa[0]=slot0`, `pa[1]=slot1`, `pa[2]=slot2` and
2491+ * `pa[i]=0` for `i>2`.
2492+ **/
23862493 void readJSON (const JsonWrapper& jw);
23872494
23882495 friend std::istream& operator >>(std::istream& is, PtxtArray& pa);
0 commit comments