services/control: Autogenerate stable marshalers

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-20 13:24:30 +03:00 committed by LeL
parent d2d1694113
commit 0408acc40e
17 changed files with 6 additions and 1309 deletions

View file

@ -66,11 +66,14 @@ protoc:
@GOPRIVATE=github.com/nspcc-dev go mod vendor @GOPRIVATE=github.com/nspcc-dev go mod vendor
# Install specific version for protobuf lib # Install specific version for protobuf lib
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/golang/protobuf | xargs go install -v @go list -f '{{.Path}}/...@{{.Version}}' -m github.com/golang/protobuf | xargs go install -v
@GOBIN=$(abspath $(BIN)) go install -mod=mod -v github.com/nspcc-dev/neofs-api-go/v2/util/protogen
# Protoc generate # Protoc generate
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \ @for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
echo "⇒ Processing $$f "; \ echo "⇒ Processing $$f "; \
protoc \ protoc \
--proto_path=.:./vendor:/usr/local/include \ --proto_path=.:./vendor:/usr/local/include \
--plugin=protoc-gen-go-neofs=$(BIN)/protogen \
--go-neofs_out=. --go-neofs_opt=paths=source_relative \
--go_out=. --go_opt=paths=source_relative \ --go_out=. --go_opt=paths=source_relative \
--go-grpc_opt=require_unimplemented_servers=false \ --go-grpc_opt=require_unimplemented_servers=false \
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \ --go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \

4
go.mod
View file

@ -17,7 +17,7 @@ require (
github.com/nspcc-dev/hrw v1.0.9 github.com/nspcc-dev/hrw v1.0.9
github.com/nspcc-dev/neo-go v0.99.1-pre.0.20220609082921-2c9fb2044242 github.com/nspcc-dev/neo-go v0.99.1-pre.0.20220609082921-2c9fb2044242
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 // indirect github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 // indirect
github.com/nspcc-dev/neofs-api-go/v2 v2.12.2 github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220620114558-454b5c0ed7e9
github.com/nspcc-dev/neofs-contract v0.15.1 github.com/nspcc-dev/neofs-contract v0.15.1
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220616082321-e986f4780721 github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220616082321-e986f4780721
github.com/nspcc-dev/tzhash v1.5.2 github.com/nspcc-dev/tzhash v1.5.2
@ -34,7 +34,7 @@ require (
go.uber.org/zap v1.18.1 go.uber.org/zap v1.18.1
golang.org/x/term v0.0.0-20210429154555-c04ba851c2a4 golang.org/x/term v0.0.0-20210429154555-c04ba851c2a4
google.golang.org/grpc v1.41.0 google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.27.1 google.golang.org/protobuf v1.28.0
) )
require ( require (

BIN
go.sum

Binary file not shown.

View file

@ -1,30 +1,5 @@
package control package control
import (
"github.com/nspcc-dev/neofs-api-go/v2/util/proto"
)
// StableMarshal reads binary representation of health check request body
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *HealthCheckRequest_Body) StableMarshal(buf []byte) ([]byte, error) {
return buf, nil
}
// StableSize returns binary size of health check request body
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *HealthCheckRequest_Body) StableSize() int {
return 0
}
// SetBody sets health check request body. // SetBody sets health check request body.
func (x *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) { func (x *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) {
if x != nil { if x != nil {
@ -32,33 +7,6 @@ func (x *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) {
} }
} }
// SetSignature sets signature of the health check request body.
func (x *HealthCheckRequest) SetSignature(body *Signature) {
if x != nil {
x.Signature = body
}
}
// ReadSignedData reads signed data of health check request to buf.
//
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *HealthCheckRequest) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf)
}
// SignedDataSize returns binary size of the signed data
// of health check request.
//
// Structures with the same field values have the same signed data size.
func (x *HealthCheckRequest) SignedDataSize() int {
return x.GetBody().StableSize()
}
// SetHealthStatus sets health status of the IR application. // SetHealthStatus sets health status of the IR application.
func (x *HealthCheckResponse_Body) SetHealthStatus(v HealthStatus) { func (x *HealthCheckResponse_Body) SetHealthStatus(v HealthStatus) {
if x != nil { if x != nil {
@ -66,79 +14,9 @@ func (x *HealthCheckResponse_Body) SetHealthStatus(v HealthStatus) {
} }
} }
const (
_ = iota
healthRespBodyHealthStatusFNum
)
// StableMarshal reads binary representation of health check response body
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *HealthCheckResponse_Body) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if sz := x.StableSize(); len(buf) < sz {
buf = make([]byte, sz)
}
proto.EnumMarshal(healthRespBodyHealthStatusFNum, buf, int32(x.HealthStatus))
return buf
}
// StableSize returns binary size of health check response body
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *HealthCheckResponse_Body) StableSize() int {
if x == nil {
return 0
}
size := 0
size += proto.EnumSize(healthRespBodyHealthStatusFNum, int32(x.HealthStatus))
return size
}
// SetBody sets health check response body. // SetBody sets health check response body.
func (x *HealthCheckResponse) SetBody(v *HealthCheckResponse_Body) { func (x *HealthCheckResponse) SetBody(v *HealthCheckResponse_Body) {
if x != nil { if x != nil {
x.Body = v x.Body = v
} }
} }
// SetSignature sets signature of the health check response body.
func (x *HealthCheckResponse) SetSignature(v *Signature) {
if x != nil {
x.Signature = v
}
}
// ReadSignedData reads signed data of health check response to buf.
//
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *HealthCheckResponse) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf), nil
}
// SignedDataSize returns binary size of the signed data
// of health check response.
//
// Structures with the same field values have the same signed data size.
func (x *HealthCheckResponse) SignedDataSize() int {
return x.GetBody().StableSize()
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pkg/services/control/ir/types_neofs.pb.go generated Normal file

Binary file not shown.

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.

BIN
pkg/services/control/service_neofs.pb.go generated Normal file

Binary file not shown.

View file

@ -1,7 +1,6 @@
package control package control
import ( import (
"github.com/nspcc-dev/neofs-api-go/v2/util/proto"
"google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/protojson"
) )
@ -40,62 +39,6 @@ func (x *NodeInfo_Attribute) SetParents(v []string) {
} }
} }
const (
_ = iota
nodeAttrKeyFNum
nodeAttrValueFNum
nodeAttrParentsFNum
)
// StableMarshal reads binary representation of node attribute
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *NodeInfo_Attribute) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if sz := x.StableSize(); len(buf) < sz {
buf = make([]byte, sz)
}
offset := proto.StringMarshal(nodeAttrKeyFNum, buf, x.Key)
offset += proto.StringMarshal(nodeAttrValueFNum, buf[offset:], x.Value)
for i := range x.Parents {
offset += proto.StringMarshal(nodeAttrParentsFNum, buf[offset:], x.Parents[i])
}
return buf
}
// StableSize returns binary size of node attribute
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *NodeInfo_Attribute) StableSize() int {
if x == nil {
return 0
}
size := 0
size += proto.StringSize(nodeAttrKeyFNum, x.Key)
size += proto.StringSize(nodeAttrValueFNum, x.Value)
parents := x.GetParents()
for i := range parents {
size += proto.StringSize(nodeAttrParentsFNum, parents[i])
}
return size
}
// SetPublicKey sets public key of the NeoFS node in a binary format. // SetPublicKey sets public key of the NeoFS node in a binary format.
func (x *NodeInfo) SetPublicKey(v []byte) { func (x *NodeInfo) SetPublicKey(v []byte) {
if x != nil { if x != nil {
@ -124,66 +67,6 @@ func (x *NodeInfo) SetState(v NetmapStatus) {
} }
} }
const (
_ = iota
nodePubKeyFNum
nodeAddrFNum
nodeAttrsFNum
nodeStateFNum
)
// StableMarshal reads binary representation of node information
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *NodeInfo) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if sz := x.StableSize(); len(buf) < sz {
buf = make([]byte, sz)
}
offset := proto.BytesMarshal(nodePubKeyFNum, buf, x.PublicKey)
offset += proto.RepeatedStringMarshal(nodeAddrFNum, buf[offset:], x.Addresses)
for i := range x.Attributes {
offset += proto.NestedStructureMarshal(nodeAttrsFNum, buf[offset:], x.Attributes[i])
}
proto.EnumMarshal(nodeStateFNum, buf[offset:], int32(x.State))
return buf
}
// StableSize returns binary size of node information
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *NodeInfo) StableSize() int {
if x == nil {
return 0
}
size := 0
size += proto.BytesSize(nodePubKeyFNum, x.PublicKey)
size += proto.RepeatedStringSize(nodeAddrFNum, x.Addresses)
for i := range x.Attributes {
size += proto.NestedStructureSize(nodeAttrsFNum, x.Attributes[i])
}
size += proto.EnumSize(nodeStateFNum, int32(x.State))
return size
}
// SetEpoch sets revision number of the network map. // SetEpoch sets revision number of the network map.
func (x *Netmap) SetEpoch(v uint64) { func (x *Netmap) SetEpoch(v uint64) {
if x != nil { if x != nil {
@ -198,56 +81,6 @@ func (x *Netmap) SetNodes(v []*NodeInfo) {
} }
} }
const (
_ = iota
netmapEpochFNum
netmapNodesFNum
)
// StableMarshal reads binary representation of netmap in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *Netmap) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if sz := x.StableSize(); len(buf) < sz {
buf = make([]byte, sz)
}
offset := proto.UInt64Marshal(netmapEpochFNum, buf, x.Epoch)
for i := range x.Nodes {
offset += proto.NestedStructureMarshal(netmapNodesFNum, buf[offset:], x.Nodes[i])
}
return buf
}
// StableSize returns binary size of netmap in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *Netmap) StableSize() int {
if x == nil {
return 0
}
size := 0
size += proto.UInt64Size(netmapEpochFNum, x.Epoch)
for i := range x.Nodes {
size += proto.NestedStructureSize(netmapNodesFNum, x.Nodes[i])
}
return size
}
func (x *Netmap) MarshalJSON() ([]byte, error) { func (x *Netmap) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{ return protojson.MarshalOptions{
EmitUnpopulated: true, EmitUnpopulated: true,
@ -283,61 +116,3 @@ func (x *ShardInfo) SetMode(v ShardMode) {
func (x *ShardInfo) SetErrorCount(count uint32) { func (x *ShardInfo) SetErrorCount(count uint32) {
x.ErrorCount = count x.ErrorCount = count
} }
const (
_ = iota
shardInfoIDFNum
shardInfoMetabaseFNum
shardInfoBlobstorFNum
shardInfoWriteCacheFNum
shardInfoModeFNum
shardInfoErrorCountFNum
)
// StableSize returns binary size of shard information
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *ShardInfo) StableSize() int {
if x == nil {
return 0
}
size := 0
size += proto.BytesSize(shardInfoIDFNum, x.Shard_ID)
size += proto.StringSize(shardInfoMetabaseFNum, x.MetabasePath)
size += proto.StringSize(shardInfoBlobstorFNum, x.BlobstorPath)
size += proto.StringSize(shardInfoWriteCacheFNum, x.WritecachePath)
size += proto.EnumSize(shardInfoModeFNum, int32(x.Mode))
size += proto.UInt32Size(shardInfoErrorCountFNum, x.ErrorCount)
return size
}
// StableMarshal reads binary representation of shard information
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *ShardInfo) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if sz := x.StableSize(); len(buf) < sz {
buf = make([]byte, sz)
}
offset := proto.BytesMarshal(shardInfoIDFNum, buf, x.Shard_ID)
offset += proto.StringMarshal(shardInfoMetabaseFNum, buf[offset:], x.MetabasePath)
offset += proto.StringMarshal(shardInfoBlobstorFNum, buf[offset:], x.BlobstorPath)
offset += proto.StringMarshal(shardInfoWriteCacheFNum, buf[offset:], x.WritecachePath)
offset += proto.EnumMarshal(shardInfoModeFNum, buf[offset:], int32(x.Mode))
proto.EnumMarshal(shardInfoErrorCountFNum, buf[offset:], int32(x.ErrorCount))
return buf
}

Binary file not shown.

BIN
pkg/services/control/types_neofs.pb.go generated Normal file

Binary file not shown.