-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.go
More file actions
44 lines (32 loc) · 871 Bytes
/
utils.go
File metadata and controls
44 lines (32 loc) · 871 Bytes
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
package main
import (
"fmt"
"bytes"
"encoding/binary"
"os"
)
func ToNetworkByteOrder(val int32) ([]byte, error) {
iobuf := new(bytes.Buffer)
err := binary.Write(iobuf, binary.BigEndian, val)
if err != nil {
fmt.Println("toNetworkByteOrder:binary.Write failed:", err)
return iobuf.Bytes(), err
}
// fmt.Printf("server version:%x:\n", iobuf.Bytes())
return iobuf.Bytes(), nil
}
func FromNetworkByteOrder(iobuf []byte) (rv int32, err error) {
bufReader := bytes.NewReader(iobuf)
err = binary.Read(bufReader, binary.LittleEndian, &rv)
if err != nil {
fmt.Println("binary.Read failed:", err)
return rv, err
}
return rv, nil
}
func checkError(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
// os.Exit(1)
}
}