|
7 | 7 | import java.lang.reflect.InvocationTargetException; |
8 | 8 |
|
9 | 9 | /** |
10 | | - * Utility class for serializing plugin messages to JSON format. |
11 | | - * |
12 | | - * @since 1.0.0 |
| 10 | + * Utility class for serializing ModAPI messages to JSON format. |
13 | 11 | */ |
14 | | -public final class PluginMessageUtility { |
| 12 | +public final class ModAPIUtility { |
15 | 13 |
|
16 | | - private PluginMessageUtility() { |
| 14 | + private ModAPIUtility() { |
17 | 15 | // Prevent instantiation. |
18 | 16 | } |
19 | 17 |
|
20 | 18 | /** |
21 | | - * Serializes a protobuf message to a JSON string, |
| 19 | + * Serializes a Protocol Message to a JSON string, |
22 | 20 | * including the packet ID for identification on the receiving end. |
23 | 21 | * |
24 | | - * @param message the protobuf message to serialize |
25 | | - * @return the serialized JSON string with packet ID |
| 22 | + * @param message the Protocol Message to serialize |
| 23 | + * @return the serialized JSON string with its packet ID included |
26 | 24 | * @throws InvalidProtocolBufferException if serialization fails |
27 | 25 | */ |
28 | 26 | public static String serializeMessage(final Message message) throws InvalidProtocolBufferException { |
29 | 27 | final String json = JsonFormat.printer().print(message); |
30 | 28 | final JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject(); |
31 | | - jsonObject.add("packet_id", new JsonPrimitive(PluginMessages.getMessageId(message.getClass()))); |
| 29 | + jsonObject.add("packet_id", new JsonPrimitive(ModAPIMessages.getMessageId(message.getClass()))); |
32 | 30 | return jsonObject.toString(); |
33 | 31 | } |
34 | 32 |
|
35 | 33 | /** |
36 | | - * Deserializes a JSON string back into a protobuf message of the specified class. |
| 34 | + * Deserializes a JSON string back into a Protocol Message of the specified class. |
37 | 35 | * |
38 | 36 | * @param json the JSON string to deserialize |
39 | | - * @param clazz the class of the protobuf message to deserialize into |
40 | | - * @param <T> the type of the protobuf message |
41 | | - * @return the deserialized protobuf message |
| 37 | + * @param clazz the class of the Protocol Message to deserialize into |
| 38 | + * @param <T> the type of the Protocol Message |
| 39 | + * @return the deserialized Protocol Message |
42 | 40 | * @throws InvalidProtocolBufferException if deserialization fails |
43 | 41 | * @throws JsonSyntaxException if the JSON is not properly formatted |
44 | 42 | * @throws IllegalStateException if the JSON does not contain a valid packet ID |
45 | | - * @throws RuntimeException if reflection fails |
| 43 | + * @throws RuntimeException if reflection fails to create a new builder instance |
46 | 44 | * @throws ClassCastException if the built message is not of the expected type |
47 | 45 | */ |
48 | 46 | public static <T extends Message> T deserializeMessage(final String json, final Class<T> clazz) throws InvalidProtocolBufferException { |
|
0 commit comments