-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathio.go
More file actions
65 lines (51 loc) · 1.32 KB
/
Copy pathio.go
File metadata and controls
65 lines (51 loc) · 1.32 KB
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
//
// io.go
//
// Copyright (c) 2023-2026 Markku Rossi
//
// All rights reserved.
package ot
import (
"math/big"
)
// IO defines an I/O interface to communicate between peers.
type IO interface {
// SendByte sends a byte value.
SendByte(val byte) error
// SendUint32 sends an uint32 value.
SendUint32(val int) error
// SendData sends binary data.
SendData(val []byte) error
// SendLabel sends a Label.
SendLabel(val Label, data *LabelData) error
// Flush flushed any pending data in the connection.
Flush() error
// ReceiveByte receives a byte value.
ReceiveByte() (byte, error)
// ReceiveUint32 receives an uint32 value.
ReceiveUint32() (int, error)
// ReceiveData receives binary data.
ReceiveData() ([]byte, error)
// ReceiveLabel receives a Label.
ReceiveLabel(val *Label, data *LabelData) error
}
// SendString sends a string value.
func SendString(io IO, str string) error {
return io.SendData([]byte(str))
}
// ReceiveString receives a string value.
func ReceiveString(io IO) (string, error) {
data, err := io.ReceiveData()
if err != nil {
return "", err
}
return string(data), nil
}
// ReceiveBigInt receives a bit.Int from the connection.
func ReceiveBigInt(io IO) (*big.Int, error) {
data, err := io.ReceiveData()
if err != nil {
return nil, err
}
return big.NewInt(0).SetBytes(data), nil
}