flowsprenger / RxLifx-Swift

RxSwift based SDK for the LIFX Lan protocol
MIT License
10 stars 5 forks source link

Remove unnecessary string-padding from Commands #4

Closed lightbow closed 6 years ago

lightbow commented 6 years ago

Three commands (SetGroup, SetLabel, SetLocation) were calling something like .padding(toLength: 32, withPad: "", startingAt: 0) which is not necessary because DataOutputStream already takes a length for writeString and pads appropriately.

    func writeString(value:String, size:Int){
        let padding = size - value.utf8.count
        for _ in 0..<padding{
            writeByte(value: 20)
        }
        value.utf8.forEach{ writeByte(value: UInt8($0)) }
    }

Also, if the string passed into any of these commands actually was too short, it would result in a crash, which you can reproduce by pasting the following line into a Swift Playground (can't actually pad with an empty string like that)

let padded = "Hello World".padding(toLength: 32, withPad: "", startingAt: 0)

With this fix, I am able to properly rename bulbs now in my host app.

flowsprenger commented 6 years ago

Excellent, thanks :)