Skip to content

Commit b402ca6

Browse files
Update Main.java
1 parent a5d9d3c commit b402ca6

File tree

1 file changed

+20
-10
lines changed
  • Sample Open Source Implementations/head

1 file changed

+20
-10
lines changed

Sample Open Source Implementations/head/Main.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ public static void main(String[] args)
2222
@Override
2323
public Object[] serialize(Random object)
2424
{
25-
long seed = 0;
2625
try
2726
{
2827
Field f = Random.class.getDeclaredField("seed");
2928
f.setAccessible(true);
30-
seed = ((AtomicLong) f.get(object)).get();
29+
return new Object[] {((AtomicLong) f.get(object)).get()};
3130
}
3231
catch (Exception e)
3332
{
3433
e.printStackTrace();
34+
return new Object[] {-1};
3535
}
36-
return new Object[] {seed};
3736
}
3837

3938
@Override
@@ -49,14 +48,13 @@ public Class<? extends Random> applicableFor()
4948
}
5049
});
5150

52-
File f = new File("./test.srlx");
53-
51+
File f = new File("./lukasko.srlx");
52+
5453
//Sample objects
5554
Random r = new Random();
5655
List<Object> list = new ArrayList<>();
5756
for (int i = 0; i < 10; i++)
5857
list.add(r.nextBoolean() ? r.nextInt(i+1) : r.nextBoolean());
59-
int[] intArr = {1, 2, 3, 4};
6058

6159
HashMap<String, Object> vars = new HashMap<>(); //Variables to serialize
6260
vars.put("yourMom", "is heavier than sun...");
@@ -66,15 +64,27 @@ public Class<? extends Random> applicableFor()
6664

6765
Serializer.globalVariables.put("parent", "father"); //Setting global variables
6866

69-
Serializer.PROTOCOL_REGISTRY.GetProtocolFor(String.class).setActive(false); //Disabling a string protocol. This will force Serializer to serialize string with regular Java Base64 because String implements java.io.Serializable!
70-
Serializer.SerializeTo(f, vars, "145asaa4144akhdgj31hahaXDDLol", r, list, Serializer.Comment("Size of array"), Serializer.Var("arrSize", list.size()), new Bar(), 1, 2.2, 3, 'A', true, false, null, intArr, Serializer.Code("$num")); //Saving to file (serializing)
71-
//This will insert an comment Another way to add variable except Map<String, Object> $ is used to obtain value from variable
67+
double t0 = System.nanoTime(); //Invokation of static members of this class (calling method "println" and obtaining "hello" field as argument!
68+
Serializer.SerializeTo(f, vars, "145asaa4144akhdgj31hahaXDDLol", r, list, Serializer.Comment("Size of array"), Serializer.Var("arrSize", list.size()), new Bar(), 1, 2.2, 3, 'A', true, false, null, Serializer.Code("$num"), new Scope(), Serializer.StaticMember(Main.class, "println", Serializer.StaticMember(Main.class, "hello"))); //Saving to file (serializing)
69+
double t = System.nanoTime(); //This will insert an comment Another way to add variable except Map<String, Object> $ is used to obtain value from variable
70+
System.out.println("Write: " + (t-t0)/1000000);
7271

7372
Serializer.PROTOCOL_REGISTRY.setActivityForAll(true); //Enabling all protocols
73+
t0 = System.nanoTime();
7474
Scope scope = Serializer.LoadFrom(f); //Loading scope with variables and values from file!
75+
t = System.nanoTime();
76+
System.out.println("Read: " + (t-t0)/1000000);
7577

7678
System.out.println(scope.toVarMap());
7779
System.out.println(scope.toValList());
7880
}
79-
81+
82+
//We can invoke static things from SerialX!
83+
84+
public static String hello = "Hello world!";
85+
86+
public static void println(String str)
87+
{
88+
System.out.println(str);
89+
}
8090
}

0 commit comments

Comments
 (0)