internal static LifxMessage FromPacket(byte[] data, IUdpClient respondClient) { using (MemoryStream ms = new MemoryStream(data)) { var headerBytes = new byte[36]; Array.Copy(data, headerBytes, headerBytes.Length); var header = LifxHeader.FromHeaderBytes(headerBytes); byte[] payload = null; if (data.Length > 36) { payload = new byte[data.Length - 36]; Array.Copy(data, 36, payload, 0, payload.Length); } return(LifxMessage.FromPayloadBytes(header, payload, respondClient)); } }
private static LifxMessage FromPayloadBytes(LifxHeader header, byte[] payload, IUdpClient respondClient) { ILifxPayload parsedPayload = null; switch (header.ProtocolHeader.MessageType) { case MessageType.DeviceAcknowledgement: parsedPayload = AcknowledgementResponse.FromBytes(); break; case MessageType.DeviceStateLabel: parsedPayload = StateLabelResponse.FromBytes(payload); break; case MessageType.LightState: parsedPayload = LightStateResponse.FromBytes(payload); break; case MessageType.LightStatePower: parsedPayload = LightPowerResponse.FromBytes(payload); break; case MessageType.DeviceStateVersion: parsedPayload = StateVersionResponse.FromBytes(payload); break; case MessageType.DeviceStateHostFirmware: parsedPayload = StateHostFirmwareResponse.FromBytes(payload); break; case MessageType.DeviceStateService: parsedPayload = StateServiceResponse.FromBytes(payload); break; default: parsedPayload = UnknownResponse.FromBytes(payload); break; } return(new LifxMessage(header, parsedPayload, respondClient)); }
internal LifxMessage(LifxHeader header, ILifxPayload payload, IUdpClient respondClient) { Header = header; Payload = payload; RespondClient = respondClient; }