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:
Jeff Carr 2019-05-11 07:53:32 -07:00
parent fbe1900763
commit a737a23d6f
4 changed files with 83 additions and 2 deletions

View File

@ -21,7 +21,8 @@ push:
git pull git pull
git add --all git add --all
-git commit -a -s -git commit -a -s
git push git push --all
git push --tags
# should update every go dependancy (?) # should update every go dependancy (?)
update: update:

69
channel.go Normal file
View File

@ -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)
}

View File

@ -53,6 +53,15 @@ func makeCloudInfoBox() ui.Control {
}) })
vbox.Append(add2button, false) vbox.Append(add2button, false)
// ATTEMPT TO ADD THE TABLE HERE END // 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) hbox.Append(ui.NewVerticalSeparator(), false)
@ -106,7 +115,6 @@ func setupCloudUI() {
jwcmaintab.Append("Cloud Info", makeCloudInfoBox()) jwcmaintab.Append("Cloud Info", makeCloudInfoBox())
jwcmaintab.SetMargined(tabcount, true) jwcmaintab.SetMargined(tabcount, true)
jwcmainwin.Show() jwcmainwin.Show()
} }

View File

@ -36,6 +36,9 @@ func main() {
onExit() onExit()
} }
initChannel()
go processEvents()
go retrySocket() go retrySocket()
// make this the main loop in an attempt to figure out the crashes // make this the main loop in an attempt to figure out the crashes