diff --git a/src/com/uulm/marvelous/gamelibrary/json/JSON.java b/src/com/uulm/marvelous/gamelibrary/json/JSON.java new file mode 100644 index 0000000..fe05070 --- /dev/null +++ b/src/com/uulm/marvelous/gamelibrary/json/JSON.java @@ -0,0 +1,25 @@ +package com.uulm.marvelous.gamelibrary.json; + +import jdk.jshell.spi.ExecutionControl; + +/** Contains JSON encoding and decoding. + */ +public class JSON { + /** Deserializes an incoming network message into a {@link MessageStructure}. + * @param input The JSON to deserialize. + * @return The parsed message. + */ + public static MessageStructure[] parse(String input) throws ExecutionControl.NotImplementedException { + //TODO: implement JSON.parse + throw new ExecutionControl.NotImplementedException("JSON.parse is not implemented"); + } + + /** Serializes a {@link MessageStructure} into a JSON string. + * @param input The message to serialize. + * @return The message as JSON. + */ + public static String stringify(MessageStructure input) throws ExecutionControl.NotImplementedException { + //TODO: implement JSON.stringify + throw new ExecutionControl.NotImplementedException("JSON.stringify is not implemented"); + } +} diff --git a/src/com/uulm/marvelous/gamelibrary/json/MessageStructure.java b/src/com/uulm/marvelous/gamelibrary/json/MessageStructure.java new file mode 100644 index 0000000..ae5feb1 --- /dev/null +++ b/src/com/uulm/marvelous/gamelibrary/json/MessageStructure.java @@ -0,0 +1,25 @@ +package com.uulm.marvelous.gamelibrary.json; + +import com.uulm.marvelous.gamelibrary.events.Event; + +import java.util.HashMap; + +/** Represents a message sent between client and server and contains all possible data. + */ +public class MessageStructure { + /** The list of {@link Event}s sent inside the message. + */ + public Event[] events; + + /** The checksum of the current game state at the time the message was sent. + */ + public int checksum; + + /** The type of the custom content sent with the message. + */ + public String customContentType; + + /** The decoded contents of the custom content sent. + */ + public HashMap customContent; +}