internal static TLObjectWithExtra ReadRootObject(ReadOnlySpan <byte> input)
        {
            var reader = new TdJsonReader(input);

            var(obj, converter) = ConsumeObjectProlog(ref reader);
            var result = new TLObjectWithExtra()
            {
                TLObject = obj
            };
            var hasextra = false;

            while (reader.MoveToNextObjectMember())
            {
                var keystr = reader.ReadStringUTF8();
                reader.MoveToObjectMemberValue();
                if (!hasextra && keystr.SequenceEqual(@extra_bytes))
                {
                    result.Extra = reader.ReadInt64String();
                    hasextra     = true;
                    continue;
                }
                if (!converter.TdJsonReadItem(ref reader, obj, keystr))
                {
                    throw new TdJsonReaderException(reader.BytesConsumed, string.Format("unrecognized key {0} in type {1}", Encoding.UTF8.GetString(keystr), obj.GetType()));
                }
            }
            return(result);
        }
        public static void DumpObject(IBufferWriter <byte> buffer, TLObjectWithExtra obj)
        {
            using var writer = new Utf8JsonWriter(buffer, new JsonWriterOptions { Indented = false });
            writer.WriteTLObjectValue(obj);
            writer.Flush();
            var span = buffer.GetSpan(1);

            span[0] = 0;
            buffer.Advance(1);
        }
Beispiel #3
0
        public static void WriteTLObjectValue(this Utf8JsonWriter writer, TLObjectWithExtra obj)
        {
            if (obj.TLObject == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            var converter = TLObjectFactory.GetConverterForTLObject(obj.TLObject);

            converter.TdJsonWriteUnclosedObject(writer, obj.TLObject);
            if (obj.Extra.HasValue)
            {
                writer.WritePropertyName(ExtraPropertyName);
                writer.WriteInt64String(obj.Extra.Value);
            }
            writer.WriteEndObject();
        }