-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more documentation on topics and serdes
- Loading branch information
Showing
7 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
hagrid-api/src/main/java/dev/volix/rewinside/odyssey/hagrid/serdes/HagridSerdes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
package dev.volix.rewinside.odyssey.hagrid.serdes; | ||
|
||
/** | ||
* A serdes is a serialization and deserialization instance. | ||
* | ||
* @author Tobias Büser | ||
*/ | ||
public interface HagridSerdes<T> { | ||
|
||
/** | ||
* @return The class of the type this serdes is handling. | ||
*/ | ||
Class<T> getType(); | ||
|
||
/** | ||
* Serializes the payload to a byte array, so that the bytes | ||
* can be send across the network and later on be put together again. | ||
* | ||
* @param payload The payload to serialize. | ||
* | ||
* @return The byte array | ||
*/ | ||
byte[] serialize(T payload); | ||
|
||
/** | ||
* Deserializes the given {@code data} back to the type class. | ||
* | ||
* @param typeUrl The Java url of the class i.e. {@link Class#getTypeName()} | ||
* @param data The data to be deserialized | ||
* | ||
* @return The instance deserialized out of the {@code data}. Can be null | ||
*/ | ||
T deserialize(String typeUrl, byte[] data); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
hagrid-api/src/main/java/dev/volix/rewinside/odyssey/hagrid/serdes/StringHagridSerdes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.volix.rewinside.odyssey.hagrid.serdes; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* @author Tobias Büser | ||
*/ | ||
public class StringHagridSerdes implements HagridSerdes<String> { | ||
|
||
@Override | ||
public Class<String> getType() { | ||
return String.class; | ||
} | ||
|
||
@Override | ||
public byte[] serialize(final String payload) { | ||
return payload.getBytes(StandardCharsets.UTF_8); | ||
} | ||
|
||
@Override | ||
public String deserialize(final String typeUrl, final byte[] data) { | ||
return new String(data, StandardCharsets.UTF_8); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
hagrid-api/src/main/java/dev/volix/rewinside/odyssey/hagrid/topic/TopicProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters