Ejemplo n.º 1
0
        private static int ProcessListLessThan55Bytes(byte[] msgData, int level, int levelToIndex,
                                                      RLPCollection rlpCollection, int currentPosition)
        {
            var length        = msgData[currentPosition] - OFFSET_SHORT_LIST;
            var rlpDataLength = length + 1;
            var rlpData       = new byte[length + 1];

            Array.Copy(msgData, currentPosition, rlpData, 0, rlpDataLength);

            var newLevelCollection = new RLPCollection {
                RLPData = rlpData
            };

            if (length > 0)
            {
                Decode(msgData, level + 1, currentPosition + 1, currentPosition + rlpDataLength,
                       levelToIndex,
                       newLevelCollection);
            }

            rlpCollection.Add(newLevelCollection);

            currentPosition += rlpDataLength;
            return(currentPosition);
        }
Ejemplo n.º 2
0
        private static int ProcessNullItem(RLPCollection rlpCollection, int currentPosition)
        {
            var item    = EMPTY_BYTE_ARRAY;
            var rlpItem = new RLPItem(item);

            rlpCollection.Add(rlpItem);
            currentPosition += 1;
            return(currentPosition);
        }
Ejemplo n.º 3
0
        private static int ProcessSingleByteItem(byte[] msgData, RLPCollection rlpCollection, int currentPosition)
        {
            byte[] item = { msgData[currentPosition] };

            var rlpItem = new RLPItem(item);

            rlpCollection.Add(rlpItem);
            currentPosition += 1;
            return(currentPosition);
        }
Ejemplo n.º 4
0
        private static int ProcessItemLessThan55Bytes(byte[] msgData, RLPCollection rlpCollection, int currentPosition)
        {
            var length = (byte)(msgData[currentPosition] - OFFSET_SHORT_ITEM);

            var item = new byte[length];

            Array.Copy(msgData, currentPosition + 1, item, 0, length);

            var rlpPrefix = new byte[2];

            Array.Copy(msgData, currentPosition, rlpPrefix, 0, 2);

            var rlpItem = new RLPItem(item);

            rlpCollection.Add(rlpItem);
            currentPosition += 1 + length;
            return(currentPosition);
        }
Ejemplo n.º 5
0
        private static int ProcessListBiggerThan55Bytes(byte[] msgData, int level, int levelToIndex,
                                                        RLPCollection rlpCollection, int currentPosition)
        {
            var lengthOfLength = (byte)(msgData[currentPosition] - OFFSET_LONG_LIST);
            var length         = CalculateLength(lengthOfLength, msgData, currentPosition);

            var rlpDataLength = lengthOfLength + length + 1;
            var rlpData       = new byte[rlpDataLength];

            Array.Copy(msgData, currentPosition, rlpData, 0, rlpDataLength);
            var newLevelCollection = new RLPCollection {
                RLPData = rlpData
            };

            Decode(msgData, level + 1, currentPosition + lengthOfLength + 1,
                   currentPosition + rlpDataLength, levelToIndex,
                   newLevelCollection);
            rlpCollection.Add(newLevelCollection);

            currentPosition += rlpDataLength;
            return(currentPosition);
        }
Ejemplo n.º 6
0
        private static int ProcessItemBiggerThan55Bytes(byte[] msgData, RLPCollection rlpCollection,
                                                        int currentPosition)
        {
            var lengthOfLength = (byte)(msgData[currentPosition] - OFFSET_LONG_ITEM);
            var length         = CalculateLength(lengthOfLength, msgData, currentPosition);

            // now we can parse an item for data[1]..data[length]
            var item = new byte[length];

            Array.Copy(msgData, currentPosition + lengthOfLength + 1, item,
                       0, length);

            var rlpPrefix = new byte[lengthOfLength + 1];

            Array.Copy(msgData, currentPosition, rlpPrefix, 0,
                       lengthOfLength + 1);

            var rlpItem = new RLPItem(item);

            rlpCollection.Add(rlpItem);
            currentPosition += lengthOfLength + length + 1;
            return(currentPosition);
        }