public class ReprUtil
extends java.lang.Object
Typical usage example:
Representation
argument and a getRepresentation() method.
@Represented.
For example, @Represented private Group group.
GroupElement instances are deserialized
by their group), define a restorer in the @Represented annotation.
For example, @Represented(restorer="group") private GroupElement x;.
The restorer can either be another field of your class (like group in the example above),
or another handler, which you'd have to register using
register(RepresentationRestorer, String).
new ReprUtil(this).deserialize(repr);.
getRepresentation(), call ReprUtil.serialize(this);
"bilGroup::getG1", where bilGroup is as above
(another field of the class or something registered) and getG1 is a method that returns a
RepresentationRestorer.
The framework can handle lists, sets, and maps as well.
For example, @Represented(restorer="[group]") handles a list or set of group elements
and @Represented(restorer="String -> [group]") handles a map of strings to lists of group elements.
Check Represented.restorer() for details.
An example including a bilinear pairing:
Suppose your object depends on public parameters (e.g., a publicly known bilinear group bilGroup,
consisting of groups G1, G2, GT).
You'd annotate GroupElement members with @Represented(restorer="G1"), @Represented(restorer="G2"),
@Represented(restorer="GT"), depending on which of the three groups each of them belongs to.
Your constructor would take these public parameters pp and a Representation repr as input
and then call new ReprUtil(this).register(bilGroup).deserialize(repr);.
getRepresentation() would still just call ReprUtil.serialize(this);.
For more information, consult the documentation.
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Object |
instance
Either stores the recreated object during deserialization, or the object to serialize.
|
protected java.util.HashMap<java.lang.String,RepresentationRestorer> |
restorers
Maps representation restorer identifiers to the corresponding
RepresentationRestorer instances. |
| Constructor and Description |
|---|
ReprUtil(java.lang.Object instance)
Create
ReprUtil for a specific target instance. |
| Modifier and Type | Method and Description |
|---|---|
static void |
deserialize(java.lang.Object instance,
Representation repr)
Restores the instance from the given representation, storing the result in the given object.
|
void |
deserialize(Representation repr)
Deserializes the given representation, storing the result in the instance given when
initializing this
ReprUtil. |
protected static org.cryptimeleon.math.serialization.annotations.RepresentationHandler |
getHandler(java.lang.reflect.Type type,
java.lang.String restorerString)
Derives the representation handler for a certain type and restorer string.
|
protected static org.cryptimeleon.math.serialization.annotations.RepresentationHandler |
getHandlerForField(java.lang.reflect.Field field)
Retrieves the representation handler for the given field.
|
protected static org.cryptimeleon.math.serialization.annotations.RepresentationHandler |
getHandlerWithoutRestorerString(java.lang.reflect.Type type)
Derives the representation handler for a certain type and empty restorer string.
|
protected static org.cryptimeleon.math.serialization.annotations.RepresentationHandler |
getHandlerWithRestorerString(java.lang.reflect.Type type,
java.lang.String restorerString)
Derives the representation handler for a certain type and non-empty restorer string.
|
ReprUtil |
register(BilinearGroup bilinearGroup)
Registers \(\mathbb{G}_1\), \(\mathbb{G}_2\) and \(\mathbb{G}_T\) from the given bilinear group
as restorers with names
"G1", "G2" and "GT", respectively. |
ReprUtil |
register(BilinearMap bilinearMap)
Registers \(\mathbb{G}_1\), \(\mathbb{G}_2\) and \(\mathbb{G}_T\) from the given bilinear map
as restorers with names
"G1", "G2" and "GT", respectively. |
ReprUtil |
register(java.util.function.Function<? super Representation,?> restorer,
java.lang.String name)
Register a custom restorer function, which takes a
Representation and recreates the object. |
ReprUtil |
register(RepresentationRestorer restorer,
java.lang.String name)
Register a representation restorer using the given name.
|
Representation |
serialize()
Represents the the instance given when initializing this
ReprUtil as a Representation. |
static Representation |
serialize(java.lang.Object instance)
Represents the given instance as a
Representation. |
protected java.util.HashMap<java.lang.String,RepresentationRestorer> restorers
RepresentationRestorer instances.
Used to help with deserialization of fields that need a representation restorer to be deserialized.
protected java.lang.Object instance
public ReprUtil(java.lang.Object instance)
ReprUtil for a specific target instance.
For deserialization, the target instance will be filled with field values from the deserialized representation. For serialization, the target instance will be used to create the representation.
public ReprUtil register(RepresentationRestorer restorer, java.lang.String name)
Annotate the fields that should use this restorer with @Represented(restorer = "name").
restorer - a class that knows how to restore values from Representation
(e.g., a Group knows how to restore its GroupElements)name - the name for this restorer (same as in the @Represented annotation)public ReprUtil register(BilinearGroup bilinearGroup)
"G1", "G2" and "GT", respectively.bilinearGroup - the bilinear group to register restorers forpublic ReprUtil register(BilinearMap bilinearMap)
"G1", "G2" and "GT", respectively.bilinearMap - the bilinear map to register restorers forpublic ReprUtil register(java.util.function.Function<? super Representation,?> restorer, java.lang.String name)
Representation and recreates the object.
Annotate the field that should use this with @Represented(restorer = "name").
You should usually not need this.
Instead, use register(RepresentationRestorer, String) to register a RepresentationRestorer.
restorer - a function that takes in a Representation and restores the corresponding object.name - the name for this restorer function (same as in the @Represented annotation)public Representation serialize()
ReprUtil as a Representation.public static Representation serialize(java.lang.Object instance)
Representation.instance - the object to serializepublic static void deserialize(java.lang.Object instance,
Representation repr)
For more control over the deserialization process, e.g. if using custom representation restorers,
use new ReprUtil(this).register(...).deserialize(repr) instead.
instance - the object whose attribute values to restorerepr - the representation from which to restore the objectpublic void deserialize(Representation repr)
ReprUtil.repr - the representation to deserializeprotected static org.cryptimeleon.math.serialization.annotations.RepresentationHandler getHandlerForField(java.lang.reflect.Field field)
protected static org.cryptimeleon.math.serialization.annotations.RepresentationHandler getHandler(java.lang.reflect.Type type,
java.lang.String restorerString)
protected static org.cryptimeleon.math.serialization.annotations.RepresentationHandler getHandlerWithRestorerString(java.lang.reflect.Type type,
java.lang.String restorerString)
protected static org.cryptimeleon.math.serialization.annotations.RepresentationHandler getHandlerWithoutRestorerString(java.lang.reflect.Type type)