Add VarLong encoder/decoder and integrate into generation pipeline
This commit is contained in:
@@ -301,7 +301,7 @@ func Generate(version string, w io.Writer) (err error) {
|
||||
g := &Generator{Protocol: protocol}
|
||||
|
||||
// These have annoying edge cases that would require me to implement a whole new compareTo parser
|
||||
g.Settings.ReplaceWithTodoNames = []string{"packet_scoreboard_score", "packet_advancements"}
|
||||
g.Settings.ReplaceWithTodoNames = []string{}
|
||||
|
||||
g.File = NewFile("v" + strings.ReplaceAll(version, ".", "_"))
|
||||
AppendDecl(g.File, Import("encoding/binary", "io", "github.com/admin-else/strom/proto_base", "github.com/admin-else/strom/nbt", "github.com/google/uuid"))
|
||||
|
||||
@@ -507,6 +507,11 @@ func VarIntDecoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s
|
||||
return
|
||||
}
|
||||
|
||||
func VarLongDecoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s []ast.Stmt, err error) {
|
||||
s = Stmts(Assign(Exprs(varToSet, Ident("err")), Exprs(Call(Selector("proto_base", "DecodeVarLong"), Ident("r")))), IfErrNil())
|
||||
return
|
||||
}
|
||||
|
||||
func (g *Generator) RegisterDecoderNatives() {
|
||||
g.DecoderNatives = map[string]FunctionGeneratorFunc{
|
||||
"container": ContainerDecoder,
|
||||
@@ -521,6 +526,7 @@ func (g *Generator) RegisterDecoderNatives() {
|
||||
|
||||
"void": DefaultDecoder,
|
||||
"varint": VarIntDecoder,
|
||||
"varlong": VarLongDecoder,
|
||||
"anonymousNbt": DefaultDecoder,
|
||||
"anonOptionalNbt": DefaultDecoder, // I have no idea what the difference is between these two
|
||||
"UUID": UUIDDecoder,
|
||||
|
||||
@@ -320,6 +320,11 @@ func VarIntEncoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s
|
||||
return
|
||||
}
|
||||
|
||||
func VarLongEncoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s []ast.Stmt, err error) {
|
||||
s = Stmts(Assign121(Ident("err"), Call(Selector("proto_base", "EncodeVarLong"), Ident("w"), varToSet)), IfErrNil())
|
||||
return
|
||||
}
|
||||
|
||||
func (g *Generator) RegisterEncoderNatives() {
|
||||
g.EncoderNatives = map[string]FunctionGeneratorFunc{
|
||||
"container": ContainerEncoder,
|
||||
@@ -333,6 +338,7 @@ func (g *Generator) RegisterEncoderNatives() {
|
||||
|
||||
"void": DefaultEncoder,
|
||||
"varint": VarIntEncoder,
|
||||
"varlong": VarLongEncoder,
|
||||
"anonymousNbt": DefaultEncoder,
|
||||
"anonOptionalNbt": DefaultEncoder, // I have no idea what the difference is between these two
|
||||
"UUID": UUIDEncoder,
|
||||
|
||||
@@ -158,6 +158,7 @@ func (g *Generator) RegisterNatives() {
|
||||
"container": VisitContainerType,
|
||||
"buffer": VisitBufferType,
|
||||
"varint": MakeIdentVisitor("int32"),
|
||||
"varlong": MakeIdentVisitor("int64"),
|
||||
"array": VisitArrayTypeVisitorType,
|
||||
"mapper": MakeIdentVisitor("string"),
|
||||
"native": VisitDontGenerateType,
|
||||
|
||||
Reference in New Issue
Block a user