forked from calibrae-project/spawn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.go
76 lines (67 loc) · 1.61 KB
/
solution.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
package sol
import (
"bytes"
"github.com/niubaoshu/gotiny"
"github.com/p9c/duod/pkg/wire"
)
// Magic is the marker for packets containing a solution
var Magic = []byte{'s', 'o', 'l', 1}
type Solution struct {
Nonce uint64
UUID uint64
// *wire.Block
Bytes []byte
}
// Encode a message for a solution
func Encode(nonce uint64, uuid uint64, mb *wire.BlockHeader) []byte {
var buf []byte
wr := bytes.NewBuffer(buf)
var e error
if e = mb.Serialize(wr); E.Chk(e) {
}
s := Solution{Nonce: nonce, UUID: uuid, Bytes: wr.Bytes()} // Block: mb}
return gotiny.Marshal(&s)
}
// Decode an encoded solution message to a wire.BlockHeader
func (s *Solution) Decode() (mb *wire.BlockHeader, e error) {
buf := bytes.NewBuffer(s.Bytes)
mb = &wire.BlockHeader{}
if e = mb.Deserialize(buf); E.Chk(e) {
}
return
}
//
// type Container struct {
// simplebuffer.Container
// }
//
// func GetSolContainer(port uint32, b *wire.Block) *Container {
// mB := Block.New().Put(b)
// srs := simplebuffer.Serializers{Int32.New().Put(int32(port)), mB}.CreateContainer(Magic)
// return &Container{*srs}
// }
//
// func LoadSolContainer(b []byte) (out *Container) {
// out = &Container{}
// out.Data = b
// return
// }
//
//
// func (sC *Container) GetMsgBlock() *wire.Block {
// // Traces(sC.Data)
// buff := sC.Encode(1)
// // Traces(buff)
// decoded := Block.New().DecodeOne(buff)
// // Traces(decoded)
// got := decoded.Encode()
// // Traces(got)
// return got
// }
//
// func (sC *Container) GetSenderPort() int32 {
// buff := sC.Encode(0)
// decoded := Int32.New().DecodeOne(buff)
// got := decoded.Encode()
// return got
// }