@@ -19,13 +19,13 @@ import Foundation
1919
2020internal struct BinaryDecoder : Decoder {
2121 // Current position
22- private var p : UnsafePointer < UInt8 >
22+ private var p : UnsafeRawPointer
2323 // Remaining bytes in input.
2424 private var available : Int
2525 // Position of start of field currently being parsed
26- private var fieldStartP : UnsafePointer < UInt8 >
26+ private var fieldStartP : UnsafeRawPointer
2727 // Position of end of field currently being parsed, nil if we don't know.
28- private var fieldEndP : UnsafePointer < UInt8 > ?
28+ private var fieldEndP : UnsafeRawPointer ?
2929 // Whether or not the field value has actually been parsed
3030 private var consumed = true
3131 // Wire format for last-examined field
@@ -51,7 +51,7 @@ internal struct BinaryDecoder: Decoder {
5151 private var complete : Bool { return available == 0 }
5252
5353 internal init (
54- forReadingFrom pointer: UnsafePointer < UInt8 > ,
54+ forReadingFrom pointer: UnsafeRawPointer ,
5555 count: Int ,
5656 options: BinaryDecodingOptions ,
5757 extensions: ExtensionMap ? = nil
@@ -66,7 +66,7 @@ internal struct BinaryDecoder: Decoder {
6666 }
6767
6868 internal init (
69- forReadingFrom pointer: UnsafePointer < UInt8 > ,
69+ forReadingFrom pointer: UnsafeRawPointer ,
7070 count: Int ,
7171 parent: BinaryDecoder
7272 ) {
@@ -878,8 +878,7 @@ internal struct BinaryDecoder: Decoder {
878878 var field = Data ( count: fieldSize)
879879 field. withUnsafeMutableBytes { ( body: UnsafeMutableRawBufferPointer ) in
880880 if let baseAddress = body. baseAddress, body. count > 0 {
881- let pointer = baseAddress. assumingMemoryBound ( to: UInt8 . self)
882- var encoder = BinaryEncoder ( forWritingInto: pointer)
881+ var encoder = BinaryEncoder ( forWritingInto: baseAddress)
883882 encoder. startField ( tag: fieldTag)
884883 encoder. putVarInt ( value: Int64 ( bodySize) )
885884 for v in extras {
@@ -1209,8 +1208,7 @@ internal struct BinaryDecoder: Decoder {
12091208 var wasDecoded = false
12101209 try data. withUnsafeBytes { ( body: UnsafeRawBufferPointer ) in
12111210 if let baseAddress = body. baseAddress, body. count > 0 {
1212- let pointer = baseAddress. assumingMemoryBound ( to: UInt8 . self)
1213- var extDecoder = BinaryDecoder ( forReadingFrom: pointer,
1211+ var extDecoder = BinaryDecoder ( forReadingFrom: baseAddress,
12141212 count: body. count,
12151213 parent: self )
12161214 // Prime the decode to be correct.
@@ -1253,8 +1251,7 @@ internal struct BinaryDecoder: Decoder {
12531251 var payload = Data ( count: payloadSize)
12541252 payload. withUnsafeMutableBytes { ( body: UnsafeMutableRawBufferPointer ) in
12551253 if let baseAddress = body. baseAddress, body. count > 0 {
1256- let pointer = baseAddress. assumingMemoryBound ( to: UInt8 . self)
1257- var encoder = BinaryEncoder ( forWritingInto: pointer)
1254+ var encoder = BinaryEncoder ( forWritingInto: baseAddress)
12581255 encoder. putBytesValue ( value: data)
12591256 }
12601257 }
@@ -1297,14 +1294,14 @@ internal struct BinaryDecoder: Decoder {
12971294 if available < 1 {
12981295 throw BinaryDecodingError . truncated
12991296 }
1300- var c = p [ 0 ]
1297+ var c = p. load ( fromByteOffset : 0 , as : UInt8 . self )
13011298 while ( c & 0x80 ) != 0 {
13021299 p += 1
13031300 available -= 1
13041301 if available < 1 {
13051302 throw BinaryDecodingError . truncated
13061303 }
1307- c = p [ 0 ]
1304+ c = p. load ( fromByteOffset : 0 , as : UInt8 . self )
13081305 }
13091306 p += 1
13101307 available -= 1
@@ -1382,7 +1379,7 @@ internal struct BinaryDecoder: Decoder {
13821379 }
13831380 var start = p
13841381 var length = available
1385- var c = start [ 0 ]
1382+ var c = start. load ( fromByteOffset : 0 , as : UInt8 . self )
13861383 start += 1
13871384 length -= 1
13881385 if c & 0x80 == 0 {
@@ -1396,7 +1393,7 @@ internal struct BinaryDecoder: Decoder {
13961393 if length < 1 || shift > 63 {
13971394 throw BinaryDecodingError . malformedProtobuf
13981395 }
1399- c = start [ 0 ]
1396+ c = start. load ( fromByteOffset : 0 , as : UInt8 . self )
14001397 start += 1
14011398 length -= 1
14021399 value |= UInt64 ( c & 0x7f ) << shift
@@ -1448,10 +1445,8 @@ internal struct BinaryDecoder: Decoder {
14481445 /// helper handles all four-byte number types.
14491446 private mutating func decodeFourByteNumber< T> ( value: inout T ) throws {
14501447 guard available >= 4 else { throw BinaryDecodingError . truncated}
1451- withUnsafeMutablePointer ( to: & value) { ip -> Void in
1452- let dest = UnsafeMutableRawPointer ( ip) . assumingMemoryBound ( to: UInt8 . self)
1453- let src = UnsafeRawPointer ( p) . assumingMemoryBound ( to: UInt8 . self)
1454- dest. initialize ( from: src, count: 4 )
1448+ withUnsafeMutableBytes ( of: & value) { dest -> Void in
1449+ dest. copyMemory ( from: UnsafeRawBufferPointer ( start: p, count: 4 ) )
14551450 }
14561451 consume ( length: 4 )
14571452 }
@@ -1460,10 +1455,8 @@ internal struct BinaryDecoder: Decoder {
14601455 /// helper handles all eight-byte number types.
14611456 private mutating func decodeEightByteNumber< T> ( value: inout T ) throws {
14621457 guard available >= 8 else { throw BinaryDecodingError . truncated}
1463- withUnsafeMutablePointer ( to: & value) { ip -> Void in
1464- let dest = UnsafeMutableRawPointer ( ip) . assumingMemoryBound ( to: UInt8 . self)
1465- let src = UnsafeRawPointer ( p) . assumingMemoryBound ( to: UInt8 . self)
1466- dest. initialize ( from: src, count: 8 )
1458+ withUnsafeMutableBytes ( of: & value) { dest -> Void in
1459+ dest. copyMemory ( from: UnsafeRawBufferPointer ( start: p, count: 8 ) )
14671460 }
14681461 consume ( length: 8 )
14691462 }
@@ -1490,7 +1483,7 @@ internal struct BinaryDecoder: Decoder {
14901483
14911484 /// Private: Get the start and length for the body of
14921485 // a length-delimited field.
1493- private mutating func getFieldBodyBytes( count: inout Int ) throws -> UnsafePointer < UInt8 > {
1486+ private mutating func getFieldBodyBytes( count: inout Int ) throws -> UnsafeRawPointer {
14941487 let length = try decodeVarint ( )
14951488 if length <= UInt64 ( available) {
14961489 count = Int ( length)
0 commit comments