DeOps.Implementation.WebCache.Decode C# (CSharp) Method

Decode() public static method

public static Decode ( DeOps.Implementation.Protocol.G2Header root ) : WebCache
root DeOps.Implementation.Protocol.G2Header
return WebCache
        public static WebCache Decode(G2Header root)
        {
            WebCache cache = new WebCache();

            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Address:
                        cache.Address = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_AccessKey:
                        cache.AccessKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_LastSeen:
                        cache.LastSeen = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;

                    case Packet_LastTried:
                        cache.LastTried = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;
                }
            }

            return cache;
        }

Usage Example

コード例 #1
0
ファイル: OpCore.cs プロジェクト: nandub/DeOps
        public static InvitePackage OpenInvite(byte[] decrypted, G2Protocol protocol)
        {
            // if we get down here, opening invite was success

            MemoryStream mem    = new MemoryStream(decrypted);
            PacketStream stream = new PacketStream(mem, protocol, FileAccess.Read);

            InvitePackage package = new InvitePackage();

            G2Header root = null;

            while (stream.ReadPacket(ref root))
            {
                if (root.Name == InvitePacket.Info)
                {
                    package.Info = OneWayInvite.Decode(root);
                }

                if (root.Name == InvitePacket.Contact)
                {
                    package.Contacts.Add(DhtContact.ReadPacket(root));
                }

                if (root.Name == InvitePacket.WebCache)
                {
                    package.Caches.Add(WebCache.Decode(root));
                }
            }

            return(package);
        }