mirror of
https://github.com/apple/swift-nio-extras.git
synced 2025-05-18 03:09:12 +08:00
Removes integer backing from ByteLength enum.
Motivation: To simplify the enum from the calling perspective. Modifications: Removed integer backing. Removed a string addition from a test that wasn’t actually adding anything. Result: The integer for the enum can not be seen publicly.
This commit is contained in:
parent
2dd4c26993
commit
97ffd10cae
@ -18,11 +18,28 @@ import NIO
|
|||||||
/// An enumeration to describe the length of a piece of data in bytes.
|
/// An enumeration to describe the length of a piece of data in bytes.
|
||||||
/// It is contained to lengths that can be converted to integer types.
|
/// It is contained to lengths that can be converted to integer types.
|
||||||
///
|
///
|
||||||
public enum ByteLength: Int {
|
public enum ByteLength {
|
||||||
case one = 1
|
case one
|
||||||
case two = 2
|
case two
|
||||||
case four = 4
|
case four
|
||||||
case eight = 8
|
case eight
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ByteLength {
|
||||||
|
|
||||||
|
fileprivate var length: Int {
|
||||||
|
|
||||||
|
switch self {
|
||||||
|
case .one:
|
||||||
|
return 1
|
||||||
|
case .two:
|
||||||
|
return 2
|
||||||
|
case .four:
|
||||||
|
return 4
|
||||||
|
case .eight:
|
||||||
|
return 8
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -67,7 +84,7 @@ public final class LengthFieldBasedFrameDecoder: ByteToMessageDecoder {
|
|||||||
|
|
||||||
public func decode(ctx: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
|
public func decode(ctx: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
|
||||||
|
|
||||||
guard let lengthFieldSlice = buffer.readSlice(length: self.lengthFieldLength.rawValue) else {
|
guard let lengthFieldSlice = buffer.readSlice(length: self.lengthFieldLength.length) else {
|
||||||
return .needMoreData
|
return .needMoreData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,6 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase {
|
|||||||
try? self.channel.pipeline.add(handler: self.decoderUnderTest).wait()
|
try? self.channel.pipeline.add(handler: self.decoderUnderTest).wait()
|
||||||
|
|
||||||
var buffer = self.channel.allocator.buffer(capacity: 1)
|
var buffer = self.channel.allocator.buffer(capacity: 1)
|
||||||
buffer.write(string: "")
|
|
||||||
XCTAssertFalse(try self.channel.writeInbound(buffer))
|
XCTAssertFalse(try self.channel.writeInbound(buffer))
|
||||||
XCTAssertFalse(try self.channel.finish())
|
XCTAssertFalse(try self.channel.finish())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user