public Object Clone() { TLStruct result = new TLStruct(tag, length); result.bytesRead = bytesRead; return(result); }
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; } }
public int getTag() { if (state.Count == 0) { throw new Exception("Tag not yet read."); } TLStruct currentObject = state.Peek(); return(currentObject.getTag()); }
public bool isAtStartOfLength() { if (state.Count == 0) { return(false); } TLStruct currentObject = state.Peek(); return(currentObject.getLength() < 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; }
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); }
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; }
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; }