Skip to content

Commit

Permalink
Kitura/Kitura#33 Add marshaling of frames with more than 125 bytes of…
Browse files Browse the repository at this point in the history
… payload
  • Loading branch information
shmuelk committed Nov 3, 2016
1 parent 1789c2c commit d7f52b2
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Sources/KituraWebSocket/WSFrame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,29 @@ struct WSFrame {
bytes[1] = UInt8(payloadLength)
length += 1
} else if payloadLength < Int(UInt16.max) {

bytes[1] = 126
let tempPayloadLengh = UInt16(payloadLength)
var payloadLengthUInt16: UInt16
#if os(Linux)
payloadLengthUInt16 = Glibc.htons(tempPayloadLengh)
#else
payloadLengthUInt16 = CFSwapInt16HostToBig(tempPayloadLengh)
#endif
let asBytes = UnsafeMutablePointer(&payloadLengthUInt16)
(UnsafeMutableRawPointer(mutating: bytes)+length+1).copyBytes(from: asBytes, count: 2)
length += 3
} else {

bytes[1] = 127
let tempPayloadLengh = UInt32(payloadLength)
var payloadLengthUInt32: UInt32
#if os(Linux)
payloadLengthUInt32 = Glibc.htonl(tempPayloadLengh)
#else
payloadLengthUInt32 = CFSwapInt32HostToBig(tempPayloadLengh)
#endif
let asBytes = UnsafeMutablePointer(&payloadLengthUInt32)
(UnsafeMutableRawPointer(mutating: bytes)+length+5).copyBytes(from: asBytes, count: 4)
length += 9
}
buffer.append(bytes, length: length)
}
Expand Down

0 comments on commit d7f52b2

Please sign in to comment.