generate: Fix broken doc comments
This commit is contained in:
parent
f0753c5113
commit
c5e2e0f993
@ -3,6 +3,7 @@ package generate
|
|||||||
import "io"
|
import "io"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "bufio"
|
import "bufio"
|
||||||
|
import "strings"
|
||||||
|
|
||||||
const send =
|
const send =
|
||||||
`// Send sends one message along a transaction.
|
`// Send sends one message along a transaction.
|
||||||
@ -62,7 +63,6 @@ func (this *Protocol) Generate(writer io.Writer, packag string) error {
|
|||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,13 +86,13 @@ func (this *Protocol) receive(out io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Protocol) defineMessage(out io.Writer, message Message) error {
|
func (this *Protocol) defineMessage(out io.Writer, message Message) error {
|
||||||
fmt.Fprintf(out, "// (%d) %s\n", message.Method, message.Doc)
|
fmt.Fprintln(out, comment("//", fmt.Sprintf("(%d) %s\n", message.Method, message.Doc)))
|
||||||
fmt.Fprintf(out, "type Message%s struct {\n", message.Name)
|
fmt.Fprintf(out, "type Message%s struct {\n", message.Name)
|
||||||
for _, field := range message.Fields {
|
for _, field := range message.Fields {
|
||||||
typ, err := this.ResolveType(field.Type)
|
typ, err := this.ResolveType(field.Type)
|
||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
if field.Doc != "" {
|
if field.Doc != "" {
|
||||||
fmt.Fprintf(out, "\t// %s\n", field.Doc)
|
fmt.Fprintf(out, "\t%s\n", comment("\t//", field.Doc))
|
||||||
}
|
}
|
||||||
if field.Optional {
|
if field.Optional {
|
||||||
typ = fmt.Sprintf("hopp.Option[%s]", typ)
|
typ = fmt.Sprintf("hopp.Option[%s]", typ)
|
||||||
@ -246,7 +246,9 @@ func (this *Protocol) unmarshalMessage(out io.Writer, message Message) error {
|
|||||||
fmt.Fprintf(out, "\t\t\tmsg.%s.Set(value)\n", field.Name)
|
fmt.Fprintf(out, "\t\t\tmsg.%s.Set(value)\n", field.Name)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(out, "\t\t\tmsg.%s = value\n", field.Name)
|
fmt.Fprintf(out, "\t\t\tmsg.%s = value\n", field.Name)
|
||||||
fmt.Fprintf(out, "\t\t\tfoundRequired ++\n")
|
if requiredTotal > 0 {
|
||||||
|
fmt.Fprintf(out, "\t\t\tfoundRequired ++\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "\t\t}\n")
|
fmt.Fprintf(out, "\t\t}\n")
|
||||||
@ -288,3 +290,7 @@ func (this *Protocol) unmarshalField(out io.Writer, field Field) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func comment(prefix, text string) string {
|
||||||
|
return prefix + " " + strings.ReplaceAll(strings.TrimSpace(text), "\n", "\n" + prefix + " ")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user