-
Notifications
You must be signed in to change notification settings - Fork 0
/
protonet.go
50 lines (37 loc) · 1.55 KB
/
protonet.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
package proto
import (
"github.com/dowlandaiello/GoP2P/common"
"github.com/dowlandaiello/GoP2P/types/shard"
)
// SendToAddress - common.SendBytes() wrapper
func (protoMessage *ProtobufMessage) SendToAddress(address string) error {
serialized, err := protoMessage.ToBytes() // Serialize to bytes
if err != nil { // Check for errors
return err // Return found error
}
return common.SendBytes(serialized, address) // Send to address
}
// SendToAddressResult - common.SendBytesResult() wrapper
func (protoMessage *ProtobufMessage) SendToAddressResult(address string) ([]byte, error) {
serialized, err := protoMessage.ToBytes() // Serialize to bytes
if err != nil { // Check for errors
return []byte{}, err // Return found error
}
return common.SendBytesResult(serialized, address) // Send to address
}
// SendToShard - shard.SendBytesShard() wrapper
func (protoMessage *ProtobufMessage) SendToShard(shardAddress string, port int) error {
serialized, err := protoMessage.ToBytes() // Serialize to bytes
if err != nil { // Check for errors
return err // Return found error
}
return shard.SendBytesShard(serialized, shardAddress, port) // Send to address
}
// SendToShardResult - shard.SendBytesShardResult() wrapper
func (protoMessage *ProtobufMessage) SendToShardResult(shardAddress string, port int) ([]byte, error) {
serialized, err := protoMessage.ToBytes() // Serialize to bytes
if err != nil { // Check for errors
return []byte{}, err // Return found error
}
return shard.SendBytesShardResult(serialized, shardAddress, port) // Send to address
}