Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify struct code generation. Preparation for codegen library migration. #13

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions internal/codegen/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func writeSerializeBody(output *strings.Builder, instructionList []xml.ProtocolI
}

if instructionType == "break" {
output.WriteString("\twriter.AddByte(0xFF)\n")
output.WriteString("\twriter.AddByte(255)\n")
continue
}

Expand Down Expand Up @@ -355,7 +355,11 @@ func writeSerializeBody(output *strings.Builder, instructionList []xml.ProtocolI

typeName, typeSize := getInstructionTypeName(instruction)

output.WriteString("\t// " + instructionName + " : " + instructionType + " : " + *instruction.Type + "\n")
instructionNameComment := instructionName
if len(instructionNameComment) == 0 && instruction.Content != nil {
instructionNameComment = *instruction.Content
}
output.WriteString(fmt.Sprintf("\t// %s : %s : %s\n", instructionNameComment, instructionType, *instruction.Type))

delimited := instruction.Delimited != nil && *instruction.Delimited
trailingDelimiter := instruction.TrailingDelimiter == nil || *instruction.TrailingDelimiter
Expand All @@ -370,7 +374,7 @@ func writeSerializeBody(output *strings.Builder, instructionList []xml.ProtocolI
output.WriteString(fmt.Sprintf("\tfor ndx := 0; ndx < %s; ndx++ {\n\t\t", lenExpr))

if delimited && !trailingDelimiter {
output.WriteString("\t\tif ndx > 0 {\n\t\t\twriter.AddByte(0xFF)\n\t\t}\n\n")
output.WriteString("\t\tif ndx > 0 {\n\t\t\twriter.AddByte(255)\n\t\t}\n\n")
}
}

Expand Down Expand Up @@ -442,7 +446,7 @@ func writeSerializeBody(output *strings.Builder, instructionList []xml.ProtocolI

if instructionType == "array" {
if delimited && trailingDelimiter {
output.WriteString("\t\twriter.AddByte(0xFF)\n")
output.WriteString("\t\twriter.AddByte(255)\n")
}
output.WriteString("\t}\n\n")
}
Expand Down Expand Up @@ -481,7 +485,7 @@ func writeDeserializeBody(output *strings.Builder, instructionList []xml.Protoco
if isChunked {
output.WriteString("\tif err = reader.NextChunk(); err != nil {\n\t\treturn\n\t}\n")
} else {
output.WriteString("\tif breakByte := reader.GetByte(); breakByte != 0xFF {\n")
output.WriteString("\tif breakByte := reader.GetByte(); breakByte != 255 {\n")
output.WriteString("\t\treturn fmt.Errorf(\"missing expected break byte\")\n")
output.WriteString("\t}\n")
}
Expand Down Expand Up @@ -545,7 +549,11 @@ func writeDeserializeBody(output *strings.Builder, instructionList []xml.Protoco

typeName, typeSize := getInstructionTypeName(instruction)

output.WriteString("\t// " + instructionName + " : " + instructionType + " : " + *instruction.Type + "\n")
instructionNameComment := instructionName
if len(instructionNameComment) == 0 && instruction.Content != nil {
instructionNameComment = *instruction.Content
}
output.WriteString(fmt.Sprintf("\t// %s : %s : %s\n", instructionNameComment, instructionType, *instruction.Type))

var lenExpr string
if instructionType == "array" {
Expand Down
8 changes: 4 additions & 4 deletions pkg/eolib/protocol/map/structs_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (s *Emf) Serialize(writer *data.EoWriter) (err error) {
oldSanitizeStrings := writer.SanitizeStrings
defer func() { writer.SanitizeStrings = oldSanitizeStrings }()

// : field : string
// EMF : field : string
if err = writer.AddFixedString("EMF", 3); err != nil {
return
}
Expand Down Expand Up @@ -661,7 +661,7 @@ func (s *Emf) Serialize(writer *data.EoWriter) (err error) {
if err = writer.AddChar(s.RelogY); err != nil {
return
}
// : field : char
// 0 : field : char
if err = writer.AddChar(0); err != nil {
return
}
Expand Down Expand Up @@ -745,7 +745,7 @@ func (s *Emf) Deserialize(reader *data.EoReader) (err error) {
oldIsChunked := reader.IsChunked()
defer func() { reader.SetIsChunked(oldIsChunked) }()

// : field : string
// EMF : field : string
if _, err = reader.GetFixedString(3); err != nil {
return
}
Expand Down Expand Up @@ -792,7 +792,7 @@ func (s *Emf) Deserialize(reader *data.EoReader) (err error) {
s.RelogX = reader.GetChar()
// RelogY : field : char
s.RelogY = reader.GetChar()
// : field : char
// 0 : field : char
reader.GetChar()
// NpcsCount : length : char
s.NpcsCount = reader.GetChar()
Expand Down
Loading