Exemplo n.º 1
0
        // Token: 0x06000033 RID: 51 RVA: 0x00002D68 File Offset: 0x00000F68
        private static int GetNodeCount(PNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            ArrayNode arrayNode = node as ArrayNode;

            if (arrayNode != null)
            {
                int num = 1;
                foreach (PNode node2 in arrayNode)
                {
                    num += BinaryFormatWriter.GetNodeCount(node2);
                }
                return(num);
            }
            DictionaryNode dictionaryNode = node as DictionaryNode;

            if (dictionaryNode != null)
            {
                int num2 = 1;
                foreach (PNode node3 in dictionaryNode.Values)
                {
                    num2 += BinaryFormatWriter.GetNodeCount(node3);
                }
                num2 += dictionaryNode.Keys.Count;
                return(num2);
            }
            return(1);
        }
Exemplo n.º 2
0
        // Token: 0x0600002F RID: 47 RVA: 0x00002920 File Offset: 0x00000B20
        public void Write(Stream stream, PNode node)
        {
            stream.Write(BinaryFormatWriter._header, 0, BinaryFormatWriter._header.Length);
            List <int> list = new List <int>();
            int        num  = BinaryFormatWriter.GetNodeCount(node);
            byte       b;

            if (num <= 255)
            {
                b = 1;
            }
            else if (num <= 32767)
            {
                b = 2;
            }
            else
            {
                b = 4;
            }
            int host = this.WriteInternal(stream, b, list, node);

            num = list.Count;
            int  num2 = (int)stream.Position;
            byte b2;

            if (num2 <= 255)
            {
                b2 = 1;
            }
            else if (num2 <= 32767)
            {
                b2 = 2;
            }
            else
            {
                b2 = 4;
            }
            for (int i = 0; i < list.Count; i++)
            {
                byte[] array = null;
                switch (b2)
                {
                case 1:
                    array = new byte[]
                    {
                        (byte)list[i]
                    };
                    break;

                case 2:
                    array = BitConverter.GetBytes(EndianConverter.HostToNetworkOrder((short)list[i]));
                    break;

                case 4:
                    array = BitConverter.GetBytes(EndianConverter.HostToNetworkOrder(list[i]));
                    break;
                }
                stream.Write(array, 0, array.Length);
            }
            byte[] array2 = new byte[32];
            array2[6] = b2;
            array2[7] = b;
            BitConverter.GetBytes(EndianConverter.HostToNetworkOrder(num)).CopyTo(array2, 12);
            BitConverter.GetBytes(EndianConverter.HostToNetworkOrder(host)).CopyTo(array2, 20);
            BitConverter.GetBytes(EndianConverter.HostToNetworkOrder(num2)).CopyTo(array2, 28);
            stream.Write(array2, 0, array2.Length);
        }