type DataType interface {
// GetTypeName returns the original VPP name of the data type, as defined in the VPP API.
GetTypeName() string
-
- // GetCrcString returns the string with CRC checksum of the data type definition (the string represents a hexadecimal number).
- GetCrcString() string
}
// ChannelProvider provides the communication channel with govpp core.
// generateComment writes generated comment for the object into w
func generateComment(ctx *context, w io.Writer, goName string, vppName string, objKind string) {
if objKind == "service" {
- fmt.Fprintf(w, "// %s represents VPP binary API services in %s module.\n", ctx.moduleName, goName)
+ fmt.Fprintf(w, "// %s represents VPP binary API services in %s module.\n", goName, ctx.moduleName)
} else {
fmt.Fprintf(w, "// %s represents VPP binary API %s '%s':\n", goName, objKind, vppName)
}
generateTypeNameGetter(w, name, union.Name)
// generate CRC getter
- generateCrcGetter(w, name, union.CRC)
+ if union.CRC != "" {
+ generateCrcGetter(w, name, union.CRC)
+ }
// generate getters for fields
for _, field := range union.Fields {
generateTypeNameGetter(w, name, typ.Name)
// generate CRC getter
- generateCrcGetter(w, name, typ.CRC)
+ if typ.CRC != "" {
+ generateCrcGetter(w, name, typ.CRC)
+ }
fmt.Fprintln(w)
}
}
} else {
// process all files in specified directory
+ dir, err := filepath.Abs(*inputDir)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "ERROR: invalid input directory: %v\n", err)
+ os.Exit(1)
+ }
files, err := getInputFiles(*inputDir)
if err != nil {
- fmt.Fprintf(os.Stderr, "ERROR: code generation failed: %v\n", err)
+ fmt.Fprintf(os.Stderr, "ERROR: problem getting files from input directory: %v\n", err)
+ os.Exit(1)
+ } else if len(files) == 0 {
+ fmt.Fprintf(os.Stderr, "ERROR: no input files found in input directory: %v\n", dir)
os.Exit(1)
}
for _, file := range files {
// create output directory
packageDir := filepath.Dir(ctx.outputFile)
- if err := os.MkdirAll(packageDir, 06); err != nil {
+ if err := os.MkdirAll(packageDir, 0775); err != nil {
return fmt.Errorf("creating output dir %s failed: %v", packageDir, err)
}
// write generated code to output file
if !ok {
return nil, fmt.Errorf("union name is %T, not a string", unionNode.At(0).Get())
}
- unionCRC, ok := unionNode.At(unionNode.Len() - 1).At(crcField).Get().(string)
- if !ok {
- return nil, fmt.Errorf("union crc invalid or missing")
+ var unionCRC string
+ if unionNode.At(unionNode.Len()-1).GetType() == jsongo.TypeMap {
+ unionCRC = unionNode.At(unionNode.Len() - 1).At(crcField).Get().(string)
}
union := Union{
CRC: unionCRC,
}
- // loop through union fields, skip first (name) and last (crc)
- for j := 1; j < unionNode.Len()-1; j++ {
+ // loop through union fields, skip first (name)
+ for j := 1; j < unionNode.Len(); j++ {
if unionNode.At(j).GetType() == jsongo.TypeArray {
fieldNode := unionNode.At(j)
if !ok {
return nil, fmt.Errorf("type name is %T, not a string", typeNode.At(0).Get())
}
- typeCRC, ok := typeNode.At(typeNode.Len() - 1).At(crcField).Get().(string)
- if !ok {
- return nil, fmt.Errorf("type crc invalid or missing")
+ var typeCRC string
+ if lastField := typeNode.At(typeNode.Len() - 1); lastField.GetType() == jsongo.TypeMap {
+ typeCRC = lastField.At(crcField).Get().(string)
}
typ := Type{
CRC: typeCRC,
}
- // loop through type fields, skip first (name) and last (crc)
- for j := 1; j < typeNode.Len()-1; j++ {
+ // loop through type fields, skip first (name)
+ for j := 1; j < typeNode.Len(); j++ {
if typeNode.At(j).GetType() == jsongo.TypeArray {
fieldNode := typeNode.At(j)
}
}
-// Service represents services in VPP binary API.
+// Service represents VPP binary API services in acl module.
type Service interface {
DumpACL(ctx context.Context, in *ACLDump) ([]*ACLDetails, error)
DumpACLInterfaceEtypeWhitelist(ctx context.Context, in *ACLInterfaceEtypeWhitelistDump) ([]*ACLInterfaceEtypeWhitelistDetails, error)
}
}
-// Service represents services in VPP binary API.
+// Service represents VPP binary API services in af_packet module.
type Service interface {
DumpAfPacket(ctx context.Context, in *AfPacketDump) ([]*AfPacketDetails, error)
AfPacketCreate(ctx context.Context, in *AfPacketCreate) (*AfPacketCreateReply, error)
}
}
-// Service represents services in VPP binary API.
+// Service represents VPP binary API services in interface module.
type Service interface {
DumpSwInterface(ctx context.Context, in *SwInterfaceDump) ([]*SwInterfaceDetails, error)
DumpSwInterfaceRxPlacement(ctx context.Context, in *SwInterfaceRxPlacementDump) ([]*SwInterfaceRxPlacementDetails, error)
}
}
-// Service represents services in VPP binary API.
+// Service represents VPP binary API services in ip module.
type Service interface {
DumpIP6Fib(ctx context.Context, in *IP6FibDump) ([]*IP6FibDetails, error)
DumpIP6Mfib(ctx context.Context, in *IP6MfibDump) ([]*IP6MfibDetails, error)
}
}
-// Service represents services in VPP binary API.
+// Service represents VPP binary API services in memclnt module.
type Service interface {
APIVersions(ctx context.Context, in *APIVersions) (*APIVersionsReply, error)
GetFirstMsgID(ctx context.Context, in *GetFirstMsgID) (*GetFirstMsgIDReply, error)
}
}
-// Service represents services in VPP binary API.
+// Service represents VPP binary API services in memif module.
type Service interface {
DumpMemif(ctx context.Context, in *MemifDump) ([]*MemifDetails, error)
DumpMemifSocketFilename(ctx context.Context, in *MemifSocketFilenameDump) ([]*MemifSocketFilenameDetails, error)
}
}
-// Service represents services in VPP binary API.
+// Service represents VPP binary API services in vpe module.
type Service interface {
AddNodeNext(ctx context.Context, in *AddNodeNext) (*AddNodeNextReply, error)
Cli(ctx context.Context, in *Cli) (*CliReply, error)