@@ -36,35 +36,29 @@ public protocol TLVTypeCode {
3636
3737// MARK: - Codable Implementations
3838
39- public extension TLVDecodable where Self: RawRepresentable , Self. RawValue: RawRepresentable , Self. RawValue. RawValue: Integer {
39+ #if swift(>=3.2)
40+
41+ public extension TLVDecodable where Self: RawRepresentable , Self. RawValue: RawRepresentable , Self. RawValue. RawValue == UInt8 {
4042
4143 public init ? ( valueData: Foundation . Data ) {
4244
43- typealias IntegerType = Self . RawValue . RawValue
44-
45- assert ( MemoryLayout< IntegerType> . size == 1 )
46-
4745 guard valueData. count == 1
4846 else { return nil }
4947
5048 let valueByte = valueData [ 0 ]
5149
52- guard let rawValue = RawValue . init ( rawValue: numericCast ( valueByte) as IntegerType )
50+ guard let rawValue = RawValue . init ( rawValue: valueByte)
5351 else { return nil }
5452
5553 self . init ( rawValue: rawValue)
5654 }
5755}
5856
59- public extension TLVEncodable where Self: RawRepresentable , Self. RawValue: RawRepresentable , Self. RawValue. RawValue: Integer {
57+ public extension TLVEncodable where Self: RawRepresentable , Self. RawValue: RawRepresentable , Self. RawValue. RawValue == UInt8 {
6058
6159 public var valueData : Foundation . Data {
6260
63- typealias IntegerType = Self . RawValue . RawValue
64-
65- assert ( MemoryLayout< IntegerType> . size == 1 )
66-
67- let byte = numericCast ( rawValue. rawValue) as UInt8
61+ let byte = rawValue. rawValue
6862
6963 return Data ( [ byte] )
7064 }
@@ -91,3 +85,6 @@ public extension TLVEncodable where Self: RawRepresentable, Self.RawValue: Strin
9185 return data
9286 }
9387}
88+
89+ #endif
90+
0 commit comments