[#111] protogen: Emit slice of messages without a pointer

```
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 a2025376fc
commit 5e1c6a908f
26 changed files with 138 additions and 166 deletions

View file

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

Binary file not shown.

View file

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

Binary file not shown.

View file

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

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

Binary file not shown.

View file

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

Binary file not shown.

Binary file not shown.

View file

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

View file

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

View file

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

Binary file not shown.

View file

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

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 return r
} }
func uint32SliceToAux(s []uint32) []*generated.RepPrimitives_Aux { func uint32SliceToAux(s []uint32) []generated.RepPrimitives_Aux {
r := make([]*generated.RepPrimitives_Aux, len(s)) r := make([]generated.RepPrimitives_Aux, len(s))
for i := range s { for i := range s {
r[i] = &generated.RepPrimitives_Aux{s[i]} r[i] = generated.RepPrimitives_Aux{InnerField: s[i]}
} }
return r 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()" template = "%s = in.Bytes()"
case protoreflect.MessageKind: case protoreflect.MessageKind:
if f.Desc.IsList() { if f.Desc.IsList() {
g.P("f = new(", fieldType(g, f)[3:], ")") g.P("f = ", fieldType(g, f)[2:], "{}")
} else { } else {
g.P("f = new(", fieldType(g, f)[1:], ")") 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("data, ok := fc.MessageData()")
g.P(`if !ok { return fmt.Errorf("cannot unmarshal field %s", "`, f.GoName, `") }`) g.P(`if !ok { return fmt.Errorf("cannot unmarshal field %s", "`, f.GoName, `") }`)
if f.Desc.IsList() { if f.Desc.IsList() {
g.P(name, " = append(", name, ", new(", fieldType(g, f)[3:], "))") g.P(name, " = append(", name, ", ", fieldType(g, f)[2:], "{})")
g.P("ff := ", name, "[len(", name, ")-1]") g.P("ff := &", name, "[len(", name, ")-1]")
name = "ff" name = "ff"
} else if f.Oneof != nil { } else if f.Oneof != nil {
const tmp = "oneofField" const tmp = "oneofField"
@ -172,11 +172,12 @@ func emitMarshalRaw(g *protogen.GeneratedFile, f *protogen.Field, name string) {
defer g.P("}") defer g.P("}")
name += "[i]" 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(name, ".EmitProtobuf(mm.AppendMessage(", f.Desc.Number(), "))")
g.P("}")
return return
} }

View file

@ -43,7 +43,10 @@ func fieldType(g *protogen.GeneratedFile, field *protogen.Field) structField {
case protoreflect.BytesKind: case protoreflect.BytesKind:
typ = "[]byte" typ = "[]byte"
case protoreflect.MessageKind: 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: case protoreflect.GroupKind:
panic("unimplemented") 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()): case f.Desc.IsList() && (f.Desc.Kind() == protoreflect.MessageKind || f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()):
g.P("for i := range ", name, "{") g.P("for i := range ", name, "{")
if f.Desc.Kind() == protoreflect.MessageKind { 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 { } else {
if f.Desc.Kind() != protoreflect.Uint64Kind { if f.Desc.Kind() != protoreflect.Uint64Kind {
panic("only uint64 unpacked primitive is supported") panic("only uint64 unpacked primitive is supported")