| @@ -5,7 +5,6 @@ import ( | |||||
| "fmt" | "fmt" | ||||
| "gitlink.org.cn/cloudream/common/pkgs/types" | "gitlink.org.cn/cloudream/common/pkgs/types" | ||||
| myreflect "gitlink.org.cn/cloudream/common/utils/reflect" | |||||
| "gitlink.org.cn/cloudream/common/utils/serder" | "gitlink.org.cn/cloudream/common/utils/serder" | ||||
| ) | ) | ||||
| @@ -33,19 +32,12 @@ type Redundancy interface { | |||||
| driver.Valuer | driver.Valuer | ||||
| } | } | ||||
| type RedundancyBase struct{} | |||||
| func (b *RedundancyBase) Value() (driver.Value, error) { | |||||
| return serder.ObjectToJSONEx[Redundancy](b) | |||||
| } | |||||
| var RedundancyUnion = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[Redundancy]( | var RedundancyUnion = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[Redundancy]( | ||||
| (*RepRedundancy)(nil), | (*RepRedundancy)(nil), | ||||
| (*ECRedundancy)(nil), | (*ECRedundancy)(nil), | ||||
| )), "type") | )), "type") | ||||
| type RepRedundancy struct { | type RepRedundancy struct { | ||||
| RedundancyBase | |||||
| serder.Metadata `union:"rep"` | serder.Metadata `union:"rep"` | ||||
| Type string `json:"type"` | Type string `json:"type"` | ||||
| } | } | ||||
| @@ -55,9 +47,11 @@ func NewRepRedundancy() *RepRedundancy { | |||||
| Type: "rep", | Type: "rep", | ||||
| } | } | ||||
| } | } | ||||
| func (b *RepRedundancy) Value() (driver.Value, error) { | |||||
| return serder.ObjectToJSONEx[Redundancy](b) | |||||
| } | |||||
| type ECRedundancy struct { | type ECRedundancy struct { | ||||
| RedundancyBase | |||||
| serder.Metadata `union:"ec"` | serder.Metadata `union:"ec"` | ||||
| Type string `json:"type"` | Type string `json:"type"` | ||||
| K int `json:"k"` | K int `json:"k"` | ||||
| @@ -73,6 +67,9 @@ func NewECRedundancy(k int, n int, chunkSize int) *ECRedundancy { | |||||
| ChunkSize: chunkSize, | ChunkSize: chunkSize, | ||||
| } | } | ||||
| } | } | ||||
| func (b *ECRedundancy) Value() (driver.Value, error) { | |||||
| return serder.ObjectToJSONEx[Redundancy](b) | |||||
| } | |||||
| const ( | const ( | ||||
| PackageStateNormal = "Normal" | PackageStateNormal = "Normal" | ||||
| @@ -95,21 +92,6 @@ type Object struct { | |||||
| Redundancy Redundancy `db:"Redundancy" json:"redundancy"` | Redundancy Redundancy `db:"Redundancy" json:"redundancy"` | ||||
| } | } | ||||
| func (i *Object) Scan(src interface{}) error { | |||||
| data, ok := src.([]uint8) | |||||
| if !ok { | |||||
| return fmt.Errorf("unknow src type: %v", myreflect.TypeOfValue(data)) | |||||
| } | |||||
| obj, err := serder.JSONToObjectEx[*Object](data) | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| *i = *obj | |||||
| return nil | |||||
| } | |||||
| type NodePackageCachingInfo struct { | type NodePackageCachingInfo struct { | ||||
| NodeID NodeID `json:"nodeID"` | NodeID NodeID `json:"nodeID"` | ||||
| FileSize int64 `json:"fileSize"` | FileSize int64 `json:"fileSize"` | ||||