Пример #1
0
func udpDecode(router chan<- osc.OscMessageOrBundle, oscLog chan<- string) chan<- []byte {
	decodeChan := make(chan []byte, 5)

	go func() {
		for buff := range decodeChan {
			r := bufio.NewReader(bytes.NewBuffer(buff))

			if message, err := osc.DeserializeOscMessage(r); err != nil {
				log.Fatal("Error decoding buffer: %v", err)
			} else {
				router <- message
			}
		}
	}()

	return decodeChan
}
Пример #2
0
func HandleTcpConnection(conn net.Conn, router chan<- osc.OscMessageOrBundle, oscLog chan<- string) {
	defer conn.Close()

	message_size := make([]byte, 4)

	n, err := conn.Read(message_size)

	if err != nil {
		log.Fatal(err)
	} else if n != 4 {
		log.Fatal(errors.New("Could not read the message size!"))
	}

	ir := bufio.NewReader(bytes.NewBuffer(message_size))

	int_message_size, err := osc.DeserializeOscInt32(ir)

	if err != nil {
		log.Fatal(err)
	}

	message := make([]byte, *int_message_size)

	n, err = conn.Read(message)

	if err != nil {
		log.Fatal(err)
	} else if n != int(*int_message_size) {
		log.Fatal("Could not read message complete")
	}

	r := bufio.NewReader(bytes.NewBuffer(message))

	if message, err := osc.DeserializeOscMessage(r); err != nil {
		log.Fatal("Error decoding buffer: %v", err)
	} else {
		router <- message
	}
}