UnsafeRawPointer+Shims.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. extension UnsafeRawPointer {
  15. /// A shim subscript for UnsafeRawPointer aiming to maintain code consistency.
  16. ///
  17. /// We can remove this shim when we rewrite the code to use buffer pointers.
  18. internal subscript(_ offset: Int) -> UInt8 {
  19. get {
  20. self.load(fromByteOffset: offset, as: UInt8.self)
  21. }
  22. }
  23. }
  24. extension UnsafeMutableRawPointer {
  25. /// A shim subscript for UnsafeMutableRawPointer aiming to maintain code consistency.
  26. ///
  27. /// We can remove this shim when we rewrite the code to use buffer pointers.
  28. internal subscript(_ offset: Int) -> UInt8 {
  29. get {
  30. self.load(fromByteOffset: offset, as: UInt8.self)
  31. }
  32. set {
  33. self.storeBytes(of: newValue, toByteOffset: offset, as: UInt8.self)
  34. }
  35. }
  36. }