toad-java/src/main/java/dev.toad/msg/MessageOwned.java

67 lines
1.3 KiB
Java
Raw Normal View History

2023-04-04 22:36:01 +00:00
package dev.toad.msg;
import java.net.InetSocketAddress;
2023-04-04 22:36:01 +00:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class MessageOwned implements Message {
2023-04-04 22:37:28 +00:00
private final InetSocketAddress source;
private final int id;
private final byte[] token;
private final byte[] payload;
private final MessageCode code;
private final MessageType type;
private final List<MessageOption> opts;
2023-04-04 22:36:01 +00:00
public MessageOwned(MessageRef ref) {
this.id = ref.id();
this.token = ref.token();
this.code = ref.code();
this.type = ref.type();
this.payload = ref.payloadBytes().clone();
this.source = ref.source();
2023-04-04 22:36:01 +00:00
2023-04-04 22:37:28 +00:00
this.opts =
Arrays
.asList(ref.optionRefs())
.stream()
.map(MessageOptionRef::clone)
.collect(Collectors.toList());
2023-04-04 22:36:01 +00:00
}
public InetSocketAddress source() {
return this.source;
}
2023-04-04 22:36:01 +00:00
public int id() {
return this.id;
}
public byte[] token() {
return this.token;
}
public MessageCode code() {
return this.code;
}
public MessageType type() {
return this.type;
}
public List<MessageOption> options() {
return this.opts;
}
public byte[] payloadBytes() {
return this.payload;
}
public String payloadString() {
return new String(this.payload);
}
}