Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error reflection with SwiftProtobuf #46

Open
KennethLaw opened this issue Jun 6, 2019 · 1 comment
Open

Error reflection with SwiftProtobuf #46

KennethLaw opened this issue Jun 6, 2019 · 1 comment

Comments

@KennethLaw
Copy link

KennethLaw commented Jun 6, 2019

struct UserLoginRes {
  // SwiftProtobuf.Message conformance is added in an extension below. See the
  // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
  // methods supported on all messages.

  var code: Int32 {
    get {return _storage._code}
    set {_uniqueStorage()._code = newValue}
  }

  var message: String {
    get {return _storage._message}
    set {_uniqueStorage()._message = newValue}
  }

  var data: UserInfo {
    get {return _storage._data ?? UserInfo()}
    set {_uniqueStorage()._data = newValue}
  }
  /// Returns true if `data` has been explicitly set.
  var hasData: Bool {return _storage._data != nil}
  /// Clears the value of `data`. Subsequent reads from it will return its default value.
  mutating func clearData() {_uniqueStorage()._data = nil}

  var unknownFields = SwiftProtobuf.UnknownStorage()

  init() {}

  fileprivate var _storage = _StorageClass.defaultInstance
}
extension UserLoginRes: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
  static let protoMessageName: String = _protobuf_package + ".UserLoginRes"
  static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
    1: .same(proto: "code"),
    2: .same(proto: "message"),
    3: .same(proto: "data"),
  ]

  fileprivate class _StorageClass {
    var _code: Int32 = 0
    var _message: String = String()
    var _data: UserInfo? = nil

    static let defaultInstance = _StorageClass()

    private init() {}

    init(copying source: _StorageClass) {
      _code = source._code
      _message = source._message
      _data = source._data
    }
  }

  fileprivate mutating func _uniqueStorage() -> _StorageClass {
    if !isKnownUniquelyReferenced(&_storage) {
      _storage = _StorageClass(copying: _storage)
    }
    return _storage
  }
....

Usage:
let realResp = try typeInfo(of: UserLoginRes.self)

Debug:
image

**Q: Can not find property "code" and "message"? Only "unknownFields" and "_storage"? **

@wickwirew
Copy link
Owner

wickwirew commented Jun 6, 2019

This is actually the expected output. It can only get metadata for stored properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants