From ba363dce50f6f50e8d2ee0b2c683a88372fb1a93 Mon Sep 17 00:00:00 2001 From: Sydonian <794346190@qq.com> Date: Thu, 24 Aug 2023 17:13:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=AC=E5=85=B1=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/models.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/models/models.go b/models/models.go index 3f140e1..be61d90 100644 --- a/models/models.go +++ b/models/models.go @@ -18,7 +18,7 @@ const ( // 注:如果在mq中的消息结构体使用了此类型,记得使用RegisterTypeSet注册相关的类型。 type RedundancyInfo interface{} type RedundancyInfoConst interface { - RedundancyInfo | RepRedundancyInfo | ECRedundancyInfo + RepRedundancyInfo | ECRedundancyInfo } type RepRedundancyInfo struct { RepCount int `json:"repCount"` @@ -47,7 +47,15 @@ type TypedRedundancyInfo struct { Info RedundancyInfo `json:"info"` } -func NewTypedRedundancyInfo[T RedundancyInfoConst](typ string, info T) TypedRedundancyInfo { +func NewTypedRedundancyInfo[T RedundancyInfoConst](info T) TypedRedundancyInfo { + var typ string + + if myreflect.TypeOf[T]() == myreflect.TypeOf[RepRedundancyInfo]() { + typ = RedundancyRep + } else if myreflect.TypeOf[T]() == myreflect.TypeOf[ECRedundancyInfo]() { + typ = RedundancyEC + } + return TypedRedundancyInfo{ Type: typ, Info: info, @@ -62,6 +70,16 @@ func NewTypedRepRedundancyInfo(repCount int) TypedRedundancyInfo { } } +func NewTypedECRedundancyInfo(ecName string, packetSize int64) TypedRedundancyInfo { + return TypedRedundancyInfo{ + Type: RedundancyRep, + Info: ECRedundancyInfo{ + ECName: ecName, + PacketSize: packetSize, + }, + } +} + func (i *TypedRedundancyInfo) IsRepInfo() bool { return i.Type == RedundancyRep }