protogen: Emit slice of messages without a pointer
Some checks failed
DCO action / DCO (pull_request) Failing after 1m0s
Tests and linters / Tests (1.23) (pull_request) Successful in 1m3s
Tests and linters / Tests (1.22) (pull_request) Successful in 1m6s
Tests and linters / Tests with -race (pull_request) Successful in 1m18s
Tests and linters / Lint (pull_request) Successful in 2m13s

```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
                                              │      old      │                 new                  │
                                              │    sec/op     │    sec/op     vs base                │
ObjectIDSlice/0_elements/to_grpc_message-8       3.193n ±  2%   3.242n ±  0%   +1.50% (p=0.034 n=10)
ObjectIDSlice/0_elements/from_grpc_message-8     3.197n ±  2%   3.343n ±  1%   +4.57% (p=0.000 n=10)
ObjectIDSlice/0_elements/marshal-8               5.666n ±  3%   5.642n ±  0%   -0.42% (p=0.000 n=10)
ObjectIDSlice/1_elements/to_grpc_message-8       53.10n ±  6%   29.78n ± 12%  -43.92% (p=0.000 n=10)
ObjectIDSlice/1_elements/from_grpc_message-8     28.99n ±  5%   29.77n ±  7%        ~ (p=0.165 n=10)
ObjectIDSlice/1_elements/marshal-8               49.08n ±  7%   50.72n ±  6%        ~ (p=0.218 n=10)
ObjectIDSlice/50_elements/to_grpc_message-8     1652.5n ±  7%   277.2n ±  1%  -83.22% (p=0.000 n=10)
ObjectIDSlice/50_elements/from_grpc_message-8    261.2n ± 11%   226.7n ± 15%  -13.19% (p=0.003 n=10)
ObjectIDSlice/50_elements/marshal-8              1.512µ ±  6%   1.514µ ±  6%        ~ (p=0.955 n=10)
geomean                                          52.15n         39.99n        -23.31%

                                              │      old       │                  new                   │
                                              │      B/op      │     B/op      vs base                  │
ObjectIDSlice/0_elements/to_grpc_message-8        0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/0_elements/from_grpc_message-8      0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/0_elements/marshal-8                0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/1_elements/to_grpc_message-8        32.00 ± 0%       24.00 ± 0%  -25.00% (p=0.000 n=10)
ObjectIDSlice/1_elements/from_grpc_message-8      24.00 ± 0%       24.00 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/1_elements/marshal-8                48.00 ± 0%       48.00 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/50_elements/to_grpc_message-8     1.578Ki ± 0%     1.250Ki ± 0%  -20.79% (p=0.000 n=10)
ObjectIDSlice/50_elements/from_grpc_message-8   1.250Ki ± 0%     1.250Ki ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/50_elements/marshal-8             2.000Ki ± 0%     2.000Ki ± 0%        ~ (p=1.000 n=10) ¹
geomean                                                      ²                  -5.62%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                              │      old      │                 new                  │
                                              │   allocs/op   │ allocs/op   vs base                  │
ObjectIDSlice/0_elements/to_grpc_message-8       0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/0_elements/from_grpc_message-8     0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/0_elements/marshal-8               0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/1_elements/to_grpc_message-8       2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=10)
ObjectIDSlice/1_elements/from_grpc_message-8     1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/1_elements/marshal-8               1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/50_elements/to_grpc_message-8     51.000 ± 0%     1.000 ± 0%  -98.04% (p=0.000 n=10)
ObjectIDSlice/50_elements/from_grpc_message-8    1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=10) ¹
ObjectIDSlice/50_elements/marshal-8              1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=10) ¹
geomean                                                     ²               -40.18%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-08-27 15:12:31 +03:00
parent bed8c7f00d
commit 44e2e243c8
26 changed files with 138 additions and 166 deletions

View file

@ -187,28 +187,26 @@ func (f *HeaderFilter) FromGRPCMessage(m grpc.Message) error {
return nil
}
func HeaderFiltersToGRPC(fs []HeaderFilter) (res []*acl.EACLRecord_Filter) {
func HeaderFiltersToGRPC(fs []HeaderFilter) (res []acl.EACLRecord_Filter) {
if fs != nil {
res = make([]*acl.EACLRecord_Filter, 0, len(fs))
res = make([]acl.EACLRecord_Filter, 0, len(fs))
for i := range fs {
res = append(res, fs[i].ToGRPCMessage().(*acl.EACLRecord_Filter))
res = append(res, *fs[i].ToGRPCMessage().(*acl.EACLRecord_Filter))
}
}
return
}
func HeaderFiltersFromGRPC(fs []*acl.EACLRecord_Filter) (res []HeaderFilter, err error) {
func HeaderFiltersFromGRPC(fs []acl.EACLRecord_Filter) (res []HeaderFilter, err error) {
if fs != nil {
res = make([]HeaderFilter, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&fs[i])
if err != nil {
return
}
}
}
@ -241,28 +239,26 @@ func (t *Target) FromGRPCMessage(m grpc.Message) error {
return nil
}
func TargetsToGRPC(ts []Target) (res []*acl.EACLRecord_Target) {
func TargetsToGRPC(ts []Target) (res []acl.EACLRecord_Target) {
if ts != nil {
res = make([]*acl.EACLRecord_Target, 0, len(ts))
res = make([]acl.EACLRecord_Target, 0, len(ts))
for i := range ts {
res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord_Target))
res = append(res, *ts[i].ToGRPCMessage().(*acl.EACLRecord_Target))
}
}
return
}
func TargetsFromGRPC(fs []*acl.EACLRecord_Target) (res []Target, err error) {
func TargetsFromGRPC(fs []acl.EACLRecord_Target) (res []Target, err error) {
if fs != nil {
res = make([]Target, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&fs[i])
if err != nil {
return
}
}
}
@ -309,28 +305,26 @@ func (r *Record) FromGRPCMessage(m grpc.Message) error {
return nil
}
func RecordsToGRPC(ts []Record) (res []*acl.EACLRecord) {
func RecordsToGRPC(ts []Record) (res []acl.EACLRecord) {
if ts != nil {
res = make([]*acl.EACLRecord, 0, len(ts))
res = make([]acl.EACLRecord, 0, len(ts))
for i := range ts {
res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord))
res = append(res, *ts[i].ToGRPCMessage().(*acl.EACLRecord))
}
}
return
}
func RecordsFromGRPC(fs []*acl.EACLRecord) (res []Record, err error) {
func RecordsFromGRPC(fs []acl.EACLRecord) (res []Record, err error) {
if fs != nil {
res = make([]Record, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&fs[i])
if err != nil {
return
}
}
}
@ -429,9 +423,9 @@ func (c *APEOverride) ToGRPCMessage() grpc.Message {
m.SetTarget(c.target.ToGRPCMessage().(*apeGRPC.ChainTarget))
if len(c.chains) > 0 {
apeChains := make([]*apeGRPC.Chain, len(c.chains))
apeChains := make([]apeGRPC.Chain, len(c.chains))
for i := range c.chains {
apeChains[i] = c.chains[i].ToGRPCMessage().(*apeGRPC.Chain)
apeChains[i] = *c.chains[i].ToGRPCMessage().(*apeGRPC.Chain)
}
m.SetChains(apeChains)
}
@ -459,7 +453,7 @@ func (c *APEOverride) FromGRPCMessage(m grpc.Message) error {
c.chains = make([]*ape.Chain, len(apeChains))
for i := range apeChains {
c.chains[i] = new(ape.Chain)
if err := c.chains[i].FromGRPCMessage(apeChains[i]); err != nil {
if err := c.chains[i].FromGRPCMessage(&apeChains[i]); err != nil {
return err
}
}

Binary file not shown.

View file

@ -296,9 +296,9 @@ func (respBody *ListChainsResponseBody) ToGRPCMessage() grpc.Message {
if respBody != nil {
respBodygrpc = new(apemanager.ListChainsResponse_Body)
chainsgrpc := make([]*apeGRPC.Chain, 0, len(respBody.GetChains()))
chainsgrpc := make([]apeGRPC.Chain, 0, len(respBody.GetChains()))
for _, chain := range respBody.GetChains() {
chainsgrpc = append(chainsgrpc, chain.ToGRPCMessage().(*apeGRPC.Chain))
chainsgrpc = append(chainsgrpc, *chain.ToGRPCMessage().(*apeGRPC.Chain))
}
respBodygrpc.SetChains(chainsgrpc)
@ -317,7 +317,7 @@ func (respBody *ListChainsResponseBody) FromGRPCMessage(m grpc.Message) error {
for _, chaingrpc := range respBodygrpc.GetChains() {
chain := new(ape.Chain)
if err := chain.FromGRPCMessage(chaingrpc); err != nil {
if err := chain.FromGRPCMessage(&chaingrpc); err != nil {
return err
}
chains = append(chains, chain)

Binary file not shown.

View file

@ -39,28 +39,26 @@ func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
return nil
}
func AttributesToGRPC(xs []Attribute) (res []*container.Container_Attribute) {
func AttributesToGRPC(xs []Attribute) (res []container.Container_Attribute) {
if xs != nil {
res = make([]*container.Container_Attribute, 0, len(xs))
res = make([]container.Container_Attribute, 0, len(xs))
for i := range xs {
res = append(res, xs[i].ToGRPCMessage().(*container.Container_Attribute))
res = append(res, *xs[i].ToGRPCMessage().(*container.Container_Attribute))
}
}
return
}
func AttributesFromGRPC(xs []*container.Container_Attribute) (res []Attribute, err error) {
func AttributesFromGRPC(xs []container.Container_Attribute) (res []Attribute, err error) {
if xs != nil {
res = make([]Attribute, len(xs))
for i := range xs {
if xs[i] != nil {
err = res[i].FromGRPCMessage(xs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&xs[i])
if err != nil {
return
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -45,28 +45,26 @@ func (f *Filter) FromGRPCMessage(m grpc.Message) error {
return nil
}
func FiltersToGRPC(fs []Filter) (res []*netmap.Filter) {
func FiltersToGRPC(fs []Filter) (res []netmap.Filter) {
if fs != nil {
res = make([]*netmap.Filter, 0, len(fs))
res = make([]netmap.Filter, 0, len(fs))
for i := range fs {
res = append(res, fs[i].ToGRPCMessage().(*netmap.Filter))
res = append(res, *fs[i].ToGRPCMessage().(*netmap.Filter))
}
}
return
}
func FiltersFromGRPC(fs []*netmap.Filter) (res []Filter, err error) {
func FiltersFromGRPC(fs []netmap.Filter) (res []Filter, err error) {
if fs != nil {
res = make([]Filter, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&fs[i])
if err != nil {
return
}
}
}
@ -105,28 +103,26 @@ func (s *Selector) FromGRPCMessage(m grpc.Message) error {
return nil
}
func SelectorsToGRPC(ss []Selector) (res []*netmap.Selector) {
func SelectorsToGRPC(ss []Selector) (res []netmap.Selector) {
if ss != nil {
res = make([]*netmap.Selector, 0, len(ss))
res = make([]netmap.Selector, 0, len(ss))
for i := range ss {
res = append(res, ss[i].ToGRPCMessage().(*netmap.Selector))
res = append(res, *ss[i].ToGRPCMessage().(*netmap.Selector))
}
}
return
}
func SelectorsFromGRPC(ss []*netmap.Selector) (res []Selector, err error) {
func SelectorsFromGRPC(ss []netmap.Selector) (res []Selector, err error) {
if ss != nil {
res = make([]Selector, len(ss))
for i := range ss {
if ss[i] != nil {
err = res[i].FromGRPCMessage(ss[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&ss[i])
if err != nil {
return
}
}
}
@ -163,28 +159,26 @@ func (r *Replica) FromGRPCMessage(m grpc.Message) error {
return nil
}
func ReplicasToGRPC(rs []Replica) (res []*netmap.Replica) {
func ReplicasToGRPC(rs []Replica) (res []netmap.Replica) {
if rs != nil {
res = make([]*netmap.Replica, 0, len(rs))
res = make([]netmap.Replica, 0, len(rs))
for i := range rs {
res = append(res, rs[i].ToGRPCMessage().(*netmap.Replica))
res = append(res, *rs[i].ToGRPCMessage().(*netmap.Replica))
}
}
return
}
func ReplicasFromGRPC(rs []*netmap.Replica) (res []Replica, err error) {
func ReplicasFromGRPC(rs []netmap.Replica) (res []Replica, err error) {
if rs != nil {
res = make([]Replica, len(rs))
for i := range rs {
if rs[i] != nil {
err = res[i].FromGRPCMessage(rs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&rs[i])
if err != nil {
return
}
}
}
@ -289,28 +283,26 @@ func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
return nil
}
func AttributesToGRPC(as []Attribute) (res []*netmap.NodeInfo_Attribute) {
func AttributesToGRPC(as []Attribute) (res []netmap.NodeInfo_Attribute) {
if as != nil {
res = make([]*netmap.NodeInfo_Attribute, 0, len(as))
res = make([]netmap.NodeInfo_Attribute, 0, len(as))
for i := range as {
res = append(res, as[i].ToGRPCMessage().(*netmap.NodeInfo_Attribute))
res = append(res, *as[i].ToGRPCMessage().(*netmap.NodeInfo_Attribute))
}
}
return
}
func AttributesFromGRPC(as []*netmap.NodeInfo_Attribute) (res []Attribute, err error) {
func AttributesFromGRPC(as []netmap.NodeInfo_Attribute) (res []Attribute, err error) {
if as != nil {
res = make([]Attribute, len(as))
for i := range as {
if as[i] != nil {
err = res[i].FromGRPCMessage(as[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&as[i])
if err != nil {
return
}
}
}
@ -528,13 +520,13 @@ func (x *NetworkConfig) ToGRPCMessage() grpc.Message {
if x != nil {
m = new(netmap.NetworkConfig)
var ps []*netmap.NetworkConfig_Parameter
var ps []netmap.NetworkConfig_Parameter
if ln := len(x.ps); ln > 0 {
ps = make([]*netmap.NetworkConfig_Parameter, 0, ln)
ps = make([]netmap.NetworkConfig_Parameter, 0, ln)
for i := 0; i < ln; i++ {
ps = append(ps, x.ps[i].ToGRPCMessage().(*netmap.NetworkConfig_Parameter))
ps = append(ps, *x.ps[i].ToGRPCMessage().(*netmap.NetworkConfig_Parameter))
}
}
@ -561,10 +553,8 @@ func (x *NetworkConfig) FromGRPCMessage(m grpc.Message) error {
ps = make([]NetworkParameter, ln)
for i := 0; i < ln; i++ {
if psV2[i] != nil {
if err := ps[i].FromGRPCMessage(psV2[i]); err != nil {
return err
}
if err := ps[i].FromGRPCMessage(&psV2[i]); err != nil {
return err
}
}
}
@ -756,10 +746,10 @@ func (x *NetMap) ToGRPCMessage() grpc.Message {
m.SetEpoch(x.epoch)
if x.nodes != nil {
nodes := make([]*netmap.NodeInfo, len(x.nodes))
nodes := make([]netmap.NodeInfo, len(x.nodes))
for i := range x.nodes {
nodes[i] = x.nodes[i].ToGRPCMessage().(*netmap.NodeInfo)
nodes[i] = *x.nodes[i].ToGRPCMessage().(*netmap.NodeInfo)
}
m.SetNodes(nodes)
@ -784,7 +774,7 @@ func (x *NetMap) FromGRPCMessage(m grpc.Message) error {
x.nodes = make([]NodeInfo, len(nodes))
for i := range nodes {
err = x.nodes[i].FromGRPCMessage(nodes[i])
err = x.nodes[i].FromGRPCMessage(&nodes[i])
if err != nil {
return err
}

Binary file not shown.

View file

@ -142,28 +142,26 @@ func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
return nil
}
func AttributesToGRPC(xs []Attribute) (res []*object.Header_Attribute) {
func AttributesToGRPC(xs []Attribute) (res []object.Header_Attribute) {
if xs != nil {
res = make([]*object.Header_Attribute, 0, len(xs))
res = make([]object.Header_Attribute, 0, len(xs))
for i := range xs {
res = append(res, xs[i].ToGRPCMessage().(*object.Header_Attribute))
res = append(res, *xs[i].ToGRPCMessage().(*object.Header_Attribute))
}
}
return
}
func AttributesFromGRPC(xs []*object.Header_Attribute) (res []Attribute, err error) {
func AttributesFromGRPC(xs []object.Header_Attribute) (res []Attribute, err error) {
if xs != nil {
res = make([]Attribute, len(xs))
for i := range xs {
if xs[i] != nil {
err = res[i].FromGRPCMessage(xs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&xs[i])
if err != nil {
return
}
}
}
@ -683,9 +681,9 @@ func (s *ECInfo) ToGRPCMessage() grpc.Message {
m = new(object.ECInfo)
if s.Chunks != nil {
chunks := make([]*object.ECInfo_Chunk, len(s.Chunks))
chunks := make([]object.ECInfo_Chunk, len(s.Chunks))
for i := range chunks {
chunks[i] = s.Chunks[i].ToGRPCMessage().(*object.ECInfo_Chunk)
chunks[i] = *s.Chunks[i].ToGRPCMessage().(*object.ECInfo_Chunk)
}
m.Chunks = chunks
}
@ -706,7 +704,7 @@ func (s *ECInfo) FromGRPCMessage(m grpc.Message) error {
} else {
s.Chunks = make([]ECChunk, len(chunks))
for i := range chunks {
if err := s.Chunks[i].FromGRPCMessage(chunks[i]); err != nil {
if err := s.Chunks[i].FromGRPCMessage(&chunks[i]); err != nil {
return err
}
}
@ -1626,28 +1624,26 @@ func (f *SearchFilter) FromGRPCMessage(m grpc.Message) error {
return nil
}
func SearchFiltersToGRPC(fs []SearchFilter) (res []*object.SearchRequest_Body_Filter) {
func SearchFiltersToGRPC(fs []SearchFilter) (res []object.SearchRequest_Body_Filter) {
if fs != nil {
res = make([]*object.SearchRequest_Body_Filter, 0, len(fs))
res = make([]object.SearchRequest_Body_Filter, 0, len(fs))
for i := range fs {
res = append(res, fs[i].ToGRPCMessage().(*object.SearchRequest_Body_Filter))
res = append(res, *fs[i].ToGRPCMessage().(*object.SearchRequest_Body_Filter))
}
}
return
}
func SearchFiltersFromGRPC(fs []*object.SearchRequest_Body_Filter) (res []SearchFilter, err error) {
func SearchFiltersFromGRPC(fs []object.SearchRequest_Body_Filter) (res []SearchFilter, err error) {
if fs != nil {
res = make([]SearchFilter, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&fs[i])
if err != nil {
return
}
}
}
@ -1827,28 +1823,26 @@ func (r *Range) FromGRPCMessage(m grpc.Message) error {
return nil
}
func RangesToGRPC(rs []Range) (res []*object.Range) {
func RangesToGRPC(rs []Range) (res []object.Range) {
if rs != nil {
res = make([]*object.Range, 0, len(rs))
res = make([]object.Range, 0, len(rs))
for i := range rs {
res = append(res, rs[i].ToGRPCMessage().(*object.Range))
res = append(res, *rs[i].ToGRPCMessage().(*object.Range))
}
}
return
}
func RangesFromGRPC(rs []*object.Range) (res []Range, err error) {
func RangesFromGRPC(rs []object.Range) (res []Range, err error) {
if rs != nil {
res = make([]Range, len(rs))
for i := range rs {
if rs[i] != nil {
err = res[i].FromGRPCMessage(rs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&rs[i])
if err != nil {
return
}
}
}

Binary file not shown.

Binary file not shown.

View file

@ -89,13 +89,13 @@ func (x *Lock) ToGRPCMessage() grpc.Message {
if x != nil {
m = new(lock.Lock)
var members []*refsGRPC.ObjectID
var members []refsGRPC.ObjectID
if x.members != nil {
members = make([]*refsGRPC.ObjectID, len(x.members))
members = make([]refsGRPC.ObjectID, len(x.members))
for i := range x.members {
members[i] = x.members[i].ToGRPCMessage().(*refsGRPC.ObjectID)
members[i] = *x.members[i].ToGRPCMessage().(*refsGRPC.ObjectID)
}
}
@ -119,7 +119,7 @@ func (x *Lock) FromGRPCMessage(m grpc.Message) error {
var err error
for i := range x.members {
err = x.members[i].FromGRPCMessage(members[i])
err = x.members[i].FromGRPCMessage(&members[i])
if err != nil {
return err
}

View file

@ -52,28 +52,26 @@ func (c *ContainerID) FromGRPCMessage(m grpc.Message) error {
return nil
}
func ContainerIDsToGRPCMessage(ids []ContainerID) (res []*refs.ContainerID) {
func ContainerIDsToGRPCMessage(ids []ContainerID) (res []refs.ContainerID) {
if ids != nil {
res = make([]*refs.ContainerID, 0, len(ids))
res = make([]refs.ContainerID, 0, len(ids))
for i := range ids {
res = append(res, ids[i].ToGRPCMessage().(*refs.ContainerID))
res = append(res, *ids[i].ToGRPCMessage().(*refs.ContainerID))
}
}
return
}
func ContainerIDsFromGRPCMessage(idsV2 []*refs.ContainerID) (res []ContainerID, err error) {
func ContainerIDsFromGRPCMessage(idsV2 []refs.ContainerID) (res []ContainerID, err error) {
if idsV2 != nil {
res = make([]ContainerID, len(idsV2))
for i := range idsV2 {
if idsV2[i] != nil {
err = res[i].FromGRPCMessage(idsV2[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&idsV2[i])
if err != nil {
return
}
}
}
@ -104,28 +102,26 @@ func (o *ObjectID) FromGRPCMessage(m grpc.Message) error {
return nil
}
func ObjectIDListToGRPCMessage(ids []ObjectID) (res []*refs.ObjectID) {
func ObjectIDListToGRPCMessage(ids []ObjectID) (res []refs.ObjectID) {
if ids != nil {
res = make([]*refs.ObjectID, 0, len(ids))
res = make([]refs.ObjectID, 0, len(ids))
for i := range ids {
res = append(res, ids[i].ToGRPCMessage().(*refs.ObjectID))
res = append(res, *ids[i].ToGRPCMessage().(*refs.ObjectID))
}
}
return
}
func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []ObjectID, err error) {
func ObjectIDListFromGRPCMessage(idsV2 []refs.ObjectID) (res []ObjectID, err error) {
if idsV2 != nil {
res = make([]ObjectID, len(idsV2))
for i := range idsV2 {
if idsV2[i] != nil {
err = res[i].FromGRPCMessage(idsV2[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&idsV2[i])
if err != nil {
return
}
}
}

View file

@ -207,28 +207,26 @@ func (x *XHeader) FromGRPCMessage(m grpc.Message) error {
return nil
}
func XHeadersToGRPC(xs []XHeader) (res []*session.XHeader) {
func XHeadersToGRPC(xs []XHeader) (res []session.XHeader) {
if xs != nil {
res = make([]*session.XHeader, 0, len(xs))
res = make([]session.XHeader, 0, len(xs))
for i := range xs {
res = append(res, xs[i].ToGRPCMessage().(*session.XHeader))
res = append(res, *xs[i].ToGRPCMessage().(*session.XHeader))
}
}
return
}
func XHeadersFromGRPC(xs []*session.XHeader) (res []XHeader, err error) {
func XHeadersFromGRPC(xs []session.XHeader) (res []XHeader, err error) {
if xs != nil {
res = make([]XHeader, len(xs))
for i := range xs {
if xs[i] != nil {
err = res[i].FromGRPCMessage(xs[i])
if err != nil {
return
}
err = res[i].FromGRPCMessage(&xs[i])
if err != nil {
return
}
}
}

Binary file not shown.

View file

@ -48,13 +48,13 @@ func (x *Status) ToGRPCMessage() grpc.Message {
m.SetCode(CodeToGRPC(x.code))
m.SetMessage(x.msg)
var ds []*status.Status_Detail
var ds []status.Status_Detail
if ln := len(x.details); ln > 0 {
ds = make([]*status.Status_Detail, 0, ln)
ds = make([]status.Status_Detail, 0, ln)
for i := 0; i < ln; i++ {
ds = append(ds, x.details[i].ToGRPCMessage().(*status.Status_Detail))
ds = append(ds, *x.details[i].ToGRPCMessage().(*status.Status_Detail))
}
}
@ -81,10 +81,8 @@ func (x *Status) FromGRPCMessage(m grpc.Message) error {
ds = make([]Detail, ln)
for i := 0; i < ln; i++ {
if dsV2[i] != nil {
if err := ds[i].FromGRPCMessage(dsV2[i]); err != nil {
return err
}
if err := ds[i].FromGRPCMessage(&dsV2[i]); err != nil {
return err
}
}
}

Binary file not shown.

Binary file not shown.

View file

@ -133,10 +133,10 @@ func randIntSlice[T protoInt](n int, includeZero bool) []T {
return r
}
func uint32SliceToAux(s []uint32) []*generated.RepPrimitives_Aux {
r := make([]*generated.RepPrimitives_Aux, len(s))
func uint32SliceToAux(s []uint32) []generated.RepPrimitives_Aux {
r := make([]generated.RepPrimitives_Aux, len(s))
for i := range s {
r[i] = &generated.RepPrimitives_Aux{s[i]}
r[i] = generated.RepPrimitives_Aux{InnerField: s[i]}
}
return r
}

Binary file not shown.

View file

@ -117,7 +117,7 @@ func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string
template = "%s = in.Bytes()"
case protoreflect.MessageKind:
if f.Desc.IsList() {
g.P("f = new(", fieldType(g, f)[3:], ")")
g.P("f = ", fieldType(g, f)[2:], "{}")
} else {
g.P("f = new(", fieldType(g, f)[1:], ")")
}

View file

@ -39,8 +39,8 @@ func emitFieldUnmarshal(g *protogen.GeneratedFile, f *protogen.Field) {
g.P("data, ok := fc.MessageData()")
g.P(`if !ok { return fmt.Errorf("cannot unmarshal field %s", "`, f.GoName, `") }`)
if f.Desc.IsList() {
g.P(name, " = append(", name, ", new(", fieldType(g, f)[3:], "))")
g.P("ff := ", name, "[len(", name, ")-1]")
g.P(name, " = append(", name, ", ", fieldType(g, f)[2:], "{})")
g.P("ff := &", name, "[len(", name, ")-1]")
name = "ff"
} else if f.Oneof != nil {
const tmp = "oneofField"
@ -172,11 +172,12 @@ func emitMarshalRaw(g *protogen.GeneratedFile, f *protogen.Field, name string) {
defer g.P("}")
name += "[i]"
} else {
g.P("if ", notNil(name), " {")
defer g.P("}")
}
g.P("if ", notNil(name), " {")
g.P(name, ".EmitProtobuf(mm.AppendMessage(", f.Desc.Number(), "))")
g.P("}")
return
}

View file

@ -43,7 +43,10 @@ func fieldType(g *protogen.GeneratedFile, field *protogen.Field) structField {
case protoreflect.BytesKind:
typ = "[]byte"
case protoreflect.MessageKind:
typ = structField(g.QualifiedGoIdent(field.Message.GoIdent)).PointerTo()
typ = structField(g.QualifiedGoIdent(field.Message.GoIdent))
if !field.Desc.IsList() {
typ = typ.PointerTo()
}
case protoreflect.GroupKind:
panic("unimplemented")
}

View file

@ -72,7 +72,7 @@ func emitFieldSize(g *protogen.GeneratedFile, f *protogen.Field) {
case f.Desc.IsList() && (f.Desc.Kind() == protoreflect.MessageKind || f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()):
g.P("for i := range ", name, "{")
if f.Desc.Kind() == protoreflect.MessageKind {
g.P("size += ", protoPackage.Ident("NestedStructureSize"), "(", f.Desc.Number(), ", ", name, "[i])")
g.P("size += ", protoPackage.Ident("NestedStructureSizeUnchecked"), "(", f.Desc.Number(), ", &", name, "[i])")
} else {
if f.Desc.Kind() != protoreflect.Uint64Kind {
panic("only uint64 unpacked primitive is supported")