From 20a380d2d687e2340ded8bd35b5fc5a2e2e27f0a Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Tue, 22 Apr 2025 17:35:25 +0800 Subject: [PATCH 1/4] protogen: add field number prop --- internal/protogen/exporter.go | 40 ++-- internal/protogen/field_prop.go | 4 + proto/tableau/protobuf/tableau.proto | 6 + proto/tableaupb/tableau.pb.go | 179 ++++++++++-------- .../conf/default/FieldNumberProp.json | 44 +++++ .../excel__fieldprop__field_prop.proto | 22 +++ .../fieldprop/FieldProp#FieldNumberProp.csv | 5 + 7 files changed, 201 insertions(+), 99 deletions(-) create mode 100644 test/functest/conf/default/FieldNumberProp.json create mode 100644 test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv diff --git a/internal/protogen/exporter.go b/internal/protogen/exporter.go index 47c29f84..b2a06963 100644 --- a/internal/protogen/exporter.go +++ b/internal/protogen/exporter.go @@ -201,9 +201,9 @@ func (x *sheetExporter) exportStruct() error { x.g.P("") // generate the fields depth := 1 - for i, field := range x.ws.Fields { - tagid := i + 1 - if err := x.exportField(depth, tagid, field, x.ws.Name); err != nil { + tagid := 1 + for _, field := range x.ws.Fields { + if err := x.exportField(depth, &tagid, field, x.ws.Name); err != nil { return err } } @@ -263,14 +263,9 @@ func (x *sheetExporter) exportUnion() error { depth := 2 tagid := 1 for _, field := range msgField.Fields { - if err := x.exportField(depth, tagid, field, msgField.Name); err != nil { + if err := x.exportField(depth, &tagid, field, msgField.Name); err != nil { return err } - cross := int(field.GetOptions().GetProp().GetCross()) - if cross < 1 { - cross = 1 - } - tagid += cross } x.g.P(" }") } @@ -292,9 +287,9 @@ func (x *sheetExporter) exportMessager() error { x.g.P("") // generate the fields depth := 1 - for i, field := range x.ws.Fields { - tagid := i + 1 - if err := x.exportField(depth, tagid, field, x.ws.Name); err != nil { + tagid := 1 + for _, field := range x.ws.Fields { + if err := x.exportField(depth, &tagid, field, x.ws.Name); err != nil { return err } } @@ -305,7 +300,7 @@ func (x *sheetExporter) exportMessager() error { return nil } -func (x *sheetExporter) exportField(depth int, tagid int, field *internalpb.Field, prefix string) error { +func (x *sheetExporter) exportField(depth int, tagid *int, field *internalpb.Field, prefix string) error { label := "" if x.ws.GetOptions().GetFieldPresence() && types.IsScalarType(field.FullType) && @@ -316,7 +311,18 @@ func (x *sheetExporter) exportField(depth int, tagid int, field *internalpb.Fiel if field.Note != "" { note = " // " + field.Note } - x.g.P(printer.Indent(depth), label, field.FullType, " ", field.Name, " = ", tagid, " ", genFieldOptionsString(field.Options), ";", note) + var number int + if field.Options.GetProp().GetNumber() != 0 { + number = int(field.Options.GetProp().GetNumber()) + } else { + number = *tagid + cross := int(field.GetOptions().GetProp().GetCross()) + if cross < 1 { + cross = 1 + } + *tagid += cross + } + x.g.P(printer.Indent(depth), label, field.FullType, " ", field.Name, " = ", number, " ", genFieldOptionsString(field.Options), ";", note) typeName := field.Type fullTypeName := field.FullType @@ -365,9 +371,9 @@ func (x *sheetExporter) exportField(depth int, tagid int, field *internalpb.Fiel // x.g.P("") x.g.P(printer.Indent(depth), "message ", typeName, " {") - for i, f := range field.Fields { - tagid := i + 1 - if err := x.exportField(depth+1, tagid, f, nestedMsgName); err != nil { + tid := 1 + for _, f := range field.Fields { + if err := x.exportField(depth+1, &tid, f, nestedMsgName); err != nil { return err } } diff --git a/internal/protogen/field_prop.go b/internal/protogen/field_prop.go index a6228fd6..9a99df65 100644 --- a/internal/protogen/field_prop.go +++ b/internal/protogen/field_prop.go @@ -26,6 +26,7 @@ func ExtractMapFieldProp(prop *tableaupb.FieldProp) *tableaupb.FieldProp { Patch: prop.Patch, Sep: prop.Sep, Subsep: prop.Subsep, + Number: prop.Number, } if IsEmptyFieldProp(p) { return nil @@ -50,6 +51,7 @@ func ExtractListFieldProp(prop *tableaupb.FieldProp, isScalarList bool) *tableau Sep: prop.Sep, Subsep: prop.Subsep, Cross: prop.Cross, + Number: prop.Number, } if isScalarList { p.Range = prop.Range @@ -75,6 +77,7 @@ func ExtractStructFieldProp(prop *tableaupb.FieldProp) *tableaupb.FieldProp { Patch: prop.Patch, Sep: prop.Sep, Subsep: prop.Subsep, + Number: prop.Number, } if IsEmptyFieldProp(p) { return nil @@ -99,6 +102,7 @@ func ExtractScalarFieldProp(prop *tableaupb.FieldProp) *tableaupb.FieldProp { Optional: prop.Optional, Patch: prop.Patch, Pattern: prop.Pattern, + Number: prop.Number, } if IsEmptyFieldProp(p) { return nil diff --git a/proto/tableau/protobuf/tableau.proto b/proto/tableau/protobuf/tableau.proto index 9b679846..0461a974 100644 --- a/proto/tableau/protobuf/tableau.proto +++ b/proto/tableau/protobuf/tableau.proto @@ -344,6 +344,12 @@ message FieldProp { // // TODO: use cases for more field types. string pattern = 16; + // Specify number of this field. + // All fields with number unspecified will use a sequence starting from 1 by default, + // and users should guarantee this number do not conflict with the default sequence. + // + // For tables, assigning number to a cross cell map/list/struct field also works on its 1st sub-field. + int32 number = 17; } // Layout of list and map. diff --git a/proto/tableaupb/tableau.pb.go b/proto/tableaupb/tableau.pb.go index 6c3d413a..e55c1436 100644 --- a/proto/tableaupb/tableau.pb.go +++ b/proto/tableaupb/tableau.pb.go @@ -1290,6 +1290,12 @@ type FieldProp struct { // // TODO: use cases for more field types. Pattern string `protobuf:"bytes,16,opt,name=pattern,proto3" json:"pattern,omitempty"` + // Specify number of this field. + // All fields with number unspecified will use a sequence starting from 1 by default, + // and users should guarantee this number do not conflict with the default sequence. + // + // For tables, assigning number to a cross cell map/list/struct field also works on its 1st sub-field. + Number int32 `protobuf:"varint,17,opt,name=number,proto3" json:"number,omitempty"` } func (x *FieldProp) Reset() { @@ -1436,6 +1442,13 @@ func (x *FieldProp) GetPattern() string { return "" } +func (x *FieldProp) GetNumber() int32 { + if x != nil { + return x.Number + } + return 0 +} + var file_tableau_protobuf_tableau_proto_extTypes = []protoimpl.ExtensionInfo{ { ExtendedType: (*descriptorpb.FileOptions)(nil), @@ -1662,7 +1675,7 @@ var file_tableau_protobuf_tableau_proto_rawDesc = []byte{ 0x61, 0x75, 0x2e, 0x53, 0x70, 0x61, 0x6e, 0x52, 0x04, 0x73, 0x70, 0x61, 0x6e, 0x12, 0x26, 0x0a, 0x04, 0x70, 0x72, 0x6f, 0x70, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x50, 0x72, 0x6f, 0x70, 0x52, - 0x04, 0x70, 0x72, 0x6f, 0x70, 0x22, 0xc7, 0x03, 0x0a, 0x09, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x50, + 0x04, 0x70, 0x72, 0x6f, 0x70, 0x22, 0xdf, 0x03, 0x0a, 0x09, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x50, 0x72, 0x6f, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x1b, 0x0a, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x48, 0x00, 0x52, 0x06, 0x75, 0x6e, 0x69, @@ -1689,88 +1702,90 @@ var file_tableau_protobuf_tableau_proto_rawDesc = []byte{ 0x06, 0x73, 0x75, 0x62, 0x73, 0x65, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x75, 0x6e, 0x69, 0x71, - 0x75, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x2a, - 0x5b, 0x0a, 0x06, 0x4c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x12, 0x12, 0x0a, 0x0e, 0x4c, 0x41, 0x59, - 0x4f, 0x55, 0x54, 0x5f, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x13, 0x0a, - 0x0f, 0x4c, 0x41, 0x59, 0x4f, 0x55, 0x54, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x49, 0x43, 0x41, 0x4c, - 0x10, 0x01, 0x12, 0x15, 0x0a, 0x11, 0x4c, 0x41, 0x59, 0x4f, 0x55, 0x54, 0x5f, 0x48, 0x4f, 0x52, - 0x49, 0x5a, 0x4f, 0x4e, 0x54, 0x41, 0x4c, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x4c, 0x41, 0x59, - 0x4f, 0x55, 0x54, 0x5f, 0x49, 0x4e, 0x43, 0x45, 0x4c, 0x4c, 0x10, 0x03, 0x2a, 0x42, 0x0a, 0x04, - 0x53, 0x70, 0x61, 0x6e, 0x12, 0x10, 0x0a, 0x0c, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x44, 0x45, 0x46, - 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x13, 0x0a, 0x0f, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x43, - 0x52, 0x4f, 0x53, 0x53, 0x5f, 0x43, 0x45, 0x4c, 0x4c, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x53, - 0x50, 0x41, 0x4e, 0x5f, 0x49, 0x4e, 0x4e, 0x45, 0x52, 0x5f, 0x43, 0x45, 0x4c, 0x4c, 0x10, 0x02, - 0x2a, 0xcb, 0x01, 0x0a, 0x04, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x0c, 0x4d, 0x4f, 0x44, - 0x45, 0x5f, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x12, 0x0a, 0x0e, 0x4d, - 0x4f, 0x44, 0x45, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x01, 0x12, - 0x18, 0x0a, 0x14, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x54, 0x59, 0x50, - 0x45, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x4d, 0x4f, 0x44, - 0x45, 0x5f, 0x53, 0x54, 0x52, 0x55, 0x43, 0x54, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x03, 0x12, - 0x1a, 0x0a, 0x16, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x53, 0x54, 0x52, 0x55, 0x43, 0x54, 0x5f, 0x54, - 0x59, 0x50, 0x45, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x10, 0x04, 0x12, 0x13, 0x0a, 0x0f, 0x4d, - 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x4e, 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x05, - 0x12, 0x19, 0x0a, 0x15, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x4e, 0x49, 0x4f, 0x4e, 0x5f, 0x54, - 0x59, 0x50, 0x45, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x10, 0x06, 0x12, 0x0f, 0x0a, 0x0b, 0x4d, - 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x45, 0x5f, 0x43, 0x53, 0x56, 0x10, 0x0a, 0x12, 0x10, 0x0a, 0x0c, - 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x45, 0x5f, 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x0b, 0x2a, 0x36, - 0x0a, 0x04, 0x46, 0x6f, 0x72, 0x6d, 0x12, 0x10, 0x0a, 0x0c, 0x46, 0x4f, 0x52, 0x4d, 0x5f, 0x44, - 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x46, 0x4f, 0x52, 0x4d, - 0x5f, 0x54, 0x45, 0x58, 0x54, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x46, 0x4f, 0x52, 0x4d, 0x5f, - 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x02, 0x2a, 0x3b, 0x0a, 0x05, 0x50, 0x61, 0x74, 0x63, 0x68, 0x12, - 0x0e, 0x0a, 0x0a, 0x50, 0x41, 0x54, 0x43, 0x48, 0x5f, 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x00, 0x12, - 0x11, 0x0a, 0x0d, 0x50, 0x41, 0x54, 0x43, 0x48, 0x5f, 0x52, 0x45, 0x50, 0x4c, 0x41, 0x43, 0x45, - 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x41, 0x54, 0x43, 0x48, 0x5f, 0x4d, 0x45, 0x52, 0x47, - 0x45, 0x10, 0x02, 0x3a, 0x54, 0x0a, 0x08, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x6f, 0x6f, 0x6b, 0x12, - 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, - 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, - 0x57, 0x6f, 0x72, 0x6b, 0x62, 0x6f, 0x6f, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, - 0x08, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x6f, 0x6f, 0x6b, 0x3a, 0x5a, 0x0a, 0x09, 0x77, 0x6f, 0x72, - 0x6b, 0x73, 0x68, 0x65, 0x65, 0x74, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x19, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x68, - 0x65, 0x65, 0x74, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x09, 0x77, 0x6f, 0x72, 0x6b, - 0x73, 0x68, 0x65, 0x65, 0x74, 0x3a, 0x51, 0x0a, 0x06, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, - 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x18, 0xd1, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, - 0x61, 0x75, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x52, 0x06, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x3a, 0x4e, 0x0a, 0x05, 0x75, 0x6e, 0x69, 0x6f, - 0x6e, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x18, 0xd2, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x61, 0x62, - 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x52, 0x05, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x3a, 0x4c, 0x0a, 0x05, 0x66, 0x69, 0x65, 0x6c, - 0x64, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, - 0x61, 0x75, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, - 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x3a, 0x4a, 0x0a, 0x05, 0x65, 0x74, 0x79, 0x70, 0x65, 0x12, - 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, - 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, - 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x05, 0x65, 0x74, 0x79, - 0x70, 0x65, 0x3a, 0x56, 0x0a, 0x06, 0x65, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x21, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, - 0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, + 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x18, 0x11, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x42, + 0x09, 0x0a, 0x07, 0x5f, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x73, + 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x2a, 0x5b, 0x0a, 0x06, 0x4c, 0x61, 0x79, 0x6f, 0x75, + 0x74, 0x12, 0x12, 0x0a, 0x0e, 0x4c, 0x41, 0x59, 0x4f, 0x55, 0x54, 0x5f, 0x44, 0x45, 0x46, 0x41, + 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x13, 0x0a, 0x0f, 0x4c, 0x41, 0x59, 0x4f, 0x55, 0x54, 0x5f, + 0x56, 0x45, 0x52, 0x54, 0x49, 0x43, 0x41, 0x4c, 0x10, 0x01, 0x12, 0x15, 0x0a, 0x11, 0x4c, 0x41, + 0x59, 0x4f, 0x55, 0x54, 0x5f, 0x48, 0x4f, 0x52, 0x49, 0x5a, 0x4f, 0x4e, 0x54, 0x41, 0x4c, 0x10, + 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x4c, 0x41, 0x59, 0x4f, 0x55, 0x54, 0x5f, 0x49, 0x4e, 0x43, 0x45, + 0x4c, 0x4c, 0x10, 0x03, 0x2a, 0x42, 0x0a, 0x04, 0x53, 0x70, 0x61, 0x6e, 0x12, 0x10, 0x0a, 0x0c, + 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x13, + 0x0a, 0x0f, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x43, 0x52, 0x4f, 0x53, 0x53, 0x5f, 0x43, 0x45, 0x4c, + 0x4c, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x49, 0x4e, 0x4e, 0x45, + 0x52, 0x5f, 0x43, 0x45, 0x4c, 0x4c, 0x10, 0x02, 0x2a, 0xcb, 0x01, 0x0a, 0x04, 0x4d, 0x6f, 0x64, + 0x65, 0x12, 0x10, 0x0a, 0x0c, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, + 0x54, 0x10, 0x00, 0x12, 0x12, 0x0a, 0x0e, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x45, 0x4e, 0x55, 0x4d, + 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x4f, 0x44, 0x45, 0x5f, + 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x10, + 0x02, 0x12, 0x14, 0x0a, 0x10, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x53, 0x54, 0x52, 0x55, 0x43, 0x54, + 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x03, 0x12, 0x1a, 0x0a, 0x16, 0x4d, 0x4f, 0x44, 0x45, 0x5f, + 0x53, 0x54, 0x52, 0x55, 0x43, 0x54, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x4d, 0x55, 0x4c, 0x54, + 0x49, 0x10, 0x04, 0x12, 0x13, 0x0a, 0x0f, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x4e, 0x49, 0x4f, + 0x4e, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x05, 0x12, 0x19, 0x0a, 0x15, 0x4d, 0x4f, 0x44, 0x45, + 0x5f, 0x55, 0x4e, 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x4d, 0x55, 0x4c, 0x54, + 0x49, 0x10, 0x06, 0x12, 0x0f, 0x0a, 0x0b, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x45, 0x5f, 0x43, + 0x53, 0x56, 0x10, 0x0a, 0x12, 0x10, 0x0a, 0x0c, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x45, 0x5f, + 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x0b, 0x2a, 0x36, 0x0a, 0x04, 0x46, 0x6f, 0x72, 0x6d, 0x12, 0x10, + 0x0a, 0x0c, 0x46, 0x4f, 0x52, 0x4d, 0x5f, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, + 0x12, 0x0d, 0x0a, 0x09, 0x46, 0x4f, 0x52, 0x4d, 0x5f, 0x54, 0x45, 0x58, 0x54, 0x10, 0x01, 0x12, + 0x0d, 0x0a, 0x09, 0x46, 0x4f, 0x52, 0x4d, 0x5f, 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x02, 0x2a, 0x3b, + 0x0a, 0x05, 0x50, 0x61, 0x74, 0x63, 0x68, 0x12, 0x0e, 0x0a, 0x0a, 0x50, 0x41, 0x54, 0x43, 0x48, + 0x5f, 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x50, 0x41, 0x54, 0x43, 0x48, + 0x5f, 0x52, 0x45, 0x50, 0x4c, 0x41, 0x43, 0x45, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x41, + 0x54, 0x43, 0x48, 0x5f, 0x4d, 0x45, 0x52, 0x47, 0x45, 0x10, 0x02, 0x3a, 0x54, 0x0a, 0x08, 0x77, + 0x6f, 0x72, 0x6b, 0x62, 0x6f, 0x6f, 0x6b, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x57, 0x6f, 0x72, 0x6b, 0x62, 0x6f, 0x6f, 0x6b, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x08, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x6f, 0x6f, + 0x6b, 0x3a, 0x5a, 0x0a, 0x09, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x68, 0x65, 0x65, 0x74, 0x12, 0x1f, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, - 0x75, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x52, 0x06, 0x65, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x4f, 0x0a, 0x05, 0x6f, 0x6e, - 0x65, 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4f, 0x6e, 0x65, 0x6f, 0x66, 0x4f, 0x70, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x61, 0x62, - 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x4f, 0x6e, 0x65, 0x6f, 0x66, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x52, 0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x88, 0x01, 0x01, 0x42, 0x75, 0x0a, 0x14, 0x63, - 0x6f, 0x6d, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x42, 0x0c, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x50, 0x72, 0x6f, 0x74, - 0x6f, 0x50, 0x01, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x69, 0x6f, 0x2f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, - 0x75, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x70, - 0x62, 0xa2, 0x02, 0x03, 0x54, 0x50, 0x42, 0xaa, 0x02, 0x18, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x61, - 0x75, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x61, 0x62, 0x6c, 0x65, - 0x61, 0x75, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x2e, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x68, 0x65, 0x65, 0x74, 0x4f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x52, 0x09, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x68, 0x65, 0x65, 0x74, 0x3a, 0x51, 0x0a, + 0x06, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd1, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x16, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, + 0x74, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x06, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, + 0x3a, 0x4e, 0x0a, 0x05, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd2, 0x86, 0x03, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x55, 0x6e, 0x69, + 0x6f, 0x6e, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x05, 0x75, 0x6e, 0x69, 0x6f, 0x6e, + 0x3a, 0x4c, 0x0a, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, + 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x15, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x3a, 0x4a, + 0x0a, 0x05, 0x65, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x52, 0x05, 0x65, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x56, 0x0a, 0x06, 0x65, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x12, 0x21, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c, 0x75, 0x65, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x19, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x06, 0x65, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x3a, 0x4f, 0x0a, 0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4f, 0x6e, + 0x65, 0x6f, 0x66, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x4f, 0x6e, 0x65, + 0x6f, 0x66, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, + 0x88, 0x01, 0x01, 0x42, 0x75, 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x61, 0x62, 0x6c, 0x65, + 0x61, 0x75, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x42, 0x0c, 0x54, 0x61, 0x62, + 0x6c, 0x65, 0x61, 0x75, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2c, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x69, + 0x6f, 0x2f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x50, 0x42, 0xaa, + 0x02, 0x18, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x61, 0x75, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/test/functest/conf/default/FieldNumberProp.json b/test/functest/conf/default/FieldNumberProp.json new file mode 100644 index 00000000..ba4c7705 --- /dev/null +++ b/test/functest/conf/default/FieldNumberProp.json @@ -0,0 +1,44 @@ +{ + "itemMap": { + "1": { + "id": 1, + "name": "Apple", + "price": 100, + "number": 1, + "decompose": { + "id": 1001, + "num": 10 + }, + "attributeList": [ + { + "id": 90001, + "value": 20 + }, + { + "id": 90002, + "value": 30 + } + ] + }, + "2": { + "id": 2, + "name": "Banana", + "price": 500, + "number": 20, + "decompose": { + "id": 1002, + "num": 20 + }, + "attributeList": [ + { + "id": 90003, + "value": 30 + }, + { + "id": 90004, + "value": 40 + } + ] + } + } +} \ No newline at end of file diff --git a/test/functest/proto/default/excel__fieldprop__field_prop.proto b/test/functest/proto/default/excel__fieldprop__field_prop.proto index 9b2e64d8..172a10c2 100644 --- a/test/functest/proto/default/excel__fieldprop__field_prop.proto +++ b/test/functest/proto/default/excel__fieldprop__field_prop.proto @@ -21,6 +21,28 @@ message EquipConf { } } +message FieldNumberProp { + option (tableau.worksheet) = {name:"FieldNumberProp"}; + + map item_map = 1 [(tableau.field) = {key:"ID" layout:LAYOUT_VERTICAL}]; + message Item { + uint32 id = 1 [(tableau.field) = {name:"ID"}]; + string name = 2 [(tableau.field) = {name:"Name"}]; + int32 price = 10 [(tableau.field) = {name:"Price" prop:{number:10}}]; + int32 number = 3 [(tableau.field) = {name:"Number"}]; + Decompose decompose = 20 [(tableau.field) = {name:"Decompose" prop:{number:20}}]; + message Decompose { + uint32 id = 20 [(tableau.field) = {name:"ID" prop:{number:20}}]; + int32 num = 5 [(tableau.field) = {name:"Num" prop:{number:5}}]; + } + repeated Attribute attribute_list = 30 [(tableau.field) = {name:"Attribute" layout:LAYOUT_HORIZONTAL prop:{number:30}}]; + message Attribute { + uint32 id = 30 [(tableau.field) = {name:"ID" prop:{number:30}}]; + int32 value = 1 [(tableau.field) = {name:"Value"}]; + } + } +} + message FieldPropForm { option (tableau.worksheet) = {name:"FieldPropForm"}; diff --git a/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv b/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv new file mode 100644 index 00000000..813830c8 --- /dev/null +++ b/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv @@ -0,0 +1,5 @@ +ID,Name,Price,Number,DecomposeID,DecomposeNum,Attribute1ID,Attribute1Value,Attribute2ID,Attribute2Value +"map",string,int32|{number:10},int32,{Decompose}uint32|{number:20},int32|{number:5},[Attribute]uint32|{number:30},int32,uint32,int32 +,,,,,,,,, +1,Apple,100,1,1001,10,90001,20,90002,30 +2,Banana,500,20,1002,20,90003,30,90004,40 \ No newline at end of file From c8321fc0f9790863814af2c63159a344376e591a Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Fri, 25 Apr 2025 11:29:44 +0800 Subject: [PATCH 2/4] feat: cr --- internal/protogen/exporter.go | 32 ++++++++++++------- .../fieldprop/FieldProp#FieldNumberProp.csv | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/internal/protogen/exporter.go b/internal/protogen/exporter.go index b2a06963..c39b76d0 100644 --- a/internal/protogen/exporter.go +++ b/internal/protogen/exporter.go @@ -203,7 +203,9 @@ func (x *sheetExporter) exportStruct() error { depth := 1 tagid := 1 for _, field := range x.ws.Fields { - if err := x.exportField(depth, &tagid, field, x.ws.Name); err != nil { + var err error + tagid, err = x.exportField(depth, tagid, field, x.ws.Name) + if err != nil { return err } } @@ -263,7 +265,9 @@ func (x *sheetExporter) exportUnion() error { depth := 2 tagid := 1 for _, field := range msgField.Fields { - if err := x.exportField(depth, &tagid, field, msgField.Name); err != nil { + var err error + tagid, err = x.exportField(depth, tagid, field, msgField.Name) + if err != nil { return err } } @@ -289,7 +293,9 @@ func (x *sheetExporter) exportMessager() error { depth := 1 tagid := 1 for _, field := range x.ws.Fields { - if err := x.exportField(depth, &tagid, field, x.ws.Name); err != nil { + var err error + tagid, err = x.exportField(depth, tagid, field, x.ws.Name) + if err != nil { return err } } @@ -300,7 +306,7 @@ func (x *sheetExporter) exportMessager() error { return nil } -func (x *sheetExporter) exportField(depth int, tagid *int, field *internalpb.Field, prefix string) error { +func (x *sheetExporter) exportField(depth int, tagid int, field *internalpb.Field, prefix string) (int, error) { label := "" if x.ws.GetOptions().GetFieldPresence() && types.IsScalarType(field.FullType) && @@ -315,12 +321,12 @@ func (x *sheetExporter) exportField(depth int, tagid *int, field *internalpb.Fie if field.Options.GetProp().GetNumber() != 0 { number = int(field.Options.GetProp().GetNumber()) } else { - number = *tagid + number = tagid cross := int(field.GetOptions().GetProp().GetCross()) if cross < 1 { cross = 1 } - *tagid += cross + tagid += cross } x.g.P(printer.Indent(depth), label, field.FullType, " ", field.Name, " = ", number, " ", genFieldOptionsString(field.Options), ";", note) @@ -355,16 +361,16 @@ func (x *sheetExporter) exportField(depth int, tagid *int, field *internalpb.Fie if isSameFieldMessageType(field, x.nestedMessages[nestedMsgName]) { // if the nested message is the same as the previous one, // just use the previous one, and don't generate a new one. - return nil + return tagid, nil } case !types.IsScalarType(typeName): if _, ok := x.nestedMessages[nestedMsgName]; ok { // if the nested message has the same name with the previous one, // just use the previous one, and don't generate a new one. - return nil + return tagid, nil } default: - return nil + return tagid, nil } // bookkeeping this nested msessage, so we can check if we can reuse it later. x.nestedMessages[nestedMsgName] = field @@ -373,13 +379,15 @@ func (x *sheetExporter) exportField(depth int, tagid *int, field *internalpb.Fie x.g.P(printer.Indent(depth), "message ", typeName, " {") tid := 1 for _, f := range field.Fields { - if err := x.exportField(depth+1, &tid, f, nestedMsgName); err != nil { - return err + var err error + tid, err = x.exportField(depth+1, tid, f, nestedMsgName) + if err != nil { + return tagid, err } } x.g.P(printer.Indent(depth), "}") } - return nil + return tagid, nil } func genFieldOptionsString(opts *tableaupb.FieldOptions) string { diff --git a/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv b/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv index 813830c8..f5b03168 100644 --- a/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv +++ b/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv @@ -2,4 +2,4 @@ ID,Name,Price,Number,DecomposeID,DecomposeNum,Attribute1ID,Attribute1Value,Attri "map",string,int32|{number:10},int32,{Decompose}uint32|{number:20},int32|{number:5},[Attribute]uint32|{number:30},int32,uint32,int32 ,,,,,,,,, 1,Apple,100,1,1001,10,90001,20,90002,30 -2,Banana,500,20,1002,20,90003,30,90004,40 \ No newline at end of file +2,Banana,500,20,1002,20,90003,30,90004,40 From 9fd30b512d29cacd085884c7db69dccf3f9cdbb5 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Fri, 30 May 2025 17:37:43 +0800 Subject: [PATCH 3/4] feat: cr --- internal/protogen/exporter.go | 98 ++++++++++++------- proto/tableau/protobuf/tableau.proto | 17 ++-- proto/tableaupb/tableau.pb.go | 11 ++- .../conf/default/FieldNumberProp.json | 6 +- .../excel__fieldprop__field_prop.proto | 17 ++-- .../fieldprop/FieldProp#FieldNumberProp.csv | 10 +- 6 files changed, 95 insertions(+), 64 deletions(-) diff --git a/internal/protogen/exporter.go b/internal/protogen/exporter.go index c39b76d0..37cc8eb6 100644 --- a/internal/protogen/exporter.go +++ b/internal/protogen/exporter.go @@ -200,11 +200,9 @@ func (x *sheetExporter) exportStruct() error { x.g.P(" option (tableau.struct) = {", marshalToText(opts), "};") x.g.P("") // generate the fields - depth := 1 - tagid := 1 - for _, field := range x.ws.Fields { - var err error - tagid, err = x.exportField(depth, tagid, field, x.ws.Name) + for i, field := range x.ws.Fields { + tagid := i + 1 + err := x.exportField(1, tagid, field, x.ws.Name) if err != nil { return err } @@ -262,14 +260,16 @@ func (x *sheetExporter) exportUnion() error { } x.g.P(" message ", strings.TrimSpace(msgField.Name), " {") // generate the fields - depth := 2 tagid := 1 for _, field := range msgField.Fields { - var err error - tagid, err = x.exportField(depth, tagid, field, msgField.Name) - if err != nil { + if err := x.exportField(2, tagid, field, msgField.Name); err != nil { return err } + cross := int(field.GetOptions().GetProp().GetCross()) + if cross < 1 { + cross = 1 + } + tagid += cross } x.g.P(" }") } @@ -289,13 +289,12 @@ func (x *sheetExporter) exportMessager() error { x.g.P("message ", x.ws.Name, " {") x.g.P(" option (tableau.worksheet) = {", marshalToText(x.ws.Options), "};") x.g.P("") + // generate the tagids + tagids := genTagids(x.ws.Fields) // generate the fields - depth := 1 - tagid := 1 - for _, field := range x.ws.Fields { - var err error - tagid, err = x.exportField(depth, tagid, field, x.ws.Name) - if err != nil { + for i, field := range x.ws.Fields { + tagid := tagids[i] + if err := x.exportField(1, tagid, field, x.ws.Name); err != nil { return err } } @@ -306,7 +305,7 @@ func (x *sheetExporter) exportMessager() error { return nil } -func (x *sheetExporter) exportField(depth int, tagid int, field *internalpb.Field, prefix string) (int, error) { +func (x *sheetExporter) exportField(depth int, tagid int, field *internalpb.Field, prefix string) error { label := "" if x.ws.GetOptions().GetFieldPresence() && types.IsScalarType(field.FullType) && @@ -317,18 +316,7 @@ func (x *sheetExporter) exportField(depth int, tagid int, field *internalpb.Fiel if field.Note != "" { note = " // " + field.Note } - var number int - if field.Options.GetProp().GetNumber() != 0 { - number = int(field.Options.GetProp().GetNumber()) - } else { - number = tagid - cross := int(field.GetOptions().GetProp().GetCross()) - if cross < 1 { - cross = 1 - } - tagid += cross - } - x.g.P(printer.Indent(depth), label, field.FullType, " ", field.Name, " = ", number, " ", genFieldOptionsString(field.Options), ";", note) + x.g.P(printer.Indent(depth), label, field.FullType, " ", field.Name, " = ", tagid, " ", genFieldOptionsString(field.Options), ";", note) typeName := field.Type fullTypeName := field.FullType @@ -361,33 +349,33 @@ func (x *sheetExporter) exportField(depth int, tagid int, field *internalpb.Fiel if isSameFieldMessageType(field, x.nestedMessages[nestedMsgName]) { // if the nested message is the same as the previous one, // just use the previous one, and don't generate a new one. - return tagid, nil + return nil } case !types.IsScalarType(typeName): if _, ok := x.nestedMessages[nestedMsgName]; ok { // if the nested message has the same name with the previous one, // just use the previous one, and don't generate a new one. - return tagid, nil + return nil } default: - return tagid, nil + return nil } // bookkeeping this nested msessage, so we can check if we can reuse it later. x.nestedMessages[nestedMsgName] = field // x.g.P("") x.g.P(printer.Indent(depth), "message ", typeName, " {") - tid := 1 - for _, f := range field.Fields { - var err error - tid, err = x.exportField(depth+1, tid, f, nestedMsgName) - if err != nil { - return tagid, err + // generate the tagids + tagids := genTagids(field.Fields) + for i, f := range field.Fields { + tagid := tagids[i] + if err := x.exportField(depth+1, tagid, f, nestedMsgName); err != nil { + return err } } x.g.P(printer.Indent(depth), "}") } - return tagid, nil + return nil } func genFieldOptionsString(opts *tableaupb.FieldOptions) string { @@ -396,6 +384,7 @@ func genFieldOptionsString(opts *tableaupb.FieldOptions) string { if opts.Prop != nil { jsonName = opts.Prop.JsonName opts.Prop.JsonName = "" + opts.Prop.Number = 0 // set nil if field prop is empty if IsEmptyFieldProp(opts.Prop) { @@ -438,3 +427,36 @@ func isSameFieldMessageType(left, right *internalpb.Field) bool { } return false } + +func genTagids(fields []*internalpb.Field) []int { + tagids := make([]int, 0, len(fields)) + occupiedTagids := make(map[int]bool, len(fields)) + for i, field := range fields { + if i == 0 { + tagids = append(tagids, 1) + continue + } + number := int(field.Options.GetProp().GetNumber()) + if number > 1 && !occupiedTagids[number] { + tagids = append(tagids, number) + occupiedTagids[number] = true + } else { + tagids = append(tagids, 0) + } + } + autogenTagid := 1 + nextTagid := func() int { + for { + autogenTagid++ + if !occupiedTagids[autogenTagid] { + return autogenTagid + } + } + } + for i, tagid := range tagids { + if tagid == 0 { + tagids[i] = nextTagid() + } + } + return tagids +} diff --git a/proto/tableau/protobuf/tableau.proto b/proto/tableau/protobuf/tableau.proto index 0461a974..e7d24083 100644 --- a/proto/tableau/protobuf/tableau.proto +++ b/proto/tableau/protobuf/tableau.proto @@ -71,9 +71,9 @@ message OneofOptions { message WorkbookOptions { // filename with path, e.g.: "relative/path/BookName.suffix" (slash path) - string name = 1; + string name = 1; // book alias without suffix, e.g.: "BookAlias" - string alias = 2; + string alias = 2; // Exact row number of column name definition at a worksheet. // // Default: 1. @@ -344,11 +344,14 @@ message FieldProp { // // TODO: use cases for more field types. string pattern = 16; - // Specify number of this field. - // All fields with number unspecified will use a sequence starting from 1 by default, - // and users should guarantee this number do not conflict with the default sequence. - // - // For tables, assigning number to a cross cell map/list/struct field also works on its 1st sub-field. + // Specify field number (unique numbered tag). + // All fields without numbers specified will use a sequence starting from 1 by default, + // and will not reuse explicitly specified field numbers. + // The first field of a message must occupy number 1 by default, and specifying other + // field number as 1 makes no sense since this number is reserved for the first field. + // If you specify same field number on multiple fields, only the first of them works. + // + // Refer to [protobuf: Assigning Field Numbers](https://protobuf.dev/programming-guides/proto3/#assigning) int32 number = 17; } diff --git a/proto/tableaupb/tableau.pb.go b/proto/tableaupb/tableau.pb.go index e55c1436..9b3ddf99 100644 --- a/proto/tableaupb/tableau.pb.go +++ b/proto/tableaupb/tableau.pb.go @@ -1290,11 +1290,14 @@ type FieldProp struct { // // TODO: use cases for more field types. Pattern string `protobuf:"bytes,16,opt,name=pattern,proto3" json:"pattern,omitempty"` - // Specify number of this field. - // All fields with number unspecified will use a sequence starting from 1 by default, - // and users should guarantee this number do not conflict with the default sequence. + // Specify field number (unique numbered tag). + // All fields without numbers specified will use a sequence starting from 1 by default, + // and will not reuse explicitly specified field numbers. + // The first field of a message must occupy number 1 by default, and specifying other + // field number as 1 makes no sense since this number is reserved for the first field. + // If you specify same field number on multiple fields, only the first of them works. // - // For tables, assigning number to a cross cell map/list/struct field also works on its 1st sub-field. + // Refer to [protobuf: Assigning Field Numbers](https://protobuf.dev/programming-guides/proto3/#assigning) Number int32 `protobuf:"varint,17,opt,name=number,proto3" json:"number,omitempty"` } diff --git a/test/functest/conf/default/FieldNumberProp.json b/test/functest/conf/default/FieldNumberProp.json index ba4c7705..bd91bc1d 100644 --- a/test/functest/conf/default/FieldNumberProp.json +++ b/test/functest/conf/default/FieldNumberProp.json @@ -18,7 +18,8 @@ "id": 90002, "value": 30 } - ] + ], + "rarity": 1 }, "2": { "id": 2, @@ -38,7 +39,8 @@ "id": 90004, "value": 40 } - ] + ], + "rarity": 2 } } } \ No newline at end of file diff --git a/test/functest/proto/default/excel__fieldprop__field_prop.proto b/test/functest/proto/default/excel__fieldprop__field_prop.proto index 172a10c2..dd0d2829 100644 --- a/test/functest/proto/default/excel__fieldprop__field_prop.proto +++ b/test/functest/proto/default/excel__fieldprop__field_prop.proto @@ -28,18 +28,19 @@ message FieldNumberProp { message Item { uint32 id = 1 [(tableau.field) = {name:"ID"}]; string name = 2 [(tableau.field) = {name:"Name"}]; - int32 price = 10 [(tableau.field) = {name:"Price" prop:{number:10}}]; - int32 number = 3 [(tableau.field) = {name:"Number"}]; - Decompose decompose = 20 [(tableau.field) = {name:"Decompose" prop:{number:20}}]; + int32 price = 3 [(tableau.field) = {name:"Price"}]; + int32 number = 4 [(tableau.field) = {name:"Number"}]; + Decompose decompose = 5 [(tableau.field) = {name:"Decompose"}]; message Decompose { - uint32 id = 20 [(tableau.field) = {name:"ID" prop:{number:20}}]; - int32 num = 5 [(tableau.field) = {name:"Num" prop:{number:5}}]; + uint32 id = 1 [(tableau.field) = {name:"ID"}]; + int32 num = 6 [(tableau.field) = {name:"Num"}]; } - repeated Attribute attribute_list = 30 [(tableau.field) = {name:"Attribute" layout:LAYOUT_HORIZONTAL prop:{number:30}}]; + repeated Attribute attribute_list = 7 [(tableau.field) = {name:"Attribute" layout:LAYOUT_HORIZONTAL}]; message Attribute { - uint32 id = 30 [(tableau.field) = {name:"ID" prop:{number:30}}]; - int32 value = 1 [(tableau.field) = {name:"Value"}]; + uint32 id = 1 [(tableau.field) = {name:"ID"}]; + int32 value = 8 [(tableau.field) = {name:"Value"}]; } + int32 rarity = 11 [(tableau.field) = {name:"Rarity"}]; } } diff --git a/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv b/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv index f5b03168..982973bd 100644 --- a/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv +++ b/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv @@ -1,5 +1,5 @@ -ID,Name,Price,Number,DecomposeID,DecomposeNum,Attribute1ID,Attribute1Value,Attribute2ID,Attribute2Value -"map",string,int32|{number:10},int32,{Decompose}uint32|{number:20},int32|{number:5},[Attribute]uint32|{number:30},int32,uint32,int32 -,,,,,,,,, -1,Apple,100,1,1001,10,90001,20,90002,30 -2,Banana,500,20,1002,20,90003,30,90004,40 +ID,Name,Price,Number,DecomposeID,DecomposeNum,Attribute1ID,Attribute1Value,Attribute2ID,Attribute2Value,Rarity +"map|{number:1}",string|{number:2},int32|{number:3},int32|{number:4},{Decompose}uint32|{number:5},int32|{number:6},[Attribute]uint32|{number:7},int32|{number:8},uint32|{number:9},int32|{number:10},int32|{number:11} +,,,,,,,,,, +1,Apple,100,1,1001,10,90001,20,90002,30,1 +2,Banana,500,20,1002,20,90003,30,90004,40,2 From 22db6471383df06bcd23fd64a031b12dfe3d6456 Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Fri, 30 May 2025 17:42:16 +0800 Subject: [PATCH 4/4] feat: add test case for autogen field numbers --- test/functest/conf/default/FieldNumberProp.json | 6 ++++-- .../proto/default/excel__fieldprop__field_prop.proto | 3 ++- .../excel/fieldprop/FieldProp#FieldNumberProp.csv | 10 +++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/functest/conf/default/FieldNumberProp.json b/test/functest/conf/default/FieldNumberProp.json index bd91bc1d..d6c9db3c 100644 --- a/test/functest/conf/default/FieldNumberProp.json +++ b/test/functest/conf/default/FieldNumberProp.json @@ -19,7 +19,8 @@ "value": 30 } ], - "rarity": 1 + "rarity": 1, + "effect": 1 }, "2": { "id": 2, @@ -40,7 +41,8 @@ "value": 40 } ], - "rarity": 2 + "rarity": 2, + "effect": 2 } } } \ No newline at end of file diff --git a/test/functest/proto/default/excel__fieldprop__field_prop.proto b/test/functest/proto/default/excel__fieldprop__field_prop.proto index dd0d2829..a5d45fe6 100644 --- a/test/functest/proto/default/excel__fieldprop__field_prop.proto +++ b/test/functest/proto/default/excel__fieldprop__field_prop.proto @@ -40,7 +40,8 @@ message FieldNumberProp { uint32 id = 1 [(tableau.field) = {name:"ID"}]; int32 value = 8 [(tableau.field) = {name:"Value"}]; } - int32 rarity = 11 [(tableau.field) = {name:"Rarity"}]; + int32 rarity = 6 [(tableau.field) = {name:"Rarity"}]; // Auto generated field number + int32 effect = 8 [(tableau.field) = {name:"Effect"}]; // Auto generated field number } } diff --git a/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv b/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv index 982973bd..4f20853d 100644 --- a/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv +++ b/test/functest/testdata/default/excel/fieldprop/FieldProp#FieldNumberProp.csv @@ -1,5 +1,5 @@ -ID,Name,Price,Number,DecomposeID,DecomposeNum,Attribute1ID,Attribute1Value,Attribute2ID,Attribute2Value,Rarity -"map|{number:1}",string|{number:2},int32|{number:3},int32|{number:4},{Decompose}uint32|{number:5},int32|{number:6},[Attribute]uint32|{number:7},int32|{number:8},uint32|{number:9},int32|{number:10},int32|{number:11} -,,,,,,,,,, -1,Apple,100,1,1001,10,90001,20,90002,30,1 -2,Banana,500,20,1002,20,90003,30,90004,40,2 +ID,Name,Price,Number,DecomposeID,DecomposeNum,Attribute1ID,Attribute1Value,Attribute2ID,Attribute2Value,Rarity,Effect +"map|{number:1}",string|{number:2},int32|{number:3},int32|{number:4},{Decompose}uint32|{number:5},int32|{number:6},[Attribute]uint32|{number:7},int32|{number:8},uint32,int32,int32,int32 +,,,,,,,,,,Auto generated field number,Auto generated field number +1,Apple,100,1,1001,10,90001,20,90002,30,1,1 +2,Banana,500,20,1002,20,90003,30,90004,40,2,2