added message size bytes
This commit is contained in:
20
ledd.go
20
ledd.go
@@ -184,7 +184,7 @@ func (manager *BackendManager) start() {
|
|||||||
log.Warningf("[%s] Failed to encode protobuf: %s", backend.niceName(), err)
|
log.Warningf("[%s] Failed to encode protobuf: %s", backend.niceName(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.data <- data
|
backend.data <- prepareProtobuf(data)
|
||||||
case backend := <-manager.unregister:
|
case backend := <-manager.unregister:
|
||||||
if _, ok := manager.backends[backend.name]; ok {
|
if _, ok := manager.backends[backend.name]; ok {
|
||||||
log.Debugf("[%s] Backend %s removed: connection terminated", LOG_BACKEND, backend.socket.RemoteAddr())
|
log.Debugf("[%s] Backend %s removed: connection terminated", LOG_BACKEND, backend.socket.RemoteAddr())
|
||||||
@@ -236,12 +236,12 @@ func (manager *BackendManager) receive(backend *Backend) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if length > 0 {
|
if length > 0 {
|
||||||
msgLen := binary.BigEndian.Uint32(message[0:3])
|
msgLen := binary.BigEndian.Uint32(message[0:4])
|
||||||
|
|
||||||
log.Debugf("[%s] Read %d bytes, first protobuf is %d long", backend.niceName(), length, msgLen)
|
log.Debugf("[%s] Read %d bytes, first protobuf is %d long", backend.niceName(), length, msgLen)
|
||||||
|
|
||||||
backendMsg := &ledd.BackendWrapperMessage{}
|
backendMsg := &ledd.BackendWrapperMessage{}
|
||||||
err = proto.Unmarshal(message[4:msgLen], backendMsg)
|
err = proto.Unmarshal(message[4:msgLen+1], backendMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("[%s] Couldn't decode protobuf msg!", backend.niceName())
|
log.Warningf("[%s] Couldn't decode protobuf msg!", backend.niceName())
|
||||||
continue
|
continue
|
||||||
@@ -313,12 +313,12 @@ func (manager *ClientManager) receive(client *Client) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if length > 0 {
|
if length > 0 {
|
||||||
msgLen := binary.BigEndian.Uint32(message[0:3])
|
msgLen := binary.BigEndian.Uint32(message[0:4])
|
||||||
|
|
||||||
log.Debugf("[%s] Read %d bytes, first protobuf is %d long", client.socket.RemoteAddr(), length, msgLen)
|
log.Debugf("[%s] Read %d bytes, first protobuf is %d long", client.socket.RemoteAddr(), length, msgLen)
|
||||||
|
|
||||||
clientMsg := &ledd.ClientWrapperMessage{}
|
clientMsg := &ledd.ClientWrapperMessage{}
|
||||||
err = proto.Unmarshal(message[4:msgLen], clientMsg)
|
err = proto.Unmarshal(message[4:msgLen+1], clientMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("[%s] Couldn't decode protobuf msg!", client.socket.RemoteAddr())
|
log.Warningf("[%s] Couldn't decode protobuf msg!", client.socket.RemoteAddr())
|
||||||
continue
|
continue
|
||||||
@@ -341,7 +341,7 @@ func (manager *ClientManager) receive(client *Client) {
|
|||||||
log.Errorf("[%s] Error encoding protobuf: %s", client.socket.RemoteAddr(), err)
|
log.Errorf("[%s] Error encoding protobuf: %s", client.socket.RemoteAddr(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client.data <- data
|
client.data <- prepareProtobuf(data)
|
||||||
case *ledd.ClientWrapperMessage_MAddLed:
|
case *ledd.ClientWrapperMessage_MAddLed:
|
||||||
backend, ok := backManager.backends[msg.MAddLed.Backend]
|
backend, ok := backManager.backends[msg.MAddLed.Backend]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -407,7 +407,13 @@ func (led *LED) setColor(color colorful.Color) {
|
|||||||
log.Warningf("[%s] Failed to encode protobuf msg to %s: %s", led.name, backend.name, err)
|
log.Warningf("[%s] Failed to encode protobuf msg to %s: %s", led.name, backend.name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.data <- data
|
backend.data <- prepareProtobuf(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func prepareProtobuf(data []byte) []byte {
|
||||||
|
size := make([]byte, 4)
|
||||||
|
binary.BigEndian.PutUint32(size, uint32(len(data)))
|
||||||
|
return append(size, data...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MAIN
|
// MAIN
|
||||||
|
Reference in New Issue
Block a user