@@ -2,17 +2,46 @@ package main
2
2
3
3
import (
4
4
"log"
5
+ "net"
6
+ //"fmt"
7
+ //"bytes"
8
+ "encoding/binary"
5
9
6
10
"code.google.com/p/goprotobuf/proto"
7
11
"example_mess"
8
12
)
9
13
14
+ var _ = net .Dial
15
+ //var _ = bytes.Buffer
16
+
10
17
func main () {
18
+
19
+ socket , err := net .Dial ("unix" , "socket" )
20
+ if err != nil {
21
+ log .Fatal ("Failed to connect to socket: " , err )
22
+ }
23
+
24
+ defer socket .Close ()
25
+
11
26
test := & example_mess.Boring {
12
- Cont : proto .String ("wew " ),
27
+ Cont : proto .String ("Greets from Go " ),
13
28
}
14
- _ , err := proto .Marshal (test )
29
+ serialized , err := proto .Marshal (test )
15
30
if err != nil {
16
31
log .Fatal ("marshaling error: " , err )
17
32
}
33
+
34
+
35
+ //buf := new(bytes.Buffer)
36
+ println (len (serialized ))
37
+ //err = binary.Write(buf, binary.BigEndian, int32(1337))
38
+ //fmt.Printf("% d", buf.Bytes())
39
+
40
+ // Go is unique in that, thanks to its interfaces, it's practical to encode directly to the socket
41
+ err = binary .Write (socket , binary .BigEndian , int32 (len (serialized )))
42
+ if err != nil {
43
+ log .Fatal ("failed writing to socket: " , err )
44
+ }
45
+
46
+ socket .Write (serialized )
18
47
}
0 commit comments