-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.go
93 lines (79 loc) · 2.53 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package inference
import (
"encoding/json"
"github.com/CortexFoundation/CortexTheseus/common/hexutil"
)
// infer send types
type InferType uint32
const (
INFER_UNKNOWN = InferType(0)
INFER_BY_IH = InferType(1) // Infer By Input Hash
INFER_BY_IC = InferType(2) // Infer By Input Content
GAS_BY_H = InferType(3) // Gas By Model Hash
AVAILABLE_BY_H = InferType(4) // Available by info hash
)
// Infer by input info hash
//
//go:generate gencodec -type IHWork -out gen_ih_json.go
type IHWork struct {
Type InferType `json:"type" gencodec:"required"`
Model string `json:"model" gencodec:"required"`
Input string `json:"input" gencodec:"required"`
ModelSize uint64 `json:"modelSize"`
InputSize uint64 `json:"inputSize"`
CvmVersion int `json:"cvm_version"`
CvmNetworkId int64 `json:"cvm_networkid"`
}
// Infer by input content
//
//go:generate gencodec -type ICWork -out gen_ic_json.go
type ICWork struct {
Type InferType `json:"type" gencodec:"required"`
Model string `json:"model" gencodec:"required"`
Input hexutil.Bytes `json:"input" gencodec:"required"`
ModelSize uint64 `json:"modelSize"`
CvmVersion int `json:"cvm_version"`
CvmNetworkId int64 `json:"cvm_networkid"`
}
// Infer gas
//
//go:generate gencodec -type GasWork -out gen_gas_json.go
type GasWork struct {
Type InferType `json:"type" gencodec:"required"`
Model string `json:"model" gencodec:"required"`
ModelSize uint64 `json:"modelSize"`
CvmNetworkId int64 `json:"cvm_networkid"`
}
// check Available
//
//go:generate gencodec -type AvailableWork -out gen_avaiable_json.go
type AvailableWork struct {
Type InferType `json:"type" gencodec:"required"`
InfoHash string `json:"infohash" gencodec:"required"`
RawSize uint64 `json:"rawSize" gencodec:"required"`
CvmNetworkId int64 `json:"cvm_networkid"`
}
//go:generate gencodec -type Work -out gen_work_json.go
type Work struct {
Type InferType `json:"type" gencodec:"required"`
}
func RetriveType(input []byte) InferType {
if len(input) == 0 {
return INFER_UNKNOWN
}
var dec Work
if err := json.Unmarshal(input, &dec); err != nil {
return INFER_UNKNOWN
}
return dec.Type
}
// infer response types
const (
RES_OK = "ok"
RES_ERROR = "error"
)
//go:generate gencodec -type InferResult -out gen_result_json.go
type InferResult struct {
Data hexutil.Bytes `json:"data" gencodec:"required"`
Info string `json:"info" gencodec:"required"`
}