Package net.carcdr.yhocuspocus.redis
Class MessageCodec
java.lang.Object
net.carcdr.yhocuspocus.redis.MessageCodec
Encodes and decodes Redis messages with instance ID prefix.
Message format:
+----------------+------------------+--------------+ | instanceIdLen | instanceId | payload | | (4 bytes) | (variable) | (variable) | +----------------+------------------+--------------+
The instance ID prefix allows receivers to filter out messages that originated from the same instance.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA decoded message containing instance ID and payload. -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageCodec.DecodedMessagedecode(byte[] message) Decodes a message, extracting the instance ID.static byte[]Encodes a message with instance ID prefix.
-
Method Details
-
encode
Encodes a message with instance ID prefix.- Parameters:
instanceId- the originating instance IDpayload- the message payload- Returns:
- the encoded message
-
decode
Decodes a message, extracting the instance ID.- Parameters:
message- the encoded message- Returns:
- the decoded message, or null if message is invalid
-