コード例 #1
0
        public static new PartyLeader Deserialize(BitReader br)
        {
            PartyLeader pl = new PartyLeader();

            List<object> data = new List<object>();
            pl.Type = (UniqueIdType)br.ReadByte();

            if (pl.Type != UniqueIdType.Unknown)
            {
                UniqueId.DeserializeId(br, pl);
            }

            return pl;
        }
コード例 #2
0
        public static UniqueId Deserialize(BitReader br)
        {
            List<object> data = new List<object>();
            var type = (UniqueIdType)br.ReadByte();

            UniqueId uid = new UniqueId();
            if (type == UniqueIdType.Steam)
            {
                uid = new SteamId();
            }
            uid.Type = type;

            DeserializeId(br, uid);
            return uid;
        }
コード例 #3
0
ファイル: BitReaderTests.cs プロジェクト: anddudek/anjlab.fx
        public void TestReadBits()
        {
            MemoryStream stream = new MemoryStream(new byte[] { 0xe4, 0x1b, 0x1b, 0xf1, 0xff, 0xbb}); // 11100100, 00011011,  00011011
            BitReader reader = new BitReader(stream);

            Expect(reader.ReadBits(1), EqualTo(0x1));
            Expect(reader.ReadBits(2), EqualTo(0x3));
            Expect(reader.ReadBits(5), EqualTo(0x4));
            ExpectPosition(1, stream);
            Expect(reader.ReadBits(7), EqualTo(0xD));
            ExpectPosition(2, stream);
            Expect(reader.ReadBits(8), EqualTo(0x8D));
            ExpectPosition(3, stream);

            Expect(reader.ReadBits(2), EqualTo(0x3));
            ExpectPosition(4, stream);

            Expect(reader.ReadByte(), EqualTo(0xff));
            ExpectPosition(5, stream);

            Expect(reader.ReadBits(4), EqualTo(0xb));
            Expect(reader.ReadBits(4), EqualTo(0xb));
        }
コード例 #4
0
 protected static void DeserializeId(BitReader br, UniqueId uid)
 {
     if (uid.Type == UniqueIdType.Steam)
     {
         uid.Id = br.ReadBytes(8);
     }
     else if (uid.Type == UniqueIdType.PS4)
     {
         uid.Id = br.ReadBytes(32);
     }
     else if (uid.Type == UniqueIdType.Unknown)
     {
         uid.Id = br.ReadBytes(3); // Will be 0
         if (uid.Id.Sum(x => x) != 0)
         {
             throw new Exception("Unknown id isn't 0, might be lost");
         }
     }
     else if (uid.Type == UniqueIdType.Xbox)
     {
         uid.Id = br.ReadBytes(8);
     }
     else
     {
         throw new ArgumentException(string.Format("Invalid type: {0}. Next bits are {1}", ((int)uid.Type).ToString(), br.GetBits(br.Position, Math.Min(4096, br.Length - br.Position)).ToBinaryString()));
     }
     uid.PlayerNumber = br.ReadByte();
 }