) new JsonSlurper().parseText(json);
+ return postProcess(new JsonSlurper().parseText(json));
}
/** Dumps the given exception, including stack trace, to a string. */
@@ -56,4 +61,129 @@ public static String stackTrace(Throwable t) {
t.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
+
+
+ // == serialization =======================================================
+
+ /*
+ SharedMemory is represented in JSON as
+ {
+ appose_type:shm
+ name:psm_4812f794
+ size:16384
+ }
+
+ where
+ "name" is the unique name of the shared memory segment
+ "size" is the size in bytes.
+ (as required for python shared_memory.SharedMemory constructor)
+
+
+ NDArray is represented in JSON as
+ {
+ appose_type:ndarray
+ shm:{...}
+ dtype:float32
+ shape:[2, 3, 4]
+ }
+
+ where
+ "shm" is the representation of the underlying shared memory segment (as described above)
+ "dtype" is the data type of the array elements
+ "shape" is the array dimensions in C-Order
+ */
+
+ /**
+ * Helper to create a {@link JsonGenerator.Converter}.
+ *
+ * The converter objects of a specified class {@code clz} into a {@code
+ * Map}. The given {@code appose_type} string is put into
+ * the map with key {@code "appose_type"}. The map and value to be converted
+ * are passed to the given {@code BiConsumer} which should serialize the
+ * value into the map somehow.
+ *
+ * @param clz the converter will handle objects of this class (or sub-classes)
+ * @param appose_type the value for key "appose_type" in the returned Map
+ * @param converter accepts a map and a value, and serializes the value into the map somehow.
+ * @return a new converter
+ * @param object type handled by this converter
+ */
+ private static JsonGenerator.Converter convert(final Class clz, final String appose_type, final BiConsumer