This seems to actually add a protobuf to the channel (not Marshal'd though)
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
fbe1900763
commit
a737a23d6f
3
Makefile
3
Makefile
|
@ -21,7 +21,8 @@ push:
|
|||
git pull
|
||||
git add --all
|
||||
-git commit -a -s
|
||||
git push
|
||||
git push --all
|
||||
git push --tags
|
||||
|
||||
# should update every go dependancy (?)
|
||||
update:
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "net"
|
||||
import "os"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
import "github.com/golang/protobuf/proto"
|
||||
import pb "git.wit.com/jcarr/witProtobuf"
|
||||
|
||||
var mychannel chan *pb.Event
|
||||
|
||||
func initChannel() {
|
||||
mychannel = make(chan *pb.Event)
|
||||
}
|
||||
|
||||
// func processEvents(mychannel chan *pb.Event) {
|
||||
func processEvents() {
|
||||
for {
|
||||
message := <-mychannel
|
||||
log.Println("processEvents() on channel recieved a message")
|
||||
ReadReceivedData(message)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadReceivedData(data *pb.Event) {
|
||||
msgItems := data.GetResults()
|
||||
fmt.Println("Receiving data...")
|
||||
for _, item := range msgItems {
|
||||
fmt.Println(item)
|
||||
}
|
||||
}
|
||||
|
||||
func handleProtoClient(conn net.Conn) {
|
||||
fmt.Println("Connected!")
|
||||
defer conn.Close()
|
||||
var buf bytes.Buffer
|
||||
_, err := io.Copy(&buf, conn)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
pdata := new(pb.Event)
|
||||
err = proto.Unmarshal(buf.Bytes(), pdata)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
mychannel <- pdata
|
||||
}
|
||||
|
||||
func addEvent() {
|
||||
msg := new(pb.Event)
|
||||
msg.Name = "hello jeff"
|
||||
|
||||
// var mybuf bytes.Buffer
|
||||
|
||||
data, err := proto.Marshal(msg)
|
||||
if (err != nil) {
|
||||
log.Printf("something fucked up happened")
|
||||
}
|
||||
pdata := new(pb.Event)
|
||||
// err = proto.Unmarshal(data.Bytes(), pdata)
|
||||
err = proto.Unmarshal(data, pdata)
|
||||
mychannel <- pdata
|
||||
// sendDataToDest(data)
|
||||
}
|
10
infoTabUI.go
10
infoTabUI.go
|
@ -53,6 +53,15 @@ func makeCloudInfoBox() ui.Control {
|
|||
})
|
||||
vbox.Append(add2button, false)
|
||||
// ATTEMPT TO ADD THE TABLE HERE END
|
||||
hbox.Append(ui.NewVerticalSeparator(), false)
|
||||
|
||||
add3button := ui.NewButton("Add buf to chann")
|
||||
add3button.OnClicked(func(*ui.Button) {
|
||||
log.Println("add protobuf event to the channel")
|
||||
addEvent()
|
||||
})
|
||||
vbox.Append(add3button, false)
|
||||
|
||||
|
||||
hbox.Append(ui.NewVerticalSeparator(), false)
|
||||
|
||||
|
@ -106,7 +115,6 @@ func setupCloudUI() {
|
|||
jwcmaintab.Append("Cloud Info", makeCloudInfoBox())
|
||||
jwcmaintab.SetMargined(tabcount, true)
|
||||
|
||||
|
||||
jwcmainwin.Show()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue