Custom External-Server Protocol
Introduction
ExternalMessage is the default unified protocol for user-server interaction.
By default, users (game clients) interact through ExternalMessage when sending requests.
If there are no special needs, using default ExternalMessage is recommended.
Unused fields in Protocol Buffers are efficiently handled, so bytes are used only as needed.
ExternalMessage is a framework-provided unified external interaction protocol and the default recommended approach.
Note that this is a default recommendation, not the only option. Developers can customize this part.
In other words, you can interact externally using your own unified protocol instead of ExternalMessage.
For example, if you are building an IoT-related or other project and want to simplify external protocol so it only contains route and business object,
you can use the following MyExternalMessage to replace default ExternalMessage.
syntax = "proto3";
package com.your.message;
message MyExternalMessage {
int32 cmd_merge = 1;
bytes data = 2;
}
How to Extend
- code 4~9:
MyExternalMessage, custom unified protocol. - code 11~21:
MyCommunicationMessageCodec, codec for custom unified protocol.
@Getter
@Setter
@ProtobufClass
public final class MyExternalMessage extends AbstractCommunicationMessage {
@Protobuf(fieldType = FieldType.INT32, order = 1)
int cmdMerge;
@Protobuf(fieldType = FieldType.BYTES, order = 2)
byte[] data;
}
public final class MyCommunicationMessageCodec implements CommunicationMessageCodec {
@Override
public CommunicationMessage createCommunicationMessage() {
return new MyExternalMessage();
}
@Override
public CommunicationMessage decode(byte[] bytes) {
return DataCodecKit.decode(bytes, MyExternalMessage.class);
}
}
Setting
class OneApplication {
static void main() {
CommunicationMessageKit.communicationMessageCodec = new MyCommunicationMessageCodec();
...
new RunOne()
...
.startup();
}
}