Beispiel #1
0
                public Object Clone()
                {
                    TLStruct result = new TLStruct(tag, length);

                    result.bytesRead = bytesRead;
                    return(result);
                }
Beispiel #2
0
            public void updateValueBytesRead(int n)
            {
                if (state.Count == 0)
                {
                    return;
                }
                TLStruct currentObject = state.Peek();
                int      bytesLeft     = currentObject.getLength() - currentObject.getBytesRead();

                if (n > bytesLeft)
                {
                    throw new ArgumentException("Cannot read " + n + " bytes! Only " + bytesLeft + " bytes left in this TLV object " + currentObject);
                }
                currentObject.updateValueBytesRead(n);
                int currentLength = currentObject.getLength();

                if (currentObject.getBytesRead() == currentLength)
                {
                    state.Pop();
                    /* Recursively update parent. */
                    updateValueBytesRead(currentLength);
                    _isAtStartOfTag = true;
                }
                else
                {
                    _isAtStartOfTag = false;
                }
            }
Beispiel #3
0
            public int getTag()
            {
                if (state.Count == 0)
                {
                    throw new Exception("Tag not yet read.");
                }
                TLStruct currentObject = state.Peek();

                return(currentObject.getTag());
            }
Beispiel #4
0
            public bool isAtStartOfLength()
            {
                if (state.Count == 0)
                {
                    return(false);
                }
                TLStruct currentObject = state.Peek();

                return(currentObject.getLength() < 0);
            }
Beispiel #5
0
            public void setTagRead(int tag, int bytesRead)
            {
                TLStruct obj = new TLStruct(tag, -1);

                if (state.Count != 0)
                {
                    TLStruct parent = state.Peek();
                    parent.updateValueBytesRead(bytesRead);
                }
                state.Push(obj);
                _isAtStartOfTag = false;
            }
Beispiel #6
0
            public int getLength()
            {
                if (state.Count == 0)
                {
                    throw new Exception("Length not yet read.");
                }
                TLStruct currentObject = state.Peek();
                int      length        = currentObject.getLength();

                if (length < 0)
                {
                    throw new Exception("Length not yet read.");
                }
                return(length);
            }
Beispiel #7
0
            public void setLengthRead(int length, int bytesRead)
            {
                if (length < 0)
                {
                    throw new ArgumentException("Cannot set negative length (length = " + length + ").");
                }
                TLStruct obj = state.Pop();

                if (state.Count != 0)
                {
                    TLStruct parent = state.Peek();
                    parent.updateValueBytesRead(bytesRead);
                }
                obj.setLength(length);
                state.Push(obj);
                _isAtStartOfTag = false;
            }
Beispiel #8
0
            public int getValueBytesLeft()
            {
                if (state.Count == 0)
                {
                    throw new Exception("Not yet reading value.");
                }
                TLStruct currentObject = state.Peek();
                int      currentLength = currentObject.getLength();

                if (currentLength < 0)
                {
                    throw new Exception("Not yet reading value.");
                }
                int currentBytesRead = currentObject.getBytesRead();

                return(currentLength - currentBytesRead);
            }
 public Object Clone()
 {
     TLStruct result = new TLStruct(tag, length);
     result.bytesRead = bytesRead;
     return result;
 }
 public void setTagRead(int tag, int bytesRead)
 {
     TLStruct obj = new TLStruct(tag, -1);
     if (state.Count != 0)
     {
         TLStruct parent = state.Peek();
         parent.updateValueBytesRead(bytesRead);
     }
     state.Push(obj);
     _isAtStartOfTag = false;
 }