All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minestom.server.crypto.SignedMessageBody Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
package net.minestom.server.crypto;

import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.NetworkBufferTemplate;
import org.jetbrains.annotations.NotNull;

import java.time.Instant;

public final class SignedMessageBody {

    public record Packed(@NotNull String content, @NotNull Instant timeStamp, long salt,
                         LastSeenMessages.@NotNull Packed lastSeen) {
        public Packed {
            if (content.length() > MessageSignature.SIGNATURE_BYTE_LENGTH) {
                throw new IllegalArgumentException("Message content too long");
            }
        }

        public static final NetworkBuffer.Type SERIALIZER = NetworkBufferTemplate.template(
                NetworkBuffer.STRING, Packed::content,
                NetworkBuffer.INSTANT_MS, Packed::timeStamp,
                NetworkBuffer.LONG, Packed::salt,
                LastSeenMessages.Packed.SERIALIZER, Packed::lastSeen,
                Packed::new
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy