From ecf0f09c4d4443829b98cbacd4db222c81e41d63 Mon Sep 17 00:00:00 2001 From: yfh Date: Mon, 24 Feb 2025 22:46:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20et=5Frpc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- et_rpc/go.mod | 15 + et_rpc/go.sum | 32 + et_rpc/pb/et_rpc.pb.go | 1147 ++++++++++++++++++++++ et_rpc/pb/et_rpc_grpc.pb.go | 349 +++++++ et_rpc/proto/et_rpc.proto | 124 +++ et_rpc/proto/go-protobuf生成帮助.txt | 58 ++ et_rpc/rpc.go | 22 + et_rpc/rpc_test.go | 57 ++ 8 files changed, 1804 insertions(+) create mode 100644 et_rpc/go.mod create mode 100644 et_rpc/go.sum create mode 100644 et_rpc/pb/et_rpc.pb.go create mode 100644 et_rpc/pb/et_rpc_grpc.pb.go create mode 100644 et_rpc/proto/et_rpc.proto create mode 100644 et_rpc/proto/go-protobuf生成帮助.txt create mode 100644 et_rpc/rpc.go create mode 100644 et_rpc/rpc_test.go diff --git a/et_rpc/go.mod b/et_rpc/go.mod new file mode 100644 index 0000000..7e3ff73 --- /dev/null +++ b/et_rpc/go.mod @@ -0,0 +1,15 @@ +module et_rpc + +go 1.23.1 + +require ( + google.golang.org/grpc v1.69.4 + google.golang.org/protobuf v1.36.2 +) + +require ( + golang.org/x/net v0.30.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect +) diff --git a/et_rpc/go.sum b/et_rpc/go.sum new file mode 100644 index 0000000..2dddd44 --- /dev/null +++ b/et_rpc/go.sum @@ -0,0 +1,32 @@ +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= +go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk= +go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0= +go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc= +go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A= +google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4= +google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU= +google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= diff --git a/et_rpc/pb/et_rpc.pb.go b/et_rpc/pb/et_rpc.pb.go new file mode 100644 index 0000000..f28eff1 --- /dev/null +++ b/et_rpc/pb/et_rpc.pb.go @@ -0,0 +1,1147 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.2 +// protoc v5.26.1 +// source: et_rpc.proto + +package pb + +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) +) + +// 枚举定义 +type NodeState int32 + +const ( + NodeState_UNKNOWN NodeState = 0 + NodeState_ACTIVE NodeState = 1 + NodeState_INACTIVE NodeState = 2 +) + +// Enum value maps for NodeState. +var ( + NodeState_name = map[int32]string{ + 0: "UNKNOWN", + 1: "ACTIVE", + 2: "INACTIVE", + } + NodeState_value = map[string]int32{ + "UNKNOWN": 0, + "ACTIVE": 1, + "INACTIVE": 2, + } +) + +func (x NodeState) Enum() *NodeState { + p := new(NodeState) + *p = x + return p +} + +func (x NodeState) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (NodeState) Descriptor() protoreflect.EnumDescriptor { + return file_et_rpc_proto_enumTypes[0].Descriptor() +} + +func (NodeState) Type() protoreflect.EnumType { + return &file_et_rpc_proto_enumTypes[0] +} + +func (x NodeState) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use NodeState.Descriptor instead. +func (NodeState) EnumDescriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{0} +} + +type RPCReplyCode int32 + +const ( + RPCReplyCode_SUCCESS RPCReplyCode = 0 + RPCReplyCode_FAILURE RPCReplyCode = 1 +) + +// Enum value maps for RPCReplyCode. +var ( + RPCReplyCode_name = map[int32]string{ + 0: "SUCCESS", + 1: "FAILURE", + } + RPCReplyCode_value = map[string]int32{ + "SUCCESS": 0, + "FAILURE": 1, + } +) + +func (x RPCReplyCode) Enum() *RPCReplyCode { + p := new(RPCReplyCode) + *p = x + return p +} + +func (x RPCReplyCode) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (RPCReplyCode) Descriptor() protoreflect.EnumDescriptor { + return file_et_rpc_proto_enumTypes[1].Descriptor() +} + +func (RPCReplyCode) Type() protoreflect.EnumType { + return &file_et_rpc_proto_enumTypes[1] +} + +func (x RPCReplyCode) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use RPCReplyCode.Descriptor instead. +func (RPCReplyCode) EnumDescriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{1} +} + +type RpcResponse_Status int32 + +const ( + RpcResponse_SUCCESS RpcResponse_Status = 0 // 请求成功 + RpcResponse_FAILURE RpcResponse_Status = 1 // 请求失败 + RpcResponse_INVALID_ARGUMENT RpcResponse_Status = 2 // 无效参数 + RpcResponse_NOT_FOUND RpcResponse_Status = 3 // 未找到 + RpcResponse_INTERNAL_ERROR RpcResponse_Status = 4 // 内部错误 +) + +// Enum value maps for RpcResponse_Status. +var ( + RpcResponse_Status_name = map[int32]string{ + 0: "SUCCESS", + 1: "FAILURE", + 2: "INVALID_ARGUMENT", + 3: "NOT_FOUND", + 4: "INTERNAL_ERROR", + } + RpcResponse_Status_value = map[string]int32{ + "SUCCESS": 0, + "FAILURE": 1, + "INVALID_ARGUMENT": 2, + "NOT_FOUND": 3, + "INTERNAL_ERROR": 4, + } +) + +func (x RpcResponse_Status) Enum() *RpcResponse_Status { + p := new(RpcResponse_Status) + *p = x + return p +} + +func (x RpcResponse_Status) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (RpcResponse_Status) Descriptor() protoreflect.EnumDescriptor { + return file_et_rpc_proto_enumTypes[2].Descriptor() +} + +func (RpcResponse_Status) Type() protoreflect.EnumType { + return &file_et_rpc_proto_enumTypes[2] +} + +func (x RpcResponse_Status) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use RpcResponse_Status.Descriptor instead. +func (RpcResponse_Status) EnumDescriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{8, 0} +} + +type HandleDataResponse_Status int32 + +const ( + HandleDataResponse_SUCCESS HandleDataResponse_Status = 0 // 请求成功 + HandleDataResponse_FAILURE HandleDataResponse_Status = 1 // 请求失败 + HandleDataResponse_INVALID_ARGUMENT HandleDataResponse_Status = 2 // 无效参数 + HandleDataResponse_INTERNAL_ERROR HandleDataResponse_Status = 4 // 内部错误 +) + +// Enum value maps for HandleDataResponse_Status. +var ( + HandleDataResponse_Status_name = map[int32]string{ + 0: "SUCCESS", + 1: "FAILURE", + 2: "INVALID_ARGUMENT", + 4: "INTERNAL_ERROR", + } + HandleDataResponse_Status_value = map[string]int32{ + "SUCCESS": 0, + "FAILURE": 1, + "INVALID_ARGUMENT": 2, + "INTERNAL_ERROR": 4, + } +) + +func (x HandleDataResponse_Status) Enum() *HandleDataResponse_Status { + p := new(HandleDataResponse_Status) + *p = x + return p +} + +func (x HandleDataResponse_Status) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (HandleDataResponse_Status) Descriptor() protoreflect.EnumDescriptor { + return file_et_rpc_proto_enumTypes[3].Descriptor() +} + +func (HandleDataResponse_Status) Type() protoreflect.EnumType { + return &file_et_rpc_proto_enumTypes[3] +} + +func (x HandleDataResponse_Status) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use HandleDataResponse_Status.Descriptor instead. +func (HandleDataResponse_Status) EnumDescriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{9, 0} +} + +type NodeArgs struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // 节点ID + Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` // 节点地址 + Load int32 `protobuf:"varint,3,opt,name=load,proto3" json:"load,omitempty"` // 节点荷载 + ResourceJson string `protobuf:"bytes,4,opt,name=resource_json,json=resourceJson,proto3" json:"resource_json,omitempty"` // 资源使用情况JSON + Weight int32 `protobuf:"varint,5,opt,name=weight,proto3" json:"weight,omitempty"` // 权重 + Status NodeState `protobuf:"varint,6,opt,name=status,proto3,enum=et_rpc.NodeState" json:"status,omitempty"` // 节点状态 + ErrCode RPCReplyCode `protobuf:"varint,7,opt,name=err_code,json=errCode,proto3,enum=et_rpc.RPCReplyCode" json:"err_code,omitempty"` // 错误代码 + ErrMessage string `protobuf:"bytes,8,opt,name=err_message,json=errMessage,proto3" json:"err_message,omitempty"` // 错误信息 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NodeArgs) Reset() { + *x = NodeArgs{} + mi := &file_et_rpc_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NodeArgs) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NodeArgs) ProtoMessage() {} + +func (x *NodeArgs) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NodeArgs.ProtoReflect.Descriptor instead. +func (*NodeArgs) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{0} +} + +func (x *NodeArgs) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *NodeArgs) GetAddr() string { + if x != nil { + return x.Addr + } + return "" +} + +func (x *NodeArgs) GetLoad() int32 { + if x != nil { + return x.Load + } + return 0 +} + +func (x *NodeArgs) GetResourceJson() string { + if x != nil { + return x.ResourceJson + } + return "" +} + +func (x *NodeArgs) GetWeight() int32 { + if x != nil { + return x.Weight + } + return 0 +} + +func (x *NodeArgs) GetStatus() NodeState { + if x != nil { + return x.Status + } + return NodeState_UNKNOWN +} + +func (x *NodeArgs) GetErrCode() RPCReplyCode { + if x != nil { + return x.ErrCode + } + return RPCReplyCode_SUCCESS +} + +func (x *NodeArgs) GetErrMessage() string { + if x != nil { + return x.ErrMessage + } + return "" +} + +type NodeResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` + ErrCode RPCReplyCode `protobuf:"varint,3,opt,name=err_code,json=errCode,proto3,enum=et_rpc.RPCReplyCode" json:"err_code,omitempty"` + ErrMessage string `protobuf:"bytes,4,opt,name=err_message,json=errMessage,proto3" json:"err_message,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NodeResponse) Reset() { + *x = NodeResponse{} + mi := &file_et_rpc_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NodeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NodeResponse) ProtoMessage() {} + +func (x *NodeResponse) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NodeResponse.ProtoReflect.Descriptor instead. +func (*NodeResponse) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{1} +} + +func (x *NodeResponse) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *NodeResponse) GetAddr() string { + if x != nil { + return x.Addr + } + return "" +} + +func (x *NodeResponse) GetErrCode() RPCReplyCode { + if x != nil { + return x.ErrCode + } + return RPCReplyCode_SUCCESS +} + +func (x *NodeResponse) GetErrMessage() string { + if x != nil { + return x.ErrMessage + } + return "" +} + +type NodeRegistrationRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + NodeId string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` + NodeAddr string `protobuf:"bytes,2,opt,name=node_addr,json=nodeAddr,proto3" json:"node_addr,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NodeRegistrationRequest) Reset() { + *x = NodeRegistrationRequest{} + mi := &file_et_rpc_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NodeRegistrationRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NodeRegistrationRequest) ProtoMessage() {} + +func (x *NodeRegistrationRequest) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NodeRegistrationRequest.ProtoReflect.Descriptor instead. +func (*NodeRegistrationRequest) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{2} +} + +func (x *NodeRegistrationRequest) GetNodeId() string { + if x != nil { + return x.NodeId + } + return "" +} + +func (x *NodeRegistrationRequest) GetNodeAddr() string { + if x != nil { + return x.NodeAddr + } + return "" +} + +type NodeStatusRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + NodeId string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NodeStatusRequest) Reset() { + *x = NodeStatusRequest{} + mi := &file_et_rpc_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NodeStatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NodeStatusRequest) ProtoMessage() {} + +func (x *NodeStatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NodeStatusRequest.ProtoReflect.Descriptor instead. +func (*NodeStatusRequest) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{3} +} + +func (x *NodeStatusRequest) GetNodeId() string { + if x != nil { + return x.NodeId + } + return "" +} + +type NodeStatusResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + NodeId string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` + Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"` // 例如 "active", "inactive" + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NodeStatusResponse) Reset() { + *x = NodeStatusResponse{} + mi := &file_et_rpc_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NodeStatusResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NodeStatusResponse) ProtoMessage() {} + +func (x *NodeStatusResponse) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NodeStatusResponse.ProtoReflect.Descriptor instead. +func (*NodeStatusResponse) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{4} +} + +func (x *NodeStatusResponse) GetNodeId() string { + if x != nil { + return x.NodeId + } + return "" +} + +func (x *NodeStatusResponse) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +// 定义键值对消息 +type KeyValue struct { + state protoimpl.MessageState `protogen:"open.v1"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` // 键 + Value float64 `protobuf:"fixed64,2,opt,name=value,proto3" json:"value,omitempty"` // 值 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *KeyValue) Reset() { + *x = KeyValue{} + mi := &file_et_rpc_proto_msgTypes[5] + 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_et_rpc_proto_msgTypes[5] + if 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_et_rpc_proto_rawDescGZIP(), []int{5} +} + +func (x *KeyValue) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *KeyValue) GetValue() float64 { + if x != nil { + return x.Value + } + return 0 +} + +// 定义AggData消息 +type AggData struct { + state protoimpl.MessageState `protogen:"open.v1"` + Date string `protobuf:"bytes,1,opt,name=date,proto3" json:"date,omitempty"` // 使用protobuf的时间戳类型 + SensorId int32 `protobuf:"varint,2,opt,name=sensor_id,json=sensorId,proto3" json:"sensor_id,omitempty"` // SensorId + StructId int32 `protobuf:"varint,3,opt,name=struct_id,json=structId,proto3" json:"struct_id,omitempty"` // StructId + FactorId int32 `protobuf:"varint,4,opt,name=factor_id,json=factorId,proto3" json:"factor_id,omitempty"` // FactorId + AggTypeId int32 `protobuf:"varint,5,opt,name=agg_type_id,json=aggTypeId,proto3" json:"agg_type_id,omitempty"` // 聚集类型 + AggMethodId int32 `protobuf:"varint,6,opt,name=agg_method_id,json=aggMethodId,proto3" json:"agg_method_id,omitempty"` // 聚集方法 + Agg []*KeyValue `protobuf:"bytes,7,rep,name=agg,proto3" json:"agg,omitempty"` // 聚集数据 + Changed []*KeyValue `protobuf:"bytes,8,rep,name=changed,proto3" json:"changed,omitempty"` // 变化量 + ThingId string `protobuf:"bytes,9,opt,name=thing_id,json=thingId,proto3" json:"thing_id,omitempty"` // ThingId + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AggData) Reset() { + *x = AggData{} + mi := &file_et_rpc_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AggData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AggData) ProtoMessage() {} + +func (x *AggData) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AggData.ProtoReflect.Descriptor instead. +func (*AggData) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{6} +} + +func (x *AggData) GetDate() string { + if x != nil { + return x.Date + } + return "" +} + +func (x *AggData) GetSensorId() int32 { + if x != nil { + return x.SensorId + } + return 0 +} + +func (x *AggData) GetStructId() int32 { + if x != nil { + return x.StructId + } + return 0 +} + +func (x *AggData) GetFactorId() int32 { + if x != nil { + return x.FactorId + } + return 0 +} + +func (x *AggData) GetAggTypeId() int32 { + if x != nil { + return x.AggTypeId + } + return 0 +} + +func (x *AggData) GetAggMethodId() int32 { + if x != nil { + return x.AggMethodId + } + return 0 +} + +func (x *AggData) GetAgg() []*KeyValue { + if x != nil { + return x.Agg + } + return nil +} + +func (x *AggData) GetChanged() []*KeyValue { + if x != nil { + return x.Changed + } + return nil +} + +func (x *AggData) GetThingId() string { + if x != nil { + return x.ThingId + } + return "" +} + +type NodeRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + ThingIds []string `protobuf:"bytes,3,rep,name=thing_ids,json=thingIds,proto3" json:"thing_ids,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NodeRequest) Reset() { + *x = NodeRequest{} + mi := &file_et_rpc_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NodeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NodeRequest) ProtoMessage() {} + +func (x *NodeRequest) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NodeRequest.ProtoReflect.Descriptor instead. +func (*NodeRequest) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{7} +} + +func (x *NodeRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *NodeRequest) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + +func (x *NodeRequest) GetThingIds() []string { + if x != nil { + return x.ThingIds + } + return nil +} + +type RpcResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Status RpcResponse_Status `protobuf:"varint,1,opt,name=status,proto3,enum=et_rpc.RpcResponse_Status" json:"status,omitempty"` // 请求状态 + ErrorMessage string `protobuf:"bytes,2,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"` // 错误信息,如果请求失败则返回具体的错误信息 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RpcResponse) Reset() { + *x = RpcResponse{} + mi := &file_et_rpc_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RpcResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RpcResponse) ProtoMessage() {} + +func (x *RpcResponse) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[8] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RpcResponse.ProtoReflect.Descriptor instead. +func (*RpcResponse) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{8} +} + +func (x *RpcResponse) GetStatus() RpcResponse_Status { + if x != nil { + return x.Status + } + return RpcResponse_SUCCESS +} + +func (x *RpcResponse) GetErrorMessage() string { + if x != nil { + return x.ErrorMessage + } + return "" +} + +type HandleDataResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Addr string `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` // 节点地址 + Load int32 `protobuf:"varint,2,opt,name=load,proto3" json:"load,omitempty"` // 节点荷载 + Status HandleDataResponse_Status `protobuf:"varint,3,opt,name=status,proto3,enum=et_rpc.HandleDataResponse_Status" json:"status,omitempty"` // 请求状态 + ErrorMessage string `protobuf:"bytes,4,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"` // 错误信息,如果请求失败则返回具体的错误信息 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *HandleDataResponse) Reset() { + *x = HandleDataResponse{} + mi := &file_et_rpc_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *HandleDataResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HandleDataResponse) ProtoMessage() {} + +func (x *HandleDataResponse) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[9] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HandleDataResponse.ProtoReflect.Descriptor instead. +func (*HandleDataResponse) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{9} +} + +func (x *HandleDataResponse) GetAddr() string { + if x != nil { + return x.Addr + } + return "" +} + +func (x *HandleDataResponse) GetLoad() int32 { + if x != nil { + return x.Load + } + return 0 +} + +func (x *HandleDataResponse) GetStatus() HandleDataResponse_Status { + if x != nil { + return x.Status + } + return HandleDataResponse_SUCCESS +} + +func (x *HandleDataResponse) GetErrorMessage() string { + if x != nil { + return x.ErrorMessage + } + return "" +} + +type HandleDataRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Messages []string `protobuf:"bytes,2,rep,name=messages,proto3" json:"messages,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *HandleDataRequest) Reset() { + *x = HandleDataRequest{} + mi := &file_et_rpc_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *HandleDataRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HandleDataRequest) ProtoMessage() {} + +func (x *HandleDataRequest) ProtoReflect() protoreflect.Message { + mi := &file_et_rpc_proto_msgTypes[10] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HandleDataRequest.ProtoReflect.Descriptor instead. +func (*HandleDataRequest) Descriptor() ([]byte, []int) { + return file_et_rpc_proto_rawDescGZIP(), []int{10} +} + +func (x *HandleDataRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *HandleDataRequest) GetMessages() []string { + if x != nil { + return x.Messages + } + return nil +} + +var File_et_rpc_proto protoreflect.FileDescriptor + +var file_et_rpc_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, + 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x22, 0xfc, 0x01, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x41, + 0x72, 0x67, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x6f, 0x61, 0x64, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x72, + 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4a, 0x73, 0x6f, 0x6e, + 0x12, 0x16, 0x0a, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x29, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x11, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, + 0x63, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x06, 0x73, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x12, 0x2f, 0x0a, 0x08, 0x65, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x52, + 0x50, 0x43, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x07, 0x65, 0x72, 0x72, + 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x65, 0x72, 0x72, 0x4d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x84, 0x01, 0x0a, 0x0c, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x2f, 0x0a, 0x08, 0x65, 0x72, + 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x65, + 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x50, 0x43, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x43, 0x6f, + 0x64, 0x65, 0x52, 0x07, 0x65, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x65, + 0x72, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x65, 0x72, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x4f, 0x0a, 0x17, + 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, + 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x41, 0x64, 0x64, 0x72, 0x22, 0x2c, 0x0a, + 0x11, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x22, 0x45, 0x0a, 0x12, 0x4e, + 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 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, 0x01, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0xa3, 0x02, 0x0a, 0x07, 0x41, 0x67, 0x67, 0x44, 0x61, + 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x6e, 0x73, 0x6f, 0x72, + 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x73, 0x65, 0x6e, 0x73, 0x6f, + 0x72, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x49, 0x64, + 0x12, 0x1b, 0x0a, 0x09, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x08, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, + 0x0b, 0x61, 0x67, 0x67, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x09, 0x61, 0x67, 0x67, 0x54, 0x79, 0x70, 0x65, 0x49, 0x64, 0x12, 0x22, 0x0a, + 0x0d, 0x61, 0x67, 0x67, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x61, 0x67, 0x67, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x49, + 0x64, 0x12, 0x22, 0x0a, 0x03, 0x61, 0x67, 0x67, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, + 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, + 0x52, 0x03, 0x61, 0x67, 0x67, 0x12, 0x2a, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, + 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, + 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x64, 0x12, 0x19, 0x0a, 0x08, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x22, 0x54, 0x0a, 0x0b, + 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x5f, 0x69, + 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x49, + 0x64, 0x73, 0x22, 0xc3, 0x01, 0x0a, 0x0b, 0x52, 0x70, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x32, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0e, 0x32, 0x1a, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x5b, 0x0a, 0x06, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, + 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x41, 0x49, 0x4c, 0x55, 0x52, 0x45, 0x10, 0x01, 0x12, + 0x14, 0x0a, 0x10, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49, 0x44, 0x5f, 0x41, 0x52, 0x47, 0x55, 0x4d, + 0x45, 0x4e, 0x54, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x4e, 0x4f, 0x54, 0x5f, 0x46, 0x4f, 0x55, + 0x4e, 0x44, 0x10, 0x03, 0x12, 0x12, 0x0a, 0x0e, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, + 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x04, 0x22, 0xea, 0x01, 0x0a, 0x12, 0x48, 0x61, 0x6e, + 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, + 0x64, 0x64, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x04, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x39, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, + 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x4c, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x00, 0x12, 0x0b, + 0x0a, 0x07, 0x46, 0x41, 0x49, 0x4c, 0x55, 0x52, 0x45, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x49, + 0x4e, 0x56, 0x41, 0x4c, 0x49, 0x44, 0x5f, 0x41, 0x52, 0x47, 0x55, 0x4d, 0x45, 0x4e, 0x54, 0x10, + 0x02, 0x12, 0x12, 0x0a, 0x0e, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x5f, 0x45, 0x52, + 0x52, 0x4f, 0x52, 0x10, 0x04, 0x22, 0x3f, 0x0a, 0x11, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, + 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2a, 0x32, 0x0a, 0x09, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, + 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x43, 0x54, 0x49, 0x56, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, + 0x49, 0x4e, 0x41, 0x43, 0x54, 0x49, 0x56, 0x45, 0x10, 0x02, 0x2a, 0x28, 0x0a, 0x0c, 0x52, 0x50, + 0x43, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, + 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x41, 0x49, 0x4c, 0x55, + 0x52, 0x45, 0x10, 0x01, 0x32, 0x9e, 0x01, 0x0a, 0x0b, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x0e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x49, 0x6f, + 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x12, 0x19, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, + 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1a, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, + 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x46, 0x0a, + 0x0d, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x41, 0x67, 0x67, 0x44, 0x61, 0x74, 0x61, 0x12, 0x19, + 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, + 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x65, 0x74, 0x5f, 0x72, + 0x70, 0x63, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xc0, 0x01, 0x0a, 0x0d, 0x4d, 0x61, 0x73, 0x74, 0x65, 0x72, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x38, 0x0a, 0x0c, 0x52, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x13, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, + 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x65, + 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x39, 0x0a, 0x0d, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x4e, 0x6f, + 0x64, 0x65, 0x12, 0x13, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x4e, 0x6f, 0x64, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, + 0x2e, 0x52, 0x70, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x0e, + 0x55, 0x6e, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x13, + 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x65, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x05, 0x5a, 0x03, 0x2f, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_et_rpc_proto_rawDescOnce sync.Once + file_et_rpc_proto_rawDescData = file_et_rpc_proto_rawDesc +) + +func file_et_rpc_proto_rawDescGZIP() []byte { + file_et_rpc_proto_rawDescOnce.Do(func() { + file_et_rpc_proto_rawDescData = protoimpl.X.CompressGZIP(file_et_rpc_proto_rawDescData) + }) + return file_et_rpc_proto_rawDescData +} + +var file_et_rpc_proto_enumTypes = make([]protoimpl.EnumInfo, 4) +var file_et_rpc_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_et_rpc_proto_goTypes = []any{ + (NodeState)(0), // 0: et_rpc.NodeState + (RPCReplyCode)(0), // 1: et_rpc.RPCReplyCode + (RpcResponse_Status)(0), // 2: et_rpc.RpcResponse.Status + (HandleDataResponse_Status)(0), // 3: et_rpc.HandleDataResponse.Status + (*NodeArgs)(nil), // 4: et_rpc.NodeArgs + (*NodeResponse)(nil), // 5: et_rpc.NodeResponse + (*NodeRegistrationRequest)(nil), // 6: et_rpc.NodeRegistrationRequest + (*NodeStatusRequest)(nil), // 7: et_rpc.NodeStatusRequest + (*NodeStatusResponse)(nil), // 8: et_rpc.NodeStatusResponse + (*KeyValue)(nil), // 9: et_rpc.KeyValue + (*AggData)(nil), // 10: et_rpc.AggData + (*NodeRequest)(nil), // 11: et_rpc.NodeRequest + (*RpcResponse)(nil), // 12: et_rpc.RpcResponse + (*HandleDataResponse)(nil), // 13: et_rpc.HandleDataResponse + (*HandleDataRequest)(nil), // 14: et_rpc.HandleDataRequest +} +var file_et_rpc_proto_depIdxs = []int32{ + 0, // 0: et_rpc.NodeArgs.status:type_name -> et_rpc.NodeState + 1, // 1: et_rpc.NodeArgs.err_code:type_name -> et_rpc.RPCReplyCode + 1, // 2: et_rpc.NodeResponse.err_code:type_name -> et_rpc.RPCReplyCode + 9, // 3: et_rpc.AggData.agg:type_name -> et_rpc.KeyValue + 9, // 4: et_rpc.AggData.changed:type_name -> et_rpc.KeyValue + 2, // 5: et_rpc.RpcResponse.status:type_name -> et_rpc.RpcResponse.Status + 3, // 6: et_rpc.HandleDataResponse.status:type_name -> et_rpc.HandleDataResponse.Status + 14, // 7: et_rpc.NodeService.HandleIotaData:input_type -> et_rpc.HandleDataRequest + 14, // 8: et_rpc.NodeService.HandleAggData:input_type -> et_rpc.HandleDataRequest + 11, // 9: et_rpc.MasterService.RegisterNode:input_type -> et_rpc.NodeRequest + 11, // 10: et_rpc.MasterService.HeartbeatNode:input_type -> et_rpc.NodeRequest + 11, // 11: et_rpc.MasterService.UnregisterNode:input_type -> et_rpc.NodeRequest + 13, // 12: et_rpc.NodeService.HandleIotaData:output_type -> et_rpc.HandleDataResponse + 13, // 13: et_rpc.NodeService.HandleAggData:output_type -> et_rpc.HandleDataResponse + 12, // 14: et_rpc.MasterService.RegisterNode:output_type -> et_rpc.RpcResponse + 12, // 15: et_rpc.MasterService.HeartbeatNode:output_type -> et_rpc.RpcResponse + 12, // 16: et_rpc.MasterService.UnregisterNode:output_type -> et_rpc.RpcResponse + 12, // [12:17] is the sub-list for method output_type + 7, // [7:12] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_et_rpc_proto_init() } +func file_et_rpc_proto_init() { + if File_et_rpc_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_et_rpc_proto_rawDesc, + NumEnums: 4, + NumMessages: 11, + NumExtensions: 0, + NumServices: 2, + }, + GoTypes: file_et_rpc_proto_goTypes, + DependencyIndexes: file_et_rpc_proto_depIdxs, + EnumInfos: file_et_rpc_proto_enumTypes, + MessageInfos: file_et_rpc_proto_msgTypes, + }.Build() + File_et_rpc_proto = out.File + file_et_rpc_proto_rawDesc = nil + file_et_rpc_proto_goTypes = nil + file_et_rpc_proto_depIdxs = nil +} diff --git a/et_rpc/pb/et_rpc_grpc.pb.go b/et_rpc/pb/et_rpc_grpc.pb.go new file mode 100644 index 0000000..b7667fa --- /dev/null +++ b/et_rpc/pb/et_rpc_grpc.pb.go @@ -0,0 +1,349 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.26.1 +// source: et_rpc.proto + +package pb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + NodeService_HandleIotaData_FullMethodName = "/et_rpc.NodeService/HandleIotaData" + NodeService_HandleAggData_FullMethodName = "/et_rpc.NodeService/HandleAggData" +) + +// NodeServiceClient is the client API for NodeService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// NodeService 定义 +type NodeServiceClient interface { + // 处理 Iota 数据并返回节点响应 + HandleIotaData(ctx context.Context, in *HandleDataRequest, opts ...grpc.CallOption) (*HandleDataResponse, error) + // 处理聚集数据并返回节点响应 + HandleAggData(ctx context.Context, in *HandleDataRequest, opts ...grpc.CallOption) (*HandleDataResponse, error) +} + +type nodeServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewNodeServiceClient(cc grpc.ClientConnInterface) NodeServiceClient { + return &nodeServiceClient{cc} +} + +func (c *nodeServiceClient) HandleIotaData(ctx context.Context, in *HandleDataRequest, opts ...grpc.CallOption) (*HandleDataResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(HandleDataResponse) + err := c.cc.Invoke(ctx, NodeService_HandleIotaData_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *nodeServiceClient) HandleAggData(ctx context.Context, in *HandleDataRequest, opts ...grpc.CallOption) (*HandleDataResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(HandleDataResponse) + err := c.cc.Invoke(ctx, NodeService_HandleAggData_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// NodeServiceServer is the server API for NodeService service. +// All implementations must embed UnimplementedNodeServiceServer +// for forward compatibility. +// +// NodeService 定义 +type NodeServiceServer interface { + // 处理 Iota 数据并返回节点响应 + HandleIotaData(context.Context, *HandleDataRequest) (*HandleDataResponse, error) + // 处理聚集数据并返回节点响应 + HandleAggData(context.Context, *HandleDataRequest) (*HandleDataResponse, error) + mustEmbedUnimplementedNodeServiceServer() +} + +// UnimplementedNodeServiceServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedNodeServiceServer struct{} + +func (UnimplementedNodeServiceServer) HandleIotaData(context.Context, *HandleDataRequest) (*HandleDataResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HandleIotaData not implemented") +} +func (UnimplementedNodeServiceServer) HandleAggData(context.Context, *HandleDataRequest) (*HandleDataResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HandleAggData not implemented") +} +func (UnimplementedNodeServiceServer) mustEmbedUnimplementedNodeServiceServer() {} +func (UnimplementedNodeServiceServer) testEmbeddedByValue() {} + +// UnsafeNodeServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to NodeServiceServer will +// result in compilation errors. +type UnsafeNodeServiceServer interface { + mustEmbedUnimplementedNodeServiceServer() +} + +func RegisterNodeServiceServer(s grpc.ServiceRegistrar, srv NodeServiceServer) { + // If the following call pancis, it indicates UnimplementedNodeServiceServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&NodeService_ServiceDesc, srv) +} + +func _NodeService_HandleIotaData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HandleDataRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NodeServiceServer).HandleIotaData(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: NodeService_HandleIotaData_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NodeServiceServer).HandleIotaData(ctx, req.(*HandleDataRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _NodeService_HandleAggData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HandleDataRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NodeServiceServer).HandleAggData(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: NodeService_HandleAggData_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NodeServiceServer).HandleAggData(ctx, req.(*HandleDataRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// NodeService_ServiceDesc is the grpc.ServiceDesc for NodeService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var NodeService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "et_rpc.NodeService", + HandlerType: (*NodeServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "HandleIotaData", + Handler: _NodeService_HandleIotaData_Handler, + }, + { + MethodName: "HandleAggData", + Handler: _NodeService_HandleAggData_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "et_rpc.proto", +} + +const ( + MasterService_RegisterNode_FullMethodName = "/et_rpc.MasterService/RegisterNode" + MasterService_HeartbeatNode_FullMethodName = "/et_rpc.MasterService/HeartbeatNode" + MasterService_UnregisterNode_FullMethodName = "/et_rpc.MasterService/UnregisterNode" +) + +// MasterServiceClient is the client API for MasterService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// MasterService 定义 +type MasterServiceClient interface { + RegisterNode(ctx context.Context, in *NodeRequest, opts ...grpc.CallOption) (*RpcResponse, error) + HeartbeatNode(ctx context.Context, in *NodeRequest, opts ...grpc.CallOption) (*RpcResponse, error) + UnregisterNode(ctx context.Context, in *NodeRequest, opts ...grpc.CallOption) (*RpcResponse, error) +} + +type masterServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewMasterServiceClient(cc grpc.ClientConnInterface) MasterServiceClient { + return &masterServiceClient{cc} +} + +func (c *masterServiceClient) RegisterNode(ctx context.Context, in *NodeRequest, opts ...grpc.CallOption) (*RpcResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(RpcResponse) + err := c.cc.Invoke(ctx, MasterService_RegisterNode_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *masterServiceClient) HeartbeatNode(ctx context.Context, in *NodeRequest, opts ...grpc.CallOption) (*RpcResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(RpcResponse) + err := c.cc.Invoke(ctx, MasterService_HeartbeatNode_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *masterServiceClient) UnregisterNode(ctx context.Context, in *NodeRequest, opts ...grpc.CallOption) (*RpcResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(RpcResponse) + err := c.cc.Invoke(ctx, MasterService_UnregisterNode_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MasterServiceServer is the server API for MasterService service. +// All implementations must embed UnimplementedMasterServiceServer +// for forward compatibility. +// +// MasterService 定义 +type MasterServiceServer interface { + RegisterNode(context.Context, *NodeRequest) (*RpcResponse, error) + HeartbeatNode(context.Context, *NodeRequest) (*RpcResponse, error) + UnregisterNode(context.Context, *NodeRequest) (*RpcResponse, error) + mustEmbedUnimplementedMasterServiceServer() +} + +// UnimplementedMasterServiceServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedMasterServiceServer struct{} + +func (UnimplementedMasterServiceServer) RegisterNode(context.Context, *NodeRequest) (*RpcResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterNode not implemented") +} +func (UnimplementedMasterServiceServer) HeartbeatNode(context.Context, *NodeRequest) (*RpcResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HeartbeatNode not implemented") +} +func (UnimplementedMasterServiceServer) UnregisterNode(context.Context, *NodeRequest) (*RpcResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UnregisterNode not implemented") +} +func (UnimplementedMasterServiceServer) mustEmbedUnimplementedMasterServiceServer() {} +func (UnimplementedMasterServiceServer) testEmbeddedByValue() {} + +// UnsafeMasterServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to MasterServiceServer will +// result in compilation errors. +type UnsafeMasterServiceServer interface { + mustEmbedUnimplementedMasterServiceServer() +} + +func RegisterMasterServiceServer(s grpc.ServiceRegistrar, srv MasterServiceServer) { + // If the following call pancis, it indicates UnimplementedMasterServiceServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&MasterService_ServiceDesc, srv) +} + +func _MasterService_RegisterNode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NodeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MasterServiceServer).RegisterNode(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MasterService_RegisterNode_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MasterServiceServer).RegisterNode(ctx, req.(*NodeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _MasterService_HeartbeatNode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NodeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MasterServiceServer).HeartbeatNode(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MasterService_HeartbeatNode_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MasterServiceServer).HeartbeatNode(ctx, req.(*NodeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _MasterService_UnregisterNode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NodeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MasterServiceServer).UnregisterNode(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MasterService_UnregisterNode_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MasterServiceServer).UnregisterNode(ctx, req.(*NodeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// MasterService_ServiceDesc is the grpc.ServiceDesc for MasterService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var MasterService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "et_rpc.MasterService", + HandlerType: (*MasterServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RegisterNode", + Handler: _MasterService_RegisterNode_Handler, + }, + { + MethodName: "HeartbeatNode", + Handler: _MasterService_HeartbeatNode_Handler, + }, + { + MethodName: "UnregisterNode", + Handler: _MasterService_UnregisterNode_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "et_rpc.proto", +} diff --git a/et_rpc/proto/et_rpc.proto b/et_rpc/proto/et_rpc.proto new file mode 100644 index 0000000..52522d8 --- /dev/null +++ b/et_rpc/proto/et_rpc.proto @@ -0,0 +1,124 @@ +syntax = "proto3"; + +package et_rpc; +option go_package = "/pb"; + +message NodeArgs{ + string id = 1; // 节点ID + string addr = 2; // 节点地址 + int32 load = 3; // 节点荷载 + string resource_json = 4; // 资源使用情况JSON + int32 weight = 5; // 权重 + NodeState status = 6; // 节点状态 + RPCReplyCode err_code = 7; // 错误代码 + string err_message = 8; // 错误信息 +} + +message NodeResponse { + string id = 1; + string addr = 2; + RPCReplyCode err_code = 3; + string err_message = 4; +} + +message NodeRegistrationRequest { + string node_id = 1; + string node_addr = 2; +} + +message NodeStatusRequest { + string node_id = 1; +} + +message NodeStatusResponse { + string node_id = 1; + string status = 2; // 例如 "active", "inactive" +} + +// 枚举定义 +enum NodeState { + UNKNOWN = 0; + ACTIVE = 1; + INACTIVE = 2; +} + +enum RPCReplyCode { + SUCCESS = 0; + FAILURE = 1; +} + +// 定义键值对消息 +message KeyValue { + string key = 1; // 键 + double value = 2; // 值 +} + +// 定义AggData消息 +message AggData { + string date = 1; // 使用protobuf的时间戳类型 + int32 sensor_id = 2; // SensorId + int32 struct_id = 3; // StructId + int32 factor_id = 4; // FactorId + int32 agg_type_id = 5; // 聚集类型 + int32 agg_method_id = 6; // 聚集方法 + repeated KeyValue agg = 7; // 聚集数据 + repeated KeyValue changed = 8; // 变化量 + string thing_id = 9; // ThingId +} + + + +message NodeRequest{ + string id = 1; + string address = 2; + repeated string thing_ids = 3; +} + +message RpcResponse { + enum Status { + SUCCESS = 0; // 请求成功 + FAILURE = 1; // 请求失败 + INVALID_ARGUMENT = 2; // 无效参数 + NOT_FOUND = 3; // 未找到 + INTERNAL_ERROR = 4; // 内部错误 + // 可以根据需要添加更多状态 + } + + Status status = 1; // 请求状态 + string error_message = 2; // 错误信息,如果请求失败则返回具体的错误信息 +} + +message HandleDataResponse{ + enum Status { + SUCCESS = 0; // 请求成功 + FAILURE = 1; // 请求失败 + INVALID_ARGUMENT = 2; // 无效参数 + INTERNAL_ERROR = 4; // 内部错误 + // 可以根据需要添加更多状态 + } + + string addr = 1; // 节点地址 + int32 load = 2; // 节点荷载 + Status status = 3; // 请求状态 + string error_message = 4; // 错误信息,如果请求失败则返回具体的错误信息 +} + +message HandleDataRequest { + string id = 1; + repeated string messages = 2; +} + +// NodeService 定义 +service NodeService { + // 处理 Iota 数据并返回节点响应 + rpc HandleIotaData(HandleDataRequest) returns (HandleDataResponse); + // 处理聚集数据并返回节点响应 + rpc HandleAggData(HandleDataRequest) returns (HandleDataResponse); +} + +// MasterService 定义 +service MasterService { + rpc RegisterNode(NodeRequest) returns (RpcResponse); + rpc HeartbeatNode(NodeRequest) returns (RpcResponse); + rpc UnregisterNode(NodeRequest) returns (RpcResponse); +} diff --git a/et_rpc/proto/go-protobuf生成帮助.txt b/et_rpc/proto/go-protobuf生成帮助.txt new file mode 100644 index 0000000..0107222 --- /dev/null +++ b/et_rpc/proto/go-protobuf生成帮助.txt @@ -0,0 +1,58 @@ +gRPC https://grpc.org.cn/docs/guides/cancellation/ + + +go get google.golang.org/grpc +go get google.golang.org/protobuf/cmd/protoc-gen-go +go get google.golang.org/grpc/cmd/protoc-gen-go-grpc + +go install google.golang.org/protobuf/cmd/protoc-gen-go@latest +go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest + +生成代码出错,问题解决: +查找 +go list -m all | findstr grpc +go list -m all | findstr protobuf + +移除不必要的依赖 +go get -u github.com/gogo/protobuf@nonego get -u github.com/golang/protobuf@none +go get -u github.com/matttproud/golang_protobuf_extensions@none + +更新 go.mod +go mod tidy + +重新生成代码,打开命令行执行以下命令: +cd et_rpc +protoc --proto_path=proto --go_out=./pb --go_opt=paths=source_relative --go-grpc_out=./pb --go-grpc_opt=paths=source_relative proto/*.proto + +============================================================== + +1. 使用 Protobuf 编译器 protoc 生成 Go 代码 + 基本的 Protobuf 编译指令 protoc --proto_path=IMPORT_PATH --go_out=OUTPUT_PATH --go_opt=paths=source_relative your_proto_file.proto + 参数说明 + --proto_path=IMPORT_PATH:指定 .proto 文件的搜索路径。可以使用多个 --proto_path 选项来指定多个路径。 + --go_out=OUTPUT_PATH:指定生成的 Go 代码的输出路径。可以使用 . 表示当前目录。 + --go_opt=paths=source_relative:这个选项使生成的 Go 文件的包路径与 .proto 文件的相对路径一致,通常推荐使用。 + your_proto_file.proto:要编译的 .proto 文件的名称。 + +***** ET-GO 系统的编译指令(cd 致 et-go/et_rpc 下执行) +1) 只生成消息类型的Go代码、序列化和反序列化方法、其他辅助方法: +protoc --proto_path=proto --go_out=./pb --go_opt=paths=source_relative proto/*.proto +2)生成消息类型Go代码、序列化和反序列化方法、gRPC服务的Go代码、gRPC方法的实现: +protoc --proto_path=proto --go_out=./pb --go_opt=paths=source_relative --go-grpc_out=./pb --go-grpc_opt=paths=source_relative proto/*.proto + +参数说明 +--proto_path=proto:指定 .proto 文件的搜索路径为 proto 目录。 +--go_out=./pb:指定生成的 Go 代码输出到 pb 目录。 +--go_opt=paths=source_relative:确保生成的 Go 文件的包路径与 .proto 文件的相对路径一致。 +proto/*.proto:使用通配符 *.proto 来编译 proto 目录下的所有 .proto 文件。 + +/et-go + ├── et_rpc + │ ├── pb # 存放生成的 Go 文件 + │ │ └── iota_data.pb.go # 生成的 Go 文件 + │ └── proto # 存放 Protobuf 文件 + │ └── iota_data.proto # IotaData Protobuf 文件 + └── 其他 + + + diff --git a/et_rpc/rpc.go b/et_rpc/rpc.go new file mode 100644 index 0000000..d6ac040 --- /dev/null +++ b/et_rpc/rpc.go @@ -0,0 +1,22 @@ +package et_rpc + +type RPCReplyCode int + +type NodeState int + +const ( + NodeState_Healthy NodeState = iota + NodeState_Unhealthy +) + +type NodeArgs struct { + ID string + Addr string + Load int // 节点荷载(主要为积压的数据量) + ResourceJson string // CPU\内存\硬盘 使用情况JSON + Weight int // 权重(暂时未用到) + Status NodeState // 节点状态(健康 | 不健康) + + ErrCode RPCReplyCode // RPCReply_Success | RPCReply_Failure + ErrMessage string +} diff --git a/et_rpc/rpc_test.go b/et_rpc/rpc_test.go new file mode 100644 index 0000000..326d056 --- /dev/null +++ b/et_rpc/rpc_test.go @@ -0,0 +1,57 @@ +package et_rpc + +import ( + "encoding/json" + "et_rpc/pb" + "fmt" + "google.golang.org/protobuf/proto" + "log" + "testing" +) + +// TestProtoJSONConversion 测试 Protobuf 和 JSON 之间的转换 +func TestProtoJSONConversion(t *testing.T) { + // 创建请求 + request := createHandleDataRequest() + + // 序列化请求为 Protobuf 格式 + data, err := proto.Marshal(request) + if err != nil { + log.Fatalf("Failed to marshal request: %v", err) + } + + // 打印序列化后的数据 + fmt.Println("Serialized HandleDataRequest:", data) + + // 这里可以将序列化后的数据发送到 gRPC 服务 + // 例如:client.HandleIotaData(context.Background(), request) +} + +func createJSONData(id string, value float64) (string, error) { + data := map[string]interface{}{ + "id": id, + "value": value, + } + + jsonData, err := json.Marshal(data) + if err != nil { + return "", err + } + + return string(jsonData), nil +} + +func createHandleDataRequest() *pb.HandleDataRequest { + request := &pb.HandleDataRequest{} + + // 添加 JSON 数据消息 + json1, _ := createJSONData("1", 10.5) + json2, _ := createJSONData("2", 20.3) + json3, _ := createJSONData("3", 15.8) + + request.Messages = append(request.Messages, json1) + request.Messages = append(request.Messages, json2) + request.Messages = append(request.Messages, json3) + + return request +}