You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sd...@apache.org on 2022/07/01 11:16:40 UTC
[ignite-3] branch new-marshaller created (now f580edc57)
This is an automated email from the ASF dual-hosted git repository.
sdanilov pushed a change to branch new-marshaller
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
at f580edc57 New marshaller test
This branch includes the following new commits:
new f580edc57 New marshaller test
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[ignite-3] 01/01: New marshaller test
Posted by sd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sdanilov pushed a commit to branch new-marshaller
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit f580edc5739790dbb876d32d5005363a90d8cfed
Author: Semyon Danilov <sa...@yandex.ru>
AuthorDate: Fri Jul 1 15:15:27 2022 +0400
New marshaller test
---
.../ignite/raft/jraft/util/JDKMarshaller.java | 39 ++++++++++++++++++++++
.../apache/ignite/raft/jraft/util/Marshaller.java | 2 +-
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/JDKMarshaller.java b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/JDKMarshaller.java
index 1556ddc68..7cb8f1b07 100644
--- a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/JDKMarshaller.java
+++ b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/JDKMarshaller.java
@@ -20,6 +20,12 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import org.apache.ignite.internal.network.serialization.ClassDescriptorFactory;
+import org.apache.ignite.internal.network.serialization.ClassDescriptorRegistry;
+import org.apache.ignite.internal.network.serialization.marshal.DefaultUserObjectMarshaller;
+import org.apache.ignite.internal.network.serialization.marshal.MarshalException;
+import org.apache.ignite.internal.network.serialization.marshal.UnmarshalException;
+import org.apache.ignite.internal.network.serialization.marshal.UserObjectMarshaller;
/**
*
@@ -54,4 +60,37 @@ public class JDKMarshaller implements Marshaller {
throw new Error(e);
}
}
+
+ /** */
+ public static class NewMarshaller implements Marshaller {
+ /** */
+ private final ClassDescriptorRegistry registry = new ClassDescriptorRegistry();
+
+ /** */
+ private final ClassDescriptorFactory factory = new ClassDescriptorFactory(registry);
+
+ /** */
+ private final UserObjectMarshaller uom = new DefaultUserObjectMarshaller(registry, factory);
+
+ /** {@inheritDoc} */
+ @Override
+ public byte[] marshall(Object o) {
+ try {
+ return uom.marshal(o).bytes();
+ } catch (MarshalException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public <T> T unmarshall(byte[] raw) {
+ try {
+ return uom.unmarshal(raw, registry);
+ }
+ catch (UnmarshalException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
}
diff --git a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/Marshaller.java b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/Marshaller.java
index b46128b03..d6d42e192 100644
--- a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/Marshaller.java
+++ b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/Marshaller.java
@@ -17,7 +17,7 @@
package org.apache.ignite.raft.jraft.util;
public interface Marshaller {
- public static Marshaller DEFAULT = new JDKMarshaller();
+ public static Marshaller DEFAULT = new JDKMarshaller.NewMarshaller();
byte[] marshall(Object o);