mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
47 lines
1.5 KiB
Swift
47 lines
1.5 KiB
Swift
import Foundation
|
|
|
|
final class DeviceContactImportInfoTable: Table {
|
|
static func tableSpec(_ id: Int32) -> ValueBoxTable {
|
|
return ValueBoxTable(id: id, keyType: .binary, compactValuesOnCreation: true)
|
|
}
|
|
|
|
func get(_ identifier: ValueBoxKey) -> PostboxCoding? {
|
|
if let value = self.valueBox.get(self.table, key: identifier), let object = PostboxDecoder(buffer: value).decodeRootObject() {
|
|
return object
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func set(_ identifier: ValueBoxKey, value: PostboxCoding?) {
|
|
if let value = value {
|
|
let encoder = PostboxEncoder()
|
|
encoder.encodeRootObject(value)
|
|
withExtendedLifetime(encoder, {
|
|
self.valueBox.set(self.table, key: identifier, value: encoder.readBufferNoCopy())
|
|
})
|
|
} else {
|
|
self.valueBox.remove(self.table, key: identifier, secure: false)
|
|
}
|
|
}
|
|
|
|
func getIdentifiers() -> [ValueBoxKey] {
|
|
var result: [ValueBoxKey] = []
|
|
self.valueBox.scan(self.table, keys: { key in
|
|
result.append(key)
|
|
return true
|
|
})
|
|
return result
|
|
}
|
|
|
|
func enumerateDeviceContactImportInfoItems(_ f: (ValueBoxKey, PostboxCoding) -> Bool) {
|
|
self.valueBox.scan(self.table, values: { key, value in
|
|
if let object = PostboxDecoder(buffer: value).decodeRootObject() {
|
|
return f(key, object)
|
|
} else {
|
|
return true
|
|
}
|
|
})
|
|
}
|
|
}
|