Пример #1
0
        public override async Task <TSet> ReadSetBeginAsync(CancellationToken cancellationToken)
        {
            var set = new TSet();

            await ReadJsonArrayStartAsync(cancellationToken);

            set.ElementType = TJSONProtocolHelper.GetTypeIdForTypeName(await ReadJsonStringAsync(false, cancellationToken));
            set.Count       = (int) await ReadJsonIntegerAsync(cancellationToken);

            return(set);
        }
Пример #2
0
        public override async ValueTask <TList> ReadListBeginAsync(CancellationToken cancellationToken)
        {
            var list = new TList();

            await ReadJsonArrayStartAsync(cancellationToken);

            list.ElementType = TJSONProtocolHelper.GetTypeIdForTypeName(await ReadJsonStringAsync(false, cancellationToken));
            list.Count       = (int) await ReadJsonIntegerAsync(cancellationToken);

            return(list);
        }
Пример #3
0
        public override async Task <TMap> ReadMapBeginAsync(CancellationToken cancellationToken)
        {
            var map = new TMap();

            await ReadJsonArrayStartAsync(cancellationToken);

            map.KeyType   = TJSONProtocolHelper.GetTypeIdForTypeName(await ReadJsonStringAsync(false, cancellationToken));
            map.ValueType = TJSONProtocolHelper.GetTypeIdForTypeName(await ReadJsonStringAsync(false, cancellationToken));
            map.Count     = (int) await ReadJsonIntegerAsync(cancellationToken);
            await ReadJsonObjectStartAsync(cancellationToken);

            return(map);
        }
Пример #4
0
        public override async Task <TField> ReadFieldBeginAsync(CancellationToken cancellationToken)
        {
            var field = new TField();
            var ch    = await Reader.PeekAsync(cancellationToken);

            if (ch == TJSONProtocolConstants.RightBrace[0])
            {
                field.Type = TType.Stop;
            }
            else
            {
                field.ID = (short) await ReadJsonIntegerAsync(cancellationToken);
                await ReadJsonObjectStartAsync(cancellationToken);

                field.Type = TJSONProtocolHelper.GetTypeIdForTypeName(await ReadJsonStringAsync(false, cancellationToken));
            }
            return(field);
        }
Пример #5
0
        public void GetTypeIdForTypeName_Test()
        {
            // input/output
            var sets = new List <Tuple <TType, byte[]> >
            {
                new Tuple <TType, byte[]>(TType.Bool, TJSONProtocolConstants.TypeNames.NameBool),
                new Tuple <TType, byte[]>(TType.Byte, TJSONProtocolConstants.TypeNames.NameByte),
                new Tuple <TType, byte[]>(TType.I16, TJSONProtocolConstants.TypeNames.NameI16),
                new Tuple <TType, byte[]>(TType.I32, TJSONProtocolConstants.TypeNames.NameI32),
                new Tuple <TType, byte[]>(TType.I64, TJSONProtocolConstants.TypeNames.NameI64),
                new Tuple <TType, byte[]>(TType.Double, TJSONProtocolConstants.TypeNames.NameDouble),
                new Tuple <TType, byte[]>(TType.String, TJSONProtocolConstants.TypeNames.NameString),
                new Tuple <TType, byte[]>(TType.Struct, TJSONProtocolConstants.TypeNames.NameStruct),
                new Tuple <TType, byte[]>(TType.Map, TJSONProtocolConstants.TypeNames.NameMap),
                new Tuple <TType, byte[]>(TType.Set, TJSONProtocolConstants.TypeNames.NameSet),
                new Tuple <TType, byte[]>(TType.List, TJSONProtocolConstants.TypeNames.NameList),
            };

            foreach (var t in sets)
            {
                Assert.IsTrue(TJSONProtocolHelper.GetTypeIdForTypeName(t.Item2) == t.Item1, $"Wrong mapping of TypeName {t.Item2} to TType: {t.Item1}");
            }
        }
Пример #6
0
 public void GetTypeIdForTypeName_TStopTypeName_Test()
 {
     TJSONProtocolHelper.GetTypeIdForTypeName(new [] { (byte)TType.Stop, (byte)TType.Stop });
 }
Пример #7
0
 public void GetTypeIdForTypeName_EmptyName_Test()
 {
     TJSONProtocolHelper.GetTypeIdForTypeName(new byte[] {});
 }
Пример #8
0
 public void GetTypeIdForTypeName_NonExistingTypeName_Test()
 {
     TJSONProtocolHelper.GetTypeIdForTypeName(new byte[] { 100 });
 }