Coding fixes

This commit is contained in:
Ali 2021-09-07 15:22:50 +04:00
parent 40736ca677
commit e6308196fe
3 changed files with 16 additions and 7 deletions

View File

@ -671,6 +671,20 @@ public final class PostboxEncoder {
self.buffer.write(value) self.buffer.write(value)
} }
func encodeInnerObjectDataWithHeader(typeHash: Int32, data: Data, valueType: ValueType, forKey key: String) {
self.encodeKey(key)
var t: Int8 = valueType.rawValue
self.buffer.write(&t, offset: 0, length: 1)
var typeHash = typeHash
self.buffer.write(&typeHash, offset: 0, length: 4)
var length: Int32 = Int32(data.count)
self.buffer.write(&length, offset: 0, length: 4)
self.buffer.write(data)
}
public let sharedWriteBuffer = WriteBuffer() public let sharedWriteBuffer = WriteBuffer()
} }

View File

@ -44,12 +44,7 @@ extension _AdaptedPostboxEncoder.KeyedContainer: KeyedEncodingContainerProtocol
if let value = value as? Data { if let value = value as? Data {
self.encoder.encodeData(value, forKey: key.stringValue) self.encoder.encodeData(value, forKey: key.stringValue)
} else if let value = value as? AdaptedPostboxEncoder.RawObjectData { } else if let value = value as? AdaptedPostboxEncoder.RawObjectData {
let typeHash: Int32 = value.typeHash self.encoder.encodeInnerObjectDataWithHeader(typeHash: value.typeHash, data: value.data, valueType: .Object, forKey: key.stringValue)
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
try! value.encode(to: innerEncoder)
let (data, valueType) = innerEncoder.makeData(addHeader: true, isDictionary: false)
self.encoder.encodeInnerObjectData(data, valueType: valueType, forKey: key.stringValue)
} else { } else {
let typeHash: Int32 = murMurHashString32("\(type(of: value))") let typeHash: Int32 = murMurHashString32("\(type(of: value))")
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash) let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)

View File

@ -69,7 +69,7 @@ public final class ChatThemes: Codable, Equatable {
func _internal_getChatThemes(accountManager: AccountManager<TelegramAccountManagerTypes>, network: Network, forceUpdate: Bool = false, onlyCached: Bool = false) -> Signal<[ChatTheme], NoError> { func _internal_getChatThemes(accountManager: AccountManager<TelegramAccountManagerTypes>, network: Network, forceUpdate: Bool = false, onlyCached: Bool = false) -> Signal<[ChatTheme], NoError> {
let fetch: ([ChatTheme]?, Int32?) -> Signal<[ChatTheme], NoError> = { current, hash in let fetch: ([ChatTheme]?, Int32?) -> Signal<[ChatTheme], NoError> = { current, hash in
return network.request(Api.functions.account.getChatThemes(hash: hash ?? 0)) return network.request(Api.functions.account.getChatThemes(hash: 0))
|> retryRequest |> retryRequest
|> mapToSignal { result -> Signal<[ChatTheme], NoError> in |> mapToSignal { result -> Signal<[ChatTheme], NoError> in
switch result { switch result {