[#1322] Use new protobuf marshaler

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-08-19 18:28:53 +03:00 committed by Evgenii Stratonikov
parent a345c972bf
commit 7bca428db0
29 changed files with 24581 additions and 17533 deletions

View file

@ -11,7 +11,6 @@ GO_VERSION ?= 1.22
LINT_VERSION ?= 1.60.1
TRUECLOUDLAB_LINT_VERSION ?= 0.0.6
PROTOC_VERSION ?= 25.0
PROTOC_GEN_GO_VERSION ?= $(shell go list -f '{{.Version}}' -m google.golang.org/protobuf)
PROTOGEN_FROSTFS_VERSION ?= $(shell go list -f '{{.Version}}' -m git.frostfs.info/TrueCloudLab/frostfs-api-go/v2)
PROTOC_OS_VERSION=osx-x86_64
ifeq ($(shell uname), Linux)
@ -39,7 +38,6 @@ LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT
TMP_DIR := .cache
PROTOBUF_DIR ?= $(abspath $(BIN))/protobuf
PROTOC_DIR ?= $(PROTOBUF_DIR)/protoc-v$(PROTOC_VERSION)
PROTOC_GEN_GO_DIR ?= $(PROTOBUF_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION)
PROTOGEN_FROSTFS_DIR ?= $(PROTOBUF_DIR)/protogen-$(PROTOGEN_FROSTFS_VERSION)
STATICCHECK_DIR ?= $(abspath $(BIN))/staticcheck
STATICCHECK_VERSION_DIR ?= $(STATICCHECK_DIR)/$(STATICCHECK_VERSION)
@ -107,17 +105,15 @@ export-metrics: dep
# Regenerate proto files:
protoc:
@if [ ! -d "$(PROTOC_DIR)" ] || [ ! -d "$(PROTOC_GEN_GO_DIR)" ] || [ ! -d "$(PROTOGEN_FROSTFS_DIR)" ]; then \
@if [ ! -d "$(PROTOC_DIR)" ] || [ ! -d "$(PROTOGEN_FROSTFS_DIR)" ]; then \
make protoc-install; \
fi
@for f in `find . -type f -name '*.proto' -not -path './bin/*'`; do \
echo "⇒ Processing $$f "; \
$(PROTOC_DIR)/bin/protoc \
--proto_path=.:$(PROTOC_DIR)/include:/usr/local/include \
--plugin=protoc-gen-go=$(PROTOC_GEN_GO_DIR)/protoc-gen-go \
--plugin=protoc-gen-go-frostfs=$(PROTOGEN_FROSTFS_DIR)/protogen \
--go-frostfs_out=. --go-frostfs_opt=paths=source_relative \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_opt=require_unimplemented_servers=false \
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \
done
@ -130,8 +126,6 @@ protoc-install:
@wget -q -O $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip 'https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS_VERSION).zip'
@unzip -q -o $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip -d $(PROTOC_DIR)
@rm $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip
@echo "⇒ Installing protoc-gen-go..."
@GOBIN=$(PROTOC_GEN_GO_DIR) go install -v google.golang.org/protobuf/...@$(PROTOC_GEN_GO_VERSION)
@echo "⇒ Instaling protogen FrostFS plugin..."
@GOBIN=$(PROTOGEN_FROSTFS_DIR) go install -mod=mod -v git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/protogen@$(PROTOGEN_FROSTFS_VERSION)

View file

@ -84,7 +84,7 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) {
body.SetStatus(control.NetmapStatus_MAINTENANCE)
if force {
body.SetForceMaintenance()
body.SetForceMaintenance(true)
common.PrintVerbose(cmd, "Local maintenance will be forced.")
}
targetStatus = control.NetmapStatus_MAINTENANCE

View file

@ -117,10 +117,10 @@ func setShardMode(cmd *cobra.Command, _ []string) {
req.SetBody(body)
body.SetMode(mode)
body.SetShardIDList(getShardIDList(cmd))
body.SetShard_ID(getShardIDList(cmd))
reset, _ := cmd.Flags().GetBool(shardClearErrorsFlag)
body.ClearErrorCounter(reset)
body.SetResetErrorCounter(reset)
signRequest(cmd, pk, req)

View file

@ -44,7 +44,7 @@ func verifyResponse(cmd *cobra.Command,
GetSign() []byte
},
body interface {
StableMarshal([]byte) []byte
MarshalProtobuf([]byte) []byte
},
) {
if sigControl == nil {
@ -60,7 +60,7 @@ func verifyResponse(cmd *cobra.Command,
var sig frostfscrypto.Signature
commonCmd.ExitOnErr(cmd, "can't read signature: %w", sig.ReadFromV2(sigV2))
if !sig.Verify(body.StableMarshal(nil)) {
if !sig.Verify(body.MarshalProtobuf(nil)) {
commonCmd.ExitOnErr(cmd, "", errors.New("invalid response signature"))
}
}

View file

@ -84,7 +84,7 @@ func (s *networkState) setNodeInfo(ni *netmapSDK.NodeInfo) {
}
}
s.setControlNetmapStatus(ctrlNetSt)
s.setControlNetmapStatus(control.NetmapStatus(ctrlNetSt))
}
// sets the current node state to the given value. Subsequent cfg.bootstrap

7
go.mod
View file

@ -4,16 +4,17 @@ go 1.22
require (
code.gitea.io/sdk/gitea v0.17.1
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240813155151-d112a28d382f
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240819074700-a43110e36326
git.frostfs.info/TrueCloudLab/frostfs-contract v0.19.3-0.20240621131249-49e5270f673e
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0
git.frostfs.info/TrueCloudLab/frostfs-locode-db v0.4.1-0.20240710074952-65761deb5c0d
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240813155821-98aabc45a720
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240820072028-6dd7be11d13b
git.frostfs.info/TrueCloudLab/hrw v1.2.1
git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20240814080254-96225afacb88
git.frostfs.info/TrueCloudLab/tzhash v1.8.0
git.frostfs.info/TrueCloudLab/zapjournald v0.0.0-20240124114243-cb2e66427d02
github.com/VictoriaMetrics/easyproto v0.1.4
github.com/cheggaaa/pb v1.0.29
github.com/chzyer/readline v1.5.1
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568
@ -21,6 +22,7 @@ require (
github.com/google/uuid v1.6.0
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/klauspost/compress v1.17.4
github.com/mailru/easyjson v0.7.7
github.com/mitchellh/go-homedir v1.1.0
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multiaddr v0.12.1
@ -84,7 +86,6 @@ require (
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/klauspost/reedsolomon v1.12.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect

10
go.sum
View file

@ -1,7 +1,7 @@
code.gitea.io/sdk/gitea v0.17.1 h1:3jCPOG2ojbl8AcfaUCRYLT5MUcBMFwS0OSK2mA5Zok8=
code.gitea.io/sdk/gitea v0.17.1/go.mod h1:aCnBqhHpoEWA180gMbaCtdX9Pl6BWBAuuP2miadoTNM=
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240813155151-d112a28d382f h1:xrJqsXOZeSkBFMSyN+PQ9DiCGxVULU3VIN/tuH/vtb8=
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240813155151-d112a28d382f/go.mod h1:mc7j6Cc1GU1tJZNmDwEYiJJ339biNnU1Bz3wZGogMe0=
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240819074700-a43110e36326 h1:TkH+NSsY4C/Z8MocIJyMcqLm5vEhZcSowOldJyilKKA=
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240819074700-a43110e36326/go.mod h1:zZnHiRv9m5+ESYLhBXY9Jds9A/YIDEUGiuyPUS09HwM=
git.frostfs.info/TrueCloudLab/frostfs-contract v0.19.3-0.20240621131249-49e5270f673e h1:kcBqZBiFIUBATUqEuvVigtkJJWQ2Gug/eYXn967o3M4=
git.frostfs.info/TrueCloudLab/frostfs-contract v0.19.3-0.20240621131249-49e5270f673e/go.mod h1:F/fe1OoIDKr5Bz99q4sriuHDuf3aZefZy9ZsCqEtgxc=
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSVCB8JNSfPG7Uk4r2oSk=
@ -10,8 +10,8 @@ git.frostfs.info/TrueCloudLab/frostfs-locode-db v0.4.1-0.20240710074952-65761deb
git.frostfs.info/TrueCloudLab/frostfs-locode-db v0.4.1-0.20240710074952-65761deb5c0d/go.mod h1:7ZZq8iguY7qFsXajdHGmZd2AW4QbucyrJwhbsRfOfek=
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65 h1:PaZ8GpnUoXxUoNsc1qp36bT2u7FU+neU4Jn9cl8AWqI=
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65/go.mod h1:6aAX80dvJ3r5fjN9CzzPglRptoiPgIC9KFGGsUA+1Hw=
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240813155821-98aabc45a720 h1:15UXpW42bfshIv/X5kww92jG2o0drHgsdFd+UJ6zD7g=
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240813155821-98aabc45a720/go.mod h1:XRX/bBQsDJKr040N/a0YnDhxJqaUv1XyMVj3qxnb5K0=
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240820072028-6dd7be11d13b h1:ZCJBVmQDcdv0twpX9xJU/AQwX+dXyvVfqr0Pq3x+3yk=
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240820072028-6dd7be11d13b/go.mod h1:aaC2OR34tVrBwd0Z2gqoN5WLtV/idKqpqPDhb4XqmCo=
git.frostfs.info/TrueCloudLab/hrw v1.2.1 h1:ccBRK21rFvY5R1WotI6LNoPlizk7qSvdfD8lNIRudVc=
git.frostfs.info/TrueCloudLab/hrw v1.2.1/go.mod h1:C1Ygde2n843yTZEQ0FP69jYiuaYV0kriLvP4zm8JuvM=
git.frostfs.info/TrueCloudLab/neoneo-go v0.106.1-0.20240726093631-5481339d6928 h1:LK3mCkNZkY48eBA9jnk1N0eQZLsZhOG+XYw4EBoKUjM=
@ -25,6 +25,8 @@ git.frostfs.info/TrueCloudLab/tzhash v1.8.0/go.mod h1:dhY+oy274hV8wGvGL4MwwMpdL3
git.frostfs.info/TrueCloudLab/zapjournald v0.0.0-20240124114243-cb2e66427d02 h1:HeY8n27VyPRQe49l/fzyVMkWEB2fsLJYKp64pwA7tz4=
git.frostfs.info/TrueCloudLab/zapjournald v0.0.0-20240124114243-cb2e66427d02/go.mod h1:rQFJJdEOV7KbbMtQYR2lNfiZk+ONRDJSbMCTWxKt8Fw=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/VictoriaMetrics/easyproto v0.1.4 h1:r8cNvo8o6sR4QShBXQd1bKw/VVLSQma/V2KhTBPf+Sc=
github.com/VictoriaMetrics/easyproto v0.1.4/go.mod h1:QlGlzaJnDfFd8Lk6Ci/fuLxfTo3/GThPs2KH23mv710=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=

View file

@ -1,6 +1,7 @@
package meta
import (
"bytes"
"context"
"fmt"
"time"
@ -107,7 +108,7 @@ func (db *DB) get(tx *bbolt.Tx, addr oid.Address, key []byte, checkStatus, raw b
// check in primary index
data := getFromBucket(tx, primaryBucketName(cnr, bucketName), key)
if len(data) != 0 {
return obj, obj.Unmarshal(data)
return obj, obj.Unmarshal(bytes.Clone(data))
}
data = getFromBucket(tx, ecInfoBucketName(cnr, bucketName), key)
@ -118,13 +119,13 @@ func (db *DB) get(tx *bbolt.Tx, addr oid.Address, key []byte, checkStatus, raw b
// if not found then check in tombstone index
data = getFromBucket(tx, tombstoneBucketName(cnr, bucketName), key)
if len(data) != 0 {
return obj, obj.Unmarshal(data)
return obj, obj.Unmarshal(bytes.Clone(data))
}
// if not found then check in locker index
data = getFromBucket(tx, bucketNameLockers(cnr, bucketName), key)
if len(data) != 0 {
return obj, obj.Unmarshal(data)
return obj, obj.Unmarshal(bytes.Clone(data))
}
// if not found then check if object is a virtual

View file

@ -1,33 +0,0 @@
package control_test
import (
"crypto/rand"
"testing"
"github.com/mr-tron/base58"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)
type protoMessage interface {
StableMarshal([]byte) []byte
proto.Message
}
func testStableMarshal(t *testing.T, m1, m2 protoMessage, cmp func(m1, m2 protoMessage) bool) {
require.NoError(t, proto.Unmarshal(m1.StableMarshal(nil), m2))
require.True(t, cmp(m1, m2))
}
func testData(sz int) []byte {
d := make([]byte, sz)
_, _ = rand.Read(d)
return d
}
func testString() string {
return base58.Encode(testData(10))
}

View file

@ -1,46 +0,0 @@
package control
// SetBody sets health check request body.
func (x *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetHealthStatus sets health status of the IR application.
func (x *HealthCheckResponse_Body) SetHealthStatus(v HealthStatus) {
if x != nil {
x.HealthStatus = v
}
}
// SetBody sets health check response body.
func (x *HealthCheckResponse) SetBody(v *HealthCheckResponse_Body) {
if x != nil {
x.Body = v
}
}
func (x *TickEpochRequest) SetBody(v *TickEpochRequest_Body) {
if x != nil {
x.Body = v
}
}
func (x *TickEpochResponse) SetBody(v *TickEpochResponse_Body) {
if x != nil {
x.Body = v
}
}
func (x *RemoveNodeRequest) SetBody(v *RemoveNodeRequest_Body) {
if x != nil {
x.Body = v
}
}
func (x *RemoveNodeResponse) SetBody(v *RemoveNodeResponse_Body) {
if x != nil {
x.Body = v
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,44 +0,0 @@
package control_test
import (
"testing"
control "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)
type protoMessage interface {
StableMarshal([]byte) []byte
proto.Message
}
func testStableMarshal(t *testing.T, m1, m2 protoMessage, cmp func(m1, m2 protoMessage) bool) {
require.NoError(t, proto.Unmarshal(m1.StableMarshal(nil), m2))
require.True(t, cmp(m1, m2))
}
func TestHealthCheckResponse_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateHealthCheckResponseBody(),
new(control.HealthCheckResponse_Body),
func(m1, m2 protoMessage) bool {
return equalHealthCheckResponseBodies(
m1.(*control.HealthCheckResponse_Body),
m2.(*control.HealthCheckResponse_Body),
)
},
)
}
func generateHealthCheckResponseBody() *control.HealthCheckResponse_Body {
body := new(control.HealthCheckResponse_Body)
body.SetHealthStatus(control.HealthStatus_SHUTTING_DOWN)
return body
}
func equalHealthCheckResponseBodies(b1, b2 *control.HealthCheckResponse_Body) bool {
return b1.GetHealthStatus() == b2.GetHealthStatus()
}

View file

@ -1,15 +0,0 @@
package control
// SetKey sets public key used for signing.
func (x *Signature) SetKey(v []byte) {
if x != nil {
x.Key = v
}
}
// SetSign sets binary signature.
func (x *Signature) SetSign(v []byte) {
if x != nil {
x.Sign = v
}
}

View file

@ -1,230 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.33.0
// protoc v4.25.0
// source: pkg/services/control/ir/types.proto
package control
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// Health status of the IR application.
type HealthStatus int32
const (
// Undefined status, default value.
HealthStatus_HEALTH_STATUS_UNDEFINED HealthStatus = 0
// IR application is starting.
HealthStatus_STARTING HealthStatus = 1
// IR application is started and serves all services.
HealthStatus_READY HealthStatus = 2
// IR application is shutting down.
HealthStatus_SHUTTING_DOWN HealthStatus = 3
// IR application is reconfiguring.
HealthStatus_RECONFIGURING HealthStatus = 4
)
// Enum value maps for HealthStatus.
var (
HealthStatus_name = map[int32]string{
0: "HEALTH_STATUS_UNDEFINED",
1: "STARTING",
2: "READY",
3: "SHUTTING_DOWN",
4: "RECONFIGURING",
}
HealthStatus_value = map[string]int32{
"HEALTH_STATUS_UNDEFINED": 0,
"STARTING": 1,
"READY": 2,
"SHUTTING_DOWN": 3,
"RECONFIGURING": 4,
}
)
func (x HealthStatus) Enum() *HealthStatus {
p := new(HealthStatus)
*p = x
return p
}
func (x HealthStatus) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (HealthStatus) Descriptor() protoreflect.EnumDescriptor {
return file_pkg_services_control_ir_types_proto_enumTypes[0].Descriptor()
}
func (HealthStatus) Type() protoreflect.EnumType {
return &file_pkg_services_control_ir_types_proto_enumTypes[0]
}
func (x HealthStatus) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use HealthStatus.Descriptor instead.
func (HealthStatus) EnumDescriptor() ([]byte, []int) {
return file_pkg_services_control_ir_types_proto_rawDescGZIP(), []int{0}
}
// Signature of some message.
type Signature struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Public key used for signing.
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
// Binary signature.
Sign []byte `protobuf:"bytes,2,opt,name=sign,json=signature,proto3" json:"sign,omitempty"`
}
func (x *Signature) Reset() {
*x = Signature{}
if protoimpl.UnsafeEnabled {
mi := &file_pkg_services_control_ir_types_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Signature) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Signature) ProtoMessage() {}
func (x *Signature) ProtoReflect() protoreflect.Message {
mi := &file_pkg_services_control_ir_types_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Signature.ProtoReflect.Descriptor instead.
func (*Signature) Descriptor() ([]byte, []int) {
return file_pkg_services_control_ir_types_proto_rawDescGZIP(), []int{0}
}
func (x *Signature) GetKey() []byte {
if x != nil {
return x.Key
}
return nil
}
func (x *Signature) GetSign() []byte {
if x != nil {
return x.Sign
}
return nil
}
var File_pkg_services_control_ir_types_proto protoreflect.FileDescriptor
var file_pkg_services_control_ir_types_proto_rawDesc = []byte{
0x0a, 0x23, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x63,
0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2f, 0x69, 0x72, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x69, 0x72, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
0x22, 0x36, 0x0a, 0x09, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x10, 0x0a,
0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12,
0x17, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73,
0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x2a, 0x6a, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x6c,
0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1b, 0x0a, 0x17, 0x48, 0x45, 0x41, 0x4c,
0x54, 0x48, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49,
0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x53, 0x54, 0x41, 0x52, 0x54, 0x49, 0x4e,
0x47, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x52, 0x45, 0x41, 0x44, 0x59, 0x10, 0x02, 0x12, 0x11,
0x0a, 0x0d, 0x53, 0x48, 0x55, 0x54, 0x54, 0x49, 0x4e, 0x47, 0x5f, 0x44, 0x4f, 0x57, 0x4e, 0x10,
0x03, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x45, 0x43, 0x4f, 0x4e, 0x46, 0x49, 0x47, 0x55, 0x52, 0x49,
0x4e, 0x47, 0x10, 0x04, 0x42, 0x44, 0x5a, 0x42, 0x67, 0x69, 0x74, 0x2e, 0x66, 0x72, 0x6f, 0x73,
0x74, 0x66, 0x73, 0x2e, 0x69, 0x6e, 0x66, 0x6f, 0x2f, 0x54, 0x72, 0x75, 0x65, 0x43, 0x6c, 0x6f,
0x75, 0x64, 0x4c, 0x61, 0x62, 0x2f, 0x66, 0x72, 0x6f, 0x73, 0x74, 0x66, 0x73, 0x2d, 0x6e, 0x6f,
0x64, 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f,
0x69, 0x72, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
}
var (
file_pkg_services_control_ir_types_proto_rawDescOnce sync.Once
file_pkg_services_control_ir_types_proto_rawDescData = file_pkg_services_control_ir_types_proto_rawDesc
)
func file_pkg_services_control_ir_types_proto_rawDescGZIP() []byte {
file_pkg_services_control_ir_types_proto_rawDescOnce.Do(func() {
file_pkg_services_control_ir_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_services_control_ir_types_proto_rawDescData)
})
return file_pkg_services_control_ir_types_proto_rawDescData
}
var file_pkg_services_control_ir_types_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_pkg_services_control_ir_types_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_pkg_services_control_ir_types_proto_goTypes = []interface{}{
(HealthStatus)(0), // 0: ircontrol.HealthStatus
(*Signature)(nil), // 1: ircontrol.Signature
}
var file_pkg_services_control_ir_types_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_pkg_services_control_ir_types_proto_init() }
func file_pkg_services_control_ir_types_proto_init() {
if File_pkg_services_control_ir_types_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_pkg_services_control_ir_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Signature); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_pkg_services_control_ir_types_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_pkg_services_control_ir_types_proto_goTypes,
DependencyIndexes: file_pkg_services_control_ir_types_proto_depIdxs,
EnumInfos: file_pkg_services_control_ir_types_proto_enumTypes,
MessageInfos: file_pkg_services_control_ir_types_proto_msgTypes,
}.Build()
File_pkg_services_control_ir_types_proto = out.File
file_pkg_services_control_ir_types_proto_rawDesc = nil
file_pkg_services_control_ir_types_proto_goTypes = nil
file_pkg_services_control_ir_types_proto_depIdxs = nil
}

View file

@ -2,7 +2,70 @@
package control
import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
import (
json "encoding/json"
fmt "fmt"
pool "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/pool"
proto "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
encoding "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/encoding"
easyproto "github.com/VictoriaMetrics/easyproto"
jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter"
strconv "strconv"
)
type HealthStatus int32
const (
HealthStatus_HEALTH_STATUS_UNDEFINED HealthStatus = 0
HealthStatus_STARTING HealthStatus = 1
HealthStatus_READY HealthStatus = 2
HealthStatus_SHUTTING_DOWN HealthStatus = 3
HealthStatus_RECONFIGURING HealthStatus = 4
)
var (
HealthStatus_name = map[int32]string{
0: "HEALTH_STATUS_UNDEFINED",
1: "STARTING",
2: "READY",
3: "SHUTTING_DOWN",
4: "RECONFIGURING",
}
HealthStatus_value = map[string]int32{
"HEALTH_STATUS_UNDEFINED": 0,
"STARTING": 1,
"READY": 2,
"SHUTTING_DOWN": 3,
"RECONFIGURING": 4,
}
)
func (x HealthStatus) String() string {
if v, ok := HealthStatus_name[int32(x)]; ok {
return v
}
return strconv.FormatInt(int64(x), 10)
}
func (x *HealthStatus) FromString(s string) bool {
if v, ok := HealthStatus_value[s]; ok {
*x = HealthStatus(v)
return true
}
return false
}
type Signature struct {
Key []byte `json:"key"`
Sign []byte `json:"signature"`
}
var (
_ encoding.ProtoMarshaler = (*Signature)(nil)
_ encoding.ProtoUnmarshaler = (*Signature)(nil)
_ json.Marshaler = (*Signature)(nil)
_ json.Unmarshaler = (*Signature)(nil)
)
// StableSize returns the size of x in protobuf format.
//
@ -16,23 +79,138 @@ func (x *Signature) StableSize() (size int) {
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// 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 *Signature) StableMarshal(buf []byte) []byte {
// MarshalProtobuf implements the encoding.ProtoMarshaler interface.
func (x *Signature) MarshalProtobuf(dst []byte) []byte {
m := pool.MarshalerPool.Get()
defer pool.MarshalerPool.Put(m)
x.EmitProtobuf(m.MessageMarshaler())
dst = m.Marshal(dst)
return dst
}
func (x *Signature) EmitProtobuf(mm *easyproto.MessageMarshaler) {
if x == nil {
return []byte{}
return
}
if buf == nil {
buf = make([]byte, x.StableSize())
if len(x.Key) != 0 {
mm.AppendBytes(1, x.Key)
}
if len(x.Sign) != 0 {
mm.AppendBytes(2, x.Sign)
}
}
// UnmarshalProtobuf implements the encoding.ProtoUnmarshaler interface.
func (x *Signature) UnmarshalProtobuf(src []byte) (err error) {
var fc easyproto.FieldContext
for len(src) > 0 {
src, err = fc.NextField(src)
if err != nil {
return fmt.Errorf("cannot read next field in %s", "Signature")
}
switch fc.FieldNum {
case 1: // Key
data, ok := fc.Bytes()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "Key")
}
x.Key = data
case 2: // Sign
data, ok := fc.Bytes()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "Sign")
}
x.Sign = data
}
}
return nil
}
func (x *Signature) GetKey() []byte {
if x != nil {
return x.Key
}
return nil
}
func (x *Signature) SetKey(v []byte) {
x.Key = v
}
func (x *Signature) GetSign() []byte {
if x != nil {
return x.Sign
}
return nil
}
func (x *Signature) SetSign(v []byte) {
x.Sign = v
}
// MarshalJSON implements the json.Marshaler interface.
func (x *Signature) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
x.MarshalEasyJSON(&w)
return w.Buffer.BuildBytes(), w.Error
}
func (x *Signature) MarshalEasyJSON(out *jwriter.Writer) {
if x == nil {
out.RawString("null")
return
}
out.RawByte('{')
{
const prefix string = ",\"key\":"
out.RawString(prefix[1:])
out.Base64Bytes(x.Key)
}
{
const prefix string = ",\"signature\":"
out.RawString(prefix)
out.Base64Bytes(x.Sign)
}
out.RawByte('}')
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (x *Signature) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
x.UnmarshalEasyJSON(&r)
return r.Error()
}
func (x *Signature) UnmarshalEasyJSON(in *jlexer.Lexer) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "key":
{
var f []byte
f = in.Bytes()
x.Key = f
}
case "signature":
{
var f []byte
f = in.Bytes()
x.Sign = f
}
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
var offset int
offset += proto.BytesMarshal(1, buf[offset:], x.Key)
offset += proto.BytesMarshal(2, buf[offset:], x.Sign)
return buf
}

View file

@ -30,10 +30,10 @@ func (s *Server) ListShards(_ context.Context, req *control.ListShardsRequest) (
for _, sh := range info.Shards {
si := new(control.ShardInfo)
si.SetID(*sh.ID)
si.SetShard_ID(*sh.ID)
si.SetMetabasePath(sh.MetaBaseInfo.Path)
si.Blobstor = blobstorInfoToProto(sh.BlobStorInfo)
si.SetWriteCachePath(sh.WriteCacheInfo.Path)
si.SetWritecachePath(sh.WriteCacheInfo.Path)
si.SetPiloramaPath(sh.PiloramaInfo.Path)
var m control.ShardMode

View file

@ -1,142 +0,0 @@
package control
// SetBody sets health check request body.
func (x *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetNetmapStatus sets status of the storage node in FrostFS network map.
func (x *HealthCheckResponse_Body) SetNetmapStatus(v NetmapStatus) {
if x != nil {
x.NetmapStatus = v
}
}
// SetHealthStatus sets health status of the storage node application.
func (x *HealthCheckResponse_Body) SetHealthStatus(v HealthStatus) {
if x != nil {
x.HealthStatus = v
}
}
// SetBody sets health check response body.
func (x *HealthCheckResponse) SetBody(v *HealthCheckResponse_Body) {
if x != nil {
x.Body = v
}
}
// SetStatus sets new storage node status in FrostFS network map.
func (x *SetNetmapStatusRequest_Body) SetStatus(v NetmapStatus) {
if x != nil {
x.Status = v
}
}
// SetForceMaintenance sets force_maintenance flag in the message.
func (x *SetNetmapStatusRequest_Body) SetForceMaintenance() {
x.ForceMaintenance = true
}
// SetBody sets body of the set netmap status request .
func (x *SetNetmapStatusRequest) SetBody(v *SetNetmapStatusRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetBody sets set body of the netmap status response.
func (x *SetNetmapStatusResponse) SetBody(v *SetNetmapStatusResponse_Body) {
if x != nil {
x.Body = v
}
}
// SetAddressList sets list of objects to be removed in FrostFS API binary format.
func (x *DropObjectsRequest_Body) SetAddressList(v [][]byte) {
if x != nil {
x.AddressList = v
}
}
// SetBody sets body of the set "Drop objects" request.
func (x *DropObjectsRequest) SetBody(v *DropObjectsRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetBody sets set body of the "Drop objects" response.
func (x *DropObjectsResponse) SetBody(v *DropObjectsResponse_Body) {
if x != nil {
x.Body = v
}
}
// SetBody sets list shards request body.
func (x *ListShardsRequest) SetBody(v *ListShardsRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetShards sets shards of the storage node.
func (x *ListShardsResponse_Body) SetShards(v []*ShardInfo) {
if x != nil {
x.Shards = v
}
}
// SetBody sets list shards response body.
func (x *ListShardsResponse) SetBody(v *ListShardsResponse_Body) {
if x != nil {
x.Body = v
}
}
// SetShardIDList sets shard ID whose mode is requested to be set.
func (x *SetShardModeRequest_Body) SetShardIDList(v [][]byte) {
if v != nil {
x.Shard_ID = v
}
}
// SetMode sets mode of the shard.
func (x *SetShardModeRequest_Body) SetMode(v ShardMode) {
x.Mode = v
}
// ClearErrorCounter sets flag signifying whether error counter for shard should be cleared.
func (x *SetShardModeRequest_Body) ClearErrorCounter(reset bool) {
x.ResetErrorCounter = reset
}
// SetBody sets request body.
func (x *SetShardModeRequest) SetBody(v *SetShardModeRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetBody sets body of the set shard mode response.
func (x *SetShardModeResponse) SetBody(v *SetShardModeResponse_Body) {
if x != nil {
x.Body = v
}
}
// SetBody sets list shards request body.
func (x *SynchronizeTreeRequest) SetBody(v *SynchronizeTreeRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetBody sets list shards response body.
func (x *SynchronizeTreeResponse) SetBody(v *SynchronizeTreeResponse_Body) {
if x != nil {
x.Body = v
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,181 +0,0 @@
package control_test
import (
"bytes"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
)
func TestHealthCheckResponse_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateHealthCheckResponseBody(),
new(control.HealthCheckResponse_Body),
func(m1, m2 protoMessage) bool {
return equalHealthCheckResponseBodies(
m1.(*control.HealthCheckResponse_Body),
m2.(*control.HealthCheckResponse_Body),
)
},
)
}
func generateHealthCheckResponseBody() *control.HealthCheckResponse_Body {
body := new(control.HealthCheckResponse_Body)
body.SetNetmapStatus(control.NetmapStatus_ONLINE)
body.SetHealthStatus(control.HealthStatus_SHUTTING_DOWN)
return body
}
func equalHealthCheckResponseBodies(b1, b2 *control.HealthCheckResponse_Body) bool {
return b1.GetNetmapStatus() == b2.GetNetmapStatus() &&
b1.GetHealthStatus() == b2.GetHealthStatus()
}
func TestSetNetmapStatusRequest_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateSetNetmapStatusRequestBody(),
new(control.SetNetmapStatusRequest_Body),
func(m1, m2 protoMessage) bool {
return equalSetnetmapStatusRequestBodies(
m1.(*control.SetNetmapStatusRequest_Body),
m2.(*control.SetNetmapStatusRequest_Body),
)
},
)
}
func generateSetNetmapStatusRequestBody() *control.SetNetmapStatusRequest_Body {
body := new(control.SetNetmapStatusRequest_Body)
body.SetStatus(control.NetmapStatus_ONLINE)
return body
}
func equalSetnetmapStatusRequestBodies(b1, b2 *control.SetNetmapStatusRequest_Body) bool {
return b1.GetStatus() == b2.GetStatus()
}
func TestListShardsResponse_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateListShardsResponseBody(),
new(control.ListShardsResponse_Body),
func(m1, m2 protoMessage) bool {
return equalListShardResponseBodies(
m1.(*control.ListShardsResponse_Body),
m2.(*control.ListShardsResponse_Body),
)
},
)
}
func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool {
if len(b1.Shards) != len(b2.Shards) {
return false
}
for i := range b1.Shards {
if b1.Shards[i].GetMetabasePath() != b2.Shards[i].GetMetabasePath() ||
b1.Shards[i].GetWritecachePath() != b2.Shards[i].GetWritecachePath() ||
b1.Shards[i].GetPiloramaPath() != b2.Shards[i].GetPiloramaPath() ||
!bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[i].GetShard_ID()) {
return false
}
info1 := b1.Shards[i].GetBlobstor()
info2 := b2.Shards[i].GetBlobstor()
if !compareBlobstorInfo(info1, info2) {
return false
}
}
for i := range b1.Shards {
for j := i + 1; j < len(b1.Shards); j++ {
if b1.Shards[i].GetMetabasePath() == b2.Shards[j].GetMetabasePath() ||
!compareBlobstorInfo(b1.Shards[i].Blobstor, b2.Shards[i].Blobstor) ||
b1.Shards[i].GetWritecachePath() == b2.Shards[j].GetWritecachePath() ||
bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[j].GetShard_ID()) {
return false
}
}
}
return true
}
func compareBlobstorInfo(a, b []*control.BlobstorInfo) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i].Type != b[i].Type ||
a[i].Path != b[i].Path {
return false
}
}
return true
}
func generateListShardsResponseBody() *control.ListShardsResponse_Body {
body := new(control.ListShardsResponse_Body)
body.SetShards([]*control.ShardInfo{
generateShardInfo(0),
generateShardInfo(1),
})
return body
}
func TestSetShardModeRequest_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateSetShardModeRequestBody(),
new(control.SetShardModeRequest_Body),
func(m1, m2 protoMessage) bool {
return equalSetShardModeRequestBodies(
m1.(*control.SetShardModeRequest_Body),
m2.(*control.SetShardModeRequest_Body),
)
},
)
}
func generateSetShardModeRequestBody() *control.SetShardModeRequest_Body {
body := new(control.SetShardModeRequest_Body)
body.SetShardIDList([][]byte{{0, 1, 2, 3, 4}})
body.SetMode(control.ShardMode_READ_WRITE)
return body
}
func equalSetShardModeRequestBodies(b1, b2 *control.SetShardModeRequest_Body) bool {
if b1.GetMode() != b2.GetMode() || len(b1.Shard_ID) != len(b2.Shard_ID) {
return false
}
for i := range b1.Shard_ID {
if !bytes.Equal(b1.Shard_ID[i], b2.Shard_ID[i]) {
return false
}
}
return true
}
func TestSynchronizeTreeRequest_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
&control.SynchronizeTreeRequest_Body{
ContainerId: []byte{1, 2, 3, 4, 5, 6, 7},
TreeId: "someID",
Height: 42,
},
new(control.SynchronizeTreeRequest_Body),
func(m1, m2 protoMessage) bool {
b1 := m1.(*control.SynchronizeTreeRequest_Body)
b2 := m2.(*control.SynchronizeTreeRequest_Body)
return bytes.Equal(b1.GetContainerId(), b2.GetContainerId()) &&
b1.GetTreeId() == b2.GetTreeId() &&
b1.GetHeight() == b2.GetHeight()
},
)
}

View file

@ -1,118 +0,0 @@
package control
import (
"google.golang.org/protobuf/encoding/protojson"
)
// SetKey sets public key used for signing.
func (x *Signature) SetKey(v []byte) {
if x != nil {
x.Key = v
}
}
// SetSign sets binary signature.
func (x *Signature) SetSign(v []byte) {
if x != nil {
x.Sign = v
}
}
// SetKey sets key of the node attribute.
func (x *NodeInfo_Attribute) SetKey(v string) {
if x != nil {
x.Key = v
}
}
// SetValue sets value of the node attribute.
func (x *NodeInfo_Attribute) SetValue(v string) {
if x != nil {
x.Value = v
}
}
// SetParents sets parent keys.
func (x *NodeInfo_Attribute) SetParents(v []string) {
if x != nil {
x.Parents = v
}
}
// SetPublicKey sets public key of the FrostFS node in a binary format.
func (x *NodeInfo) SetPublicKey(v []byte) {
if x != nil {
x.PublicKey = v
}
}
// SetAddresses sets ways to connect to a node.
func (x *NodeInfo) SetAddresses(v []string) {
if x != nil {
x.Addresses = v
}
}
// SetAttributes sets attributes of the FrostFS Storage Node.
func (x *NodeInfo) SetAttributes(v []*NodeInfo_Attribute) {
if x != nil {
x.Attributes = v
}
}
// SetState sets state of the FrostFS node.
func (x *NodeInfo) SetState(v NetmapStatus) {
if x != nil {
x.State = v
}
}
// SetEpoch sets revision number of the network map.
func (x *Netmap) SetEpoch(v uint64) {
if x != nil {
x.Epoch = v
}
}
// SetNodes sets nodes presented in network.
func (x *Netmap) SetNodes(v []*NodeInfo) {
if x != nil {
x.Nodes = v
}
}
func (x *Netmap) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(x)
}
// SetID sets identificator of the shard.
func (x *ShardInfo) SetID(v []byte) {
x.Shard_ID = v
}
// SetMetabasePath sets path to shard's metabase.
func (x *ShardInfo) SetMetabasePath(v string) {
x.MetabasePath = v
}
// SetWriteCachePath sets path to shard's write-cache.
func (x *ShardInfo) SetWriteCachePath(v string) {
x.WritecachePath = v
}
// SetPiloramaPath sets path to shard's pilorama.
func (x *ShardInfo) SetPiloramaPath(v string) {
x.PiloramaPath = v
}
// SetMode sets path to shard's work mode.
func (x *ShardInfo) SetMode(v ShardMode) {
x.Mode = v
}
// SetErrorCount sets shard's error counter.
func (x *ShardInfo) SetErrorCount(count uint32) {
x.ErrorCount = count
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,151 +0,0 @@
package control_test
import (
"bytes"
"path/filepath"
"strconv"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/google/uuid"
)
func TestNetmap_StableMarshal(t *testing.T) {
testStableMarshal(t, generateNetmap(), new(control.Netmap), func(m1, m2 protoMessage) bool {
return equalNetmaps(m1.(*control.Netmap), m2.(*control.Netmap))
})
}
func generateNetmap() *control.Netmap {
nm := new(control.Netmap)
nm.SetEpoch(13)
const nodeCount = 2
nodes := make([]*control.NodeInfo, 0, nodeCount)
for i := 0; i < nodeCount; i++ {
n := new(control.NodeInfo)
n.SetPublicKey(testData(33))
n.SetAddresses([]string{testString(), testString()})
n.SetState(control.NetmapStatus_ONLINE)
const attrCount = 2
attrs := make([]*control.NodeInfo_Attribute, 0, attrCount)
for j := 0; j < attrCount; j++ {
a := new(control.NodeInfo_Attribute)
a.SetKey(testString())
a.SetValue(testString())
const parentsCount = 2
parents := make([]string, 0, parentsCount)
for k := 0; k < parentsCount; k++ {
parents = append(parents, testString())
}
a.SetParents(parents)
attrs = append(attrs, a)
}
n.SetAttributes(attrs)
nodes = append(nodes, n)
}
nm.SetNodes(nodes)
return nm
}
func equalNetmaps(nm1, nm2 *control.Netmap) bool {
if nm1.GetEpoch() != nm2.GetEpoch() {
return false
}
n1, n2 := nm1.GetNodes(), nm2.GetNodes()
if len(n1) != len(n2) {
return false
}
for i := range n1 {
if !equalNodeInfos(n1[i], n2[i]) {
return false
}
}
return true
}
func equalNodeInfos(n1, n2 *control.NodeInfo) bool {
if !bytes.Equal(n1.GetPublicKey(), n2.GetPublicKey()) ||
n1.GetState() != n2.GetState() {
return false
}
na1, na2 := n1.GetAddresses(), n2.GetAddresses()
if len(na1) != len(na2) {
return false
}
for i := range na1 {
if na1[i] != na2[i] {
return false
}
}
a1, a2 := n1.GetAttributes(), n2.GetAttributes()
if len(a1) != len(a2) {
return false
}
for i := range a1 {
if a1[i].GetKey() != a2[i].GetKey() || a1[i].GetValue() != a2[i].GetValue() {
return false
}
p1, p2 := a1[i].GetParents(), a2[i].GetParents()
if len(p1) != len(p2) {
return false
}
for j := range p1 {
if p1[j] != p2[j] {
return false
}
}
}
return true
}
func generateShardInfo(id int) *control.ShardInfo {
si := new(control.ShardInfo)
path := "/nice/dir/awesome/files/" + strconv.Itoa(id)
uid, _ := uuid.NewRandom()
bin, _ := uid.MarshalBinary()
si.SetID(bin)
si.SetMode(control.ShardMode_READ_WRITE)
si.SetMetabasePath(filepath.Join(path, "meta"))
si.Blobstor = []*control.BlobstorInfo{
{Type: fstree.Type, Path: filepath.Join(path, "fstree")},
{Type: blobovniczatree.Type, Path: filepath.Join(path, "blobtree")},
}
si.SetWriteCachePath(filepath.Join(path, "writecache"))
si.SetPiloramaPath(filepath.Join(path, "pilorama"))
return si
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,320 +0,0 @@
//*
// Auxiliary structures to use with tree service.
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.33.0
// protoc v4.25.0
// source: pkg/services/tree/types.proto
package tree
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// KeyValue represents key-value pair attached to an object.
type KeyValue struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Attribute name.
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
// Attribute value.
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
}
func (x *KeyValue) Reset() {
*x = KeyValue{}
if protoimpl.UnsafeEnabled {
mi := &file_pkg_services_tree_types_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *KeyValue) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*KeyValue) ProtoMessage() {}
func (x *KeyValue) ProtoReflect() protoreflect.Message {
mi := &file_pkg_services_tree_types_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use KeyValue.ProtoReflect.Descriptor instead.
func (*KeyValue) Descriptor() ([]byte, []int) {
return file_pkg_services_tree_types_proto_rawDescGZIP(), []int{0}
}
func (x *KeyValue) GetKey() string {
if x != nil {
return x.Key
}
return ""
}
func (x *KeyValue) GetValue() []byte {
if x != nil {
return x.Value
}
return nil
}
// LogMove represents log-entry for a single move operation.
type LogMove struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// ID of the parent node.
ParentId uint64 `protobuf:"varint,1,opt,name=parent_id,json=parentID,proto3" json:"parent_id,omitempty"`
// Node meta information, including operation timestamp.
Meta []byte `protobuf:"bytes,2,opt,name=meta,proto3" json:"meta,omitempty"`
// ID of the node to move.
ChildId uint64 `protobuf:"varint,3,opt,name=child_id,json=childID,proto3" json:"child_id,omitempty"`
}
func (x *LogMove) Reset() {
*x = LogMove{}
if protoimpl.UnsafeEnabled {
mi := &file_pkg_services_tree_types_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LogMove) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LogMove) ProtoMessage() {}
func (x *LogMove) ProtoReflect() protoreflect.Message {
mi := &file_pkg_services_tree_types_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LogMove.ProtoReflect.Descriptor instead.
func (*LogMove) Descriptor() ([]byte, []int) {
return file_pkg_services_tree_types_proto_rawDescGZIP(), []int{1}
}
func (x *LogMove) GetParentId() uint64 {
if x != nil {
return x.ParentId
}
return 0
}
func (x *LogMove) GetMeta() []byte {
if x != nil {
return x.Meta
}
return nil
}
func (x *LogMove) GetChildId() uint64 {
if x != nil {
return x.ChildId
}
return 0
}
// Signature of a message.
type Signature struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Serialized public key as defined in FrostFS API.
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
// Signature of a message body.
Sign []byte `protobuf:"bytes,2,opt,name=sign,json=signature,proto3" json:"sign,omitempty"`
}
func (x *Signature) Reset() {
*x = Signature{}
if protoimpl.UnsafeEnabled {
mi := &file_pkg_services_tree_types_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Signature) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Signature) ProtoMessage() {}
func (x *Signature) ProtoReflect() protoreflect.Message {
mi := &file_pkg_services_tree_types_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Signature.ProtoReflect.Descriptor instead.
func (*Signature) Descriptor() ([]byte, []int) {
return file_pkg_services_tree_types_proto_rawDescGZIP(), []int{2}
}
func (x *Signature) GetKey() []byte {
if x != nil {
return x.Key
}
return nil
}
func (x *Signature) GetSign() []byte {
if x != nil {
return x.Sign
}
return nil
}
var File_pkg_services_tree_types_proto protoreflect.FileDescriptor
var file_pkg_services_tree_types_proto_rawDesc = []byte{
0x0a, 0x1d, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x74,
0x72, 0x65, 0x65, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
0x04, 0x74, 0x72, 0x65, 0x65, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75,
0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x55, 0x0a, 0x07, 0x4c, 0x6f, 0x67,
0x4d, 0x6f, 0x76, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x69,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49,
0x44, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x65, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52,
0x04, 0x6d, 0x65, 0x74, 0x61, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x5f, 0x69,
0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x49, 0x44,
0x22, 0x36, 0x0a, 0x09, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x10, 0x0a,
0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12,
0x17, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73,
0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x42, 0x3e, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x2e,
0x66, 0x72, 0x6f, 0x73, 0x74, 0x66, 0x73, 0x2e, 0x69, 0x6e, 0x66, 0x6f, 0x2f, 0x54, 0x72, 0x75,
0x65, 0x43, 0x6c, 0x6f, 0x75, 0x64, 0x4c, 0x61, 0x62, 0x2f, 0x66, 0x72, 0x6f, 0x73, 0x74, 0x66,
0x73, 0x2d, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x73, 0x2f, 0x74, 0x72, 0x65, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_pkg_services_tree_types_proto_rawDescOnce sync.Once
file_pkg_services_tree_types_proto_rawDescData = file_pkg_services_tree_types_proto_rawDesc
)
func file_pkg_services_tree_types_proto_rawDescGZIP() []byte {
file_pkg_services_tree_types_proto_rawDescOnce.Do(func() {
file_pkg_services_tree_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_services_tree_types_proto_rawDescData)
})
return file_pkg_services_tree_types_proto_rawDescData
}
var file_pkg_services_tree_types_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_pkg_services_tree_types_proto_goTypes = []interface{}{
(*KeyValue)(nil), // 0: tree.KeyValue
(*LogMove)(nil), // 1: tree.LogMove
(*Signature)(nil), // 2: tree.Signature
}
var file_pkg_services_tree_types_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_pkg_services_tree_types_proto_init() }
func file_pkg_services_tree_types_proto_init() {
if File_pkg_services_tree_types_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_pkg_services_tree_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*KeyValue); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_pkg_services_tree_types_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LogMove); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_pkg_services_tree_types_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Signature); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_pkg_services_tree_types_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_pkg_services_tree_types_proto_goTypes,
DependencyIndexes: file_pkg_services_tree_types_proto_depIdxs,
MessageInfos: file_pkg_services_tree_types_proto_msgTypes,
}.Build()
File_pkg_services_tree_types_proto = out.File
file_pkg_services_tree_types_proto_rawDesc = nil
file_pkg_services_tree_types_proto_goTypes = nil
file_pkg_services_tree_types_proto_depIdxs = nil
}

View file

@ -2,7 +2,28 @@
package tree
import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
import (
json "encoding/json"
fmt "fmt"
pool "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/pool"
proto "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
encoding "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/encoding"
easyproto "github.com/VictoriaMetrics/easyproto"
jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter"
)
type KeyValue struct {
Key string `json:"key"`
Value []byte `json:"value"`
}
var (
_ encoding.ProtoMarshaler = (*KeyValue)(nil)
_ encoding.ProtoUnmarshaler = (*KeyValue)(nil)
_ json.Marshaler = (*KeyValue)(nil)
_ json.Unmarshaler = (*KeyValue)(nil)
)
// StableSize returns the size of x in protobuf format.
//
@ -16,26 +37,154 @@ func (x *KeyValue) StableSize() (size int) {
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// 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 *KeyValue) StableMarshal(buf []byte) []byte {
// MarshalProtobuf implements the encoding.ProtoMarshaler interface.
func (x *KeyValue) MarshalProtobuf(dst []byte) []byte {
m := pool.MarshalerPool.Get()
defer pool.MarshalerPool.Put(m)
x.EmitProtobuf(m.MessageMarshaler())
dst = m.Marshal(dst)
return dst
}
func (x *KeyValue) EmitProtobuf(mm *easyproto.MessageMarshaler) {
if x == nil {
return []byte{}
return
}
if buf == nil {
buf = make([]byte, x.StableSize())
if len(x.Key) != 0 {
mm.AppendString(1, x.Key)
}
var offset int
offset += proto.StringMarshal(1, buf[offset:], x.Key)
offset += proto.BytesMarshal(2, buf[offset:], x.Value)
return buf
if len(x.Value) != 0 {
mm.AppendBytes(2, x.Value)
}
}
// UnmarshalProtobuf implements the encoding.ProtoUnmarshaler interface.
func (x *KeyValue) UnmarshalProtobuf(src []byte) (err error) {
var fc easyproto.FieldContext
for len(src) > 0 {
src, err = fc.NextField(src)
if err != nil {
return fmt.Errorf("cannot read next field in %s", "KeyValue")
}
switch fc.FieldNum {
case 1: // Key
data, ok := fc.String()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "Key")
}
x.Key = data
case 2: // Value
data, ok := fc.Bytes()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "Value")
}
x.Value = data
}
}
return nil
}
func (x *KeyValue) GetKey() string {
if x != nil {
return x.Key
}
return ""
}
func (x *KeyValue) SetKey(v string) {
x.Key = v
}
func (x *KeyValue) GetValue() []byte {
if x != nil {
return x.Value
}
return nil
}
func (x *KeyValue) SetValue(v []byte) {
x.Value = v
}
// MarshalJSON implements the json.Marshaler interface.
func (x *KeyValue) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
x.MarshalEasyJSON(&w)
return w.Buffer.BuildBytes(), w.Error
}
func (x *KeyValue) MarshalEasyJSON(out *jwriter.Writer) {
if x == nil {
out.RawString("null")
return
}
out.RawByte('{')
{
const prefix string = ",\"key\":"
out.RawString(prefix[1:])
out.String(x.Key)
}
{
const prefix string = ",\"value\":"
out.RawString(prefix)
out.Base64Bytes(x.Value)
}
out.RawByte('}')
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (x *KeyValue) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
x.UnmarshalEasyJSON(&r)
return r.Error()
}
func (x *KeyValue) UnmarshalEasyJSON(in *jlexer.Lexer) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "key":
{
var f string
f = in.String()
x.Key = f
}
case "value":
{
var f []byte
f = in.Bytes()
x.Value = f
}
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
type LogMove struct {
ParentId uint64 `json:"parentID"`
Meta []byte `json:"meta"`
ChildId uint64 `json:"childID"`
}
var (
_ encoding.ProtoMarshaler = (*LogMove)(nil)
_ encoding.ProtoUnmarshaler = (*LogMove)(nil)
_ json.Marshaler = (*LogMove)(nil)
_ json.Unmarshaler = (*LogMove)(nil)
)
// StableSize returns the size of x in protobuf format.
//
@ -50,27 +199,182 @@ func (x *LogMove) StableSize() (size int) {
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// 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 *LogMove) StableMarshal(buf []byte) []byte {
// MarshalProtobuf implements the encoding.ProtoMarshaler interface.
func (x *LogMove) MarshalProtobuf(dst []byte) []byte {
m := pool.MarshalerPool.Get()
defer pool.MarshalerPool.Put(m)
x.EmitProtobuf(m.MessageMarshaler())
dst = m.Marshal(dst)
return dst
}
func (x *LogMove) EmitProtobuf(mm *easyproto.MessageMarshaler) {
if x == nil {
return []byte{}
return
}
if buf == nil {
buf = make([]byte, x.StableSize())
if x.ParentId != 0 {
mm.AppendUint64(1, x.ParentId)
}
var offset int
offset += proto.UInt64Marshal(1, buf[offset:], x.ParentId)
offset += proto.BytesMarshal(2, buf[offset:], x.Meta)
offset += proto.UInt64Marshal(3, buf[offset:], x.ChildId)
return buf
if len(x.Meta) != 0 {
mm.AppendBytes(2, x.Meta)
}
if x.ChildId != 0 {
mm.AppendUint64(3, x.ChildId)
}
}
// UnmarshalProtobuf implements the encoding.ProtoUnmarshaler interface.
func (x *LogMove) UnmarshalProtobuf(src []byte) (err error) {
var fc easyproto.FieldContext
for len(src) > 0 {
src, err = fc.NextField(src)
if err != nil {
return fmt.Errorf("cannot read next field in %s", "LogMove")
}
switch fc.FieldNum {
case 1: // ParentId
data, ok := fc.Uint64()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "ParentId")
}
x.ParentId = data
case 2: // Meta
data, ok := fc.Bytes()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "Meta")
}
x.Meta = data
case 3: // ChildId
data, ok := fc.Uint64()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "ChildId")
}
x.ChildId = data
}
}
return nil
}
func (x *LogMove) GetParentId() uint64 {
if x != nil {
return x.ParentId
}
return 0
}
func (x *LogMove) SetParentId(v uint64) {
x.ParentId = v
}
func (x *LogMove) GetMeta() []byte {
if x != nil {
return x.Meta
}
return nil
}
func (x *LogMove) SetMeta(v []byte) {
x.Meta = v
}
func (x *LogMove) GetChildId() uint64 {
if x != nil {
return x.ChildId
}
return 0
}
func (x *LogMove) SetChildId(v uint64) {
x.ChildId = v
}
// MarshalJSON implements the json.Marshaler interface.
func (x *LogMove) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
x.MarshalEasyJSON(&w)
return w.Buffer.BuildBytes(), w.Error
}
func (x *LogMove) MarshalEasyJSON(out *jwriter.Writer) {
if x == nil {
out.RawString("null")
return
}
out.RawByte('{')
{
const prefix string = ",\"parentID\":"
out.RawString(prefix[1:])
out.Uint64(x.ParentId)
}
{
const prefix string = ",\"meta\":"
out.RawString(prefix)
out.Base64Bytes(x.Meta)
}
{
const prefix string = ",\"childID\":"
out.RawString(prefix)
out.Uint64(x.ChildId)
}
out.RawByte('}')
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (x *LogMove) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
x.UnmarshalEasyJSON(&r)
return r.Error()
}
func (x *LogMove) UnmarshalEasyJSON(in *jlexer.Lexer) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "parentID":
{
var f uint64
f = in.Uint64()
x.ParentId = f
}
case "meta":
{
var f []byte
f = in.Bytes()
x.Meta = f
}
case "childID":
{
var f uint64
f = in.Uint64()
x.ChildId = f
}
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
type Signature struct {
Key []byte `json:"key"`
Sign []byte `json:"signature"`
}
var (
_ encoding.ProtoMarshaler = (*Signature)(nil)
_ encoding.ProtoUnmarshaler = (*Signature)(nil)
_ json.Marshaler = (*Signature)(nil)
_ json.Unmarshaler = (*Signature)(nil)
)
// StableSize returns the size of x in protobuf format.
//
@ -84,23 +388,138 @@ func (x *Signature) StableSize() (size int) {
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// 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 *Signature) StableMarshal(buf []byte) []byte {
// MarshalProtobuf implements the encoding.ProtoMarshaler interface.
func (x *Signature) MarshalProtobuf(dst []byte) []byte {
m := pool.MarshalerPool.Get()
defer pool.MarshalerPool.Put(m)
x.EmitProtobuf(m.MessageMarshaler())
dst = m.Marshal(dst)
return dst
}
func (x *Signature) EmitProtobuf(mm *easyproto.MessageMarshaler) {
if x == nil {
return []byte{}
return
}
if buf == nil {
buf = make([]byte, x.StableSize())
if len(x.Key) != 0 {
mm.AppendBytes(1, x.Key)
}
if len(x.Sign) != 0 {
mm.AppendBytes(2, x.Sign)
}
}
// UnmarshalProtobuf implements the encoding.ProtoUnmarshaler interface.
func (x *Signature) UnmarshalProtobuf(src []byte) (err error) {
var fc easyproto.FieldContext
for len(src) > 0 {
src, err = fc.NextField(src)
if err != nil {
return fmt.Errorf("cannot read next field in %s", "Signature")
}
switch fc.FieldNum {
case 1: // Key
data, ok := fc.Bytes()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "Key")
}
x.Key = data
case 2: // Sign
data, ok := fc.Bytes()
if !ok {
return fmt.Errorf("cannot unmarshal field %s", "Sign")
}
x.Sign = data
}
}
return nil
}
func (x *Signature) GetKey() []byte {
if x != nil {
return x.Key
}
return nil
}
func (x *Signature) SetKey(v []byte) {
x.Key = v
}
func (x *Signature) GetSign() []byte {
if x != nil {
return x.Sign
}
return nil
}
func (x *Signature) SetSign(v []byte) {
x.Sign = v
}
// MarshalJSON implements the json.Marshaler interface.
func (x *Signature) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
x.MarshalEasyJSON(&w)
return w.Buffer.BuildBytes(), w.Error
}
func (x *Signature) MarshalEasyJSON(out *jwriter.Writer) {
if x == nil {
out.RawString("null")
return
}
out.RawByte('{')
{
const prefix string = ",\"key\":"
out.RawString(prefix[1:])
out.Base64Bytes(x.Key)
}
{
const prefix string = ",\"signature\":"
out.RawString(prefix)
out.Base64Bytes(x.Sign)
}
out.RawByte('}')
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (x *Signature) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
x.UnmarshalEasyJSON(&r)
return r.Error()
}
func (x *Signature) UnmarshalEasyJSON(in *jlexer.Lexer) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "key":
{
var f []byte
f = in.Bytes()
x.Key = f
}
case "signature":
{
var f []byte
f = in.Bytes()
x.Sign = f
}
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
var offset int
offset += proto.BytesMarshal(1, buf[offset:], x.Key)
offset += proto.BytesMarshal(2, buf[offset:], x.Sign)
return buf
}