From adbb6f61292a679ca60eb632f1acc9faea29f58d Mon Sep 17 00:00:00 2001 From: Ali <> Date: Wed, 22 Sep 2021 12:00:05 +0300 Subject: [PATCH] Fix empty object encoding --- .../Utils/Encoder/AdaptedPostboxEncoder.swift | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/submodules/Postbox/Sources/Utils/Encoder/AdaptedPostboxEncoder.swift b/submodules/Postbox/Sources/Utils/Encoder/AdaptedPostboxEncoder.swift index 2e0854f5d0..695f9663a8 100644 --- a/submodules/Postbox/Sources/Utils/Encoder/AdaptedPostboxEncoder.swift +++ b/submodules/Postbox/Sources/Utils/Encoder/AdaptedPostboxEncoder.swift @@ -42,7 +42,28 @@ final class _AdaptedPostboxEncoder { } func makeData(addHeader: Bool, isDictionary: Bool) -> (Data, ValueType) { - return self.container!.makeData(addHeader: addHeader, isDictionary: isDictionary) + if let container = self.container { + return container.makeData(addHeader: addHeader, isDictionary: isDictionary) + } else { + let buffer = WriteBuffer() + + if addHeader { + var typeHash: Int32 = self.typeHash + buffer.write(&typeHash, offset: 0, length: 4) + } + + let innerEncoder = PostboxEncoder() + let data = innerEncoder.makeData() + + if addHeader { + var length: Int32 = Int32(data.count) + buffer.write(&length, offset: 0, length: 4) + } + + buffer.write(data) + + return (buffer.makeData(), .Object) + } } }