Refactor SyncCore

This commit is contained in:
Peter
2019-10-21 16:58:00 +04:00
parent 75aa77faa8
commit 10692a323e
1162 changed files with 12205 additions and 10925 deletions

View File

@@ -0,0 +1,42 @@
import Postbox
public final class CachedResolvedByNamePeer: PostboxCoding {
public let peerId: PeerId?
public let timestamp: Int32
public static func key(name: String) -> ValueBoxKey {
let key: ValueBoxKey
if let nameData = name.data(using: .utf8) {
key = ValueBoxKey(length: nameData.count)
nameData.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
memcpy(key.memory, bytes, nameData.count)
}
} else {
key = ValueBoxKey(length: 0)
}
return key
}
public init(peerId: PeerId?, timestamp: Int32) {
self.peerId = peerId
self.timestamp = timestamp
}
public init(decoder: PostboxDecoder) {
if let peerId = decoder.decodeOptionalInt64ForKey("p") {
self.peerId = PeerId(peerId)
} else {
self.peerId = nil
}
self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0)
}
public func encode(_ encoder: PostboxEncoder) {
if let peerId = self.peerId {
encoder.encodeInt64(peerId.toInt64(), forKey: "p")
} else {
encoder.encodeNil(forKey: "p")
}
encoder.encodeInt32(self.timestamp, forKey: "t")
}
}