gRPC.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2016, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #if SWIFT_PACKAGE
  17. import CgRPC
  18. #endif
  19. import Foundation // for String.Encoding
  20. public final class gRPC {
  21. private init() { } // Static members only.
  22. /// Initializes gRPC system
  23. public static func initialize() {
  24. grpc_init()
  25. }
  26. /// Shuts down gRPC system
  27. public static func shutdown() {
  28. grpc_shutdown()
  29. }
  30. /// Returns version of underlying gRPC library
  31. ///
  32. /// Returns: gRPC version string
  33. public static var version: String {
  34. // These two should always be valid UTF-8 strings, so we can forcibly unwrap them.
  35. return String(cString: grpc_version_string(), encoding: String.Encoding.utf8)!
  36. }
  37. /// Returns name associated with gRPC version
  38. ///
  39. /// Returns: gRPC version name
  40. public static var gStandsFor: String {
  41. return String(cString: grpc_g_stands_for(), encoding: String.Encoding.utf8)!
  42. }
  43. }