ys.artifact-network.1.0.0.source-code.struct.btl Maven / Gradle / Ivy
package ${packageName}.structs;
import org.artifact.core.context.bytebuf.IByteBuff;
import lombok.Data;
<%
var extends = false;
var extendConstant = "";
if(strutil.isNotBlank(struct.extendsName)){
extends = true;
extendConstant = "extends " + struct.extendsName;
}else{
extends = false;
extendConstant = "implements ISerializable<"+struct.structName+">";
}
%>
<%if(!extends){%>
import org.artifact.core.lang.ISerializable;
<%}%>
@Data
/**
* ${struct.remark}
*/
public class ${struct.structName} ${extendConstant}{
<%for(field in struct.fields){%>
/** ${field.key.remark} */
<%if(strutil.startWith(field.value.type,"java.util.Map")){%>
private ${field.value.intact} ${field.key.name} = new java.util.HashMap<>();
<%}else if(strutil.startWith(field.value.type,"java.util.List")){%>
private ${field.value.intact} ${field.key.name} = new java.util.ArrayList<>();
<%}else{%>
private ${field.value.intact} ${field.key.name};
<%}%>
<%}%>
@Override
public IByteBuff toByteBuff(IByteBuff buff) {
<%if(extends){%>
super.toByteBuff(buff);
<%}%>
<%
for(field in struct.fields){
var v = "";
select(field.value.type){
case "short","java.lang.Short":
v = "buff.writeShort";
case "int","java.lang.Integer":
v = "buff.writeInt";
case "long","java.lang.Long":
v = "buff.writeLong";
case "float","java.lang.Float":
v = "buff.writeFloat";
case "double","java.lang.Double":
v = "buff.writeDouble";
case "String","java.lang.String":
v = "buff.writeString";
case "boolean","java.lang.Boolean":
v = "buff.writeBoolean";
case "map","java.util.Map":
v = "buff.writeMap";
case "list","java.util.List":
v = "buff.writeCollection";
default:
v = "buff.writeObject";
}
%>
${v}(this.${field.key.name});
<%}%>
return buff;
}
@Override
public ${struct.structName} forByteBuff(IByteBuff buff) {
<%if(extends){%>
super.forByteBuff(buff);
<%}%>
<%
for(field in struct.fields){
var v = "";
select(field.value.type){
case "short","java.lang.Short":
v = "buff.readShort()";
case "int","java.lang.Integer":
v = "buff.readInt()";
case "long","java.lang.Long":
v = "buff.readLong()";
case "float","java.lang.Float":
v = "buff.readFloat()";
case "double","java.lang.Double":
v = "buff.readDouble()";
case "String","java.lang.String":
v = "buff.readString()";
case "boolean","java.lang.Boolean":
v = "buff.readBoolean()";
case "map","java.util.":
v = "buff.readMap(null)";
case "list","java.util.List":
v = "buff.readCollection()";
default:
v = "("+field.value.type+")buff.readObject()";
}
%>
this.${field.key.name} = ${v};
<%}%>
return this;
}
}