/src/swift-protobuf/Sources/SwiftProtobuf/UnsafeRawPointer+Shims.swift
Line | Count | Source |
1 | | // Sources/SwiftProtobuf/UnsafeRawPointer+Shims.swift - Shims for UnsafeRawPointer and friends |
2 | | // |
3 | | // Copyright (c) 2019 Apple Inc. and the project authors |
4 | | // Licensed under Apache License v2.0 with Runtime Library Exception |
5 | | // |
6 | | // See LICENSE.txt for license information: |
7 | | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt |
8 | | // |
9 | | // ----------------------------------------------------------------------------- |
10 | | /// |
11 | | /// Shims for UnsafeRawPointer and friends. |
12 | | /// |
13 | | // ----------------------------------------------------------------------------- |
14 | | |
15 | | extension UnsafeRawPointer { |
16 | | /// A shim subscript for UnsafeRawPointer aiming to maintain code consistency. |
17 | | /// |
18 | | /// We can remove this shim when we rewrite the code to use buffer pointers. |
19 | | internal subscript(_ offset: Int) -> UInt8 { |
20 | 164M | get { |
21 | 164M | self.load(fromByteOffset: offset, as: UInt8.self) |
22 | 164M | } |
23 | | } |
24 | | } |
25 | | |
26 | | extension UnsafeMutableRawPointer { |
27 | | /// A shim subscript for UnsafeMutableRawPointer aiming to maintain code consistency. |
28 | | /// |
29 | | /// We can remove this shim when we rewrite the code to use buffer pointers. |
30 | | internal subscript(_ offset: Int) -> UInt8 { |
31 | 0 | get { |
32 | 0 | self.load(fromByteOffset: offset, as: UInt8.self) |
33 | 0 | } |
34 | 0 | set { |
35 | 0 | self.storeBytes(of: newValue, toByteOffset: offset, as: UInt8.self) |
36 | 0 | } |
37 | | } |
38 | | } |