Added array length parameter in json
This commit is contained in:
+7
-15
@@ -3,10 +3,8 @@ package proto
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"unicode"
|
||||
)
|
||||
@@ -27,8 +25,9 @@ type ProtoMessage struct {
|
||||
}
|
||||
|
||||
type ProtoMessagePayload struct {
|
||||
Name string `json:"name"`
|
||||
DataType string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
DataType string `json:"type"`
|
||||
ArrayLength int `json:"array,omitempty"`
|
||||
}
|
||||
|
||||
type Proto struct {
|
||||
@@ -98,16 +97,6 @@ func CreateCStyle(proto *Proto) (string, error) {
|
||||
payloads = append(payloads, tmp)
|
||||
}
|
||||
|
||||
for _, payload := range payloads {
|
||||
for i, entry := range payload.Entries {
|
||||
in := strings.Index(entry.DataType, "[")
|
||||
if in > 0 {
|
||||
payload.Entries[i].Name = fmt.Sprintf("%s%s", payload.Entries[i].Name, payload.Entries[i].DataType[in:])
|
||||
payload.Entries[i].DataType = payload.Entries[i].DataType[:in]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var data = CStyleData{
|
||||
CenumPCTOESP: Cenum{
|
||||
EnumName: "PC_TO_ESP_MESSAGE_IDS",
|
||||
@@ -123,7 +112,10 @@ func CreateCStyle(proto *Proto) (string, error) {
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
tmpl.ExecuteTemplate(&buf, "cpart", data)
|
||||
err = tmpl.ExecuteTemplate(&buf, "cpart", data)
|
||||
if err != nil {
|
||||
log.Printf("Error Rendering template: %v", err)
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user