public bool GetFixedSize(ref int size) { if (size < 0) { return(false); } if (_data.Length == 0) { return(true); } // Sensible? size = ProtocolInformation.Padded(size, Alignment); if (_data.Length == 1) { int valueSize = GetSize(this[0]); if (valueSize == -1) { return(false); } size += valueSize; return(true); } if (IsStructlike) { foreach (Signature sig in GetParts()) { if (!sig.GetFixedSize(ref size)) { return(false); } } return(true); } if (IsArray || IsDict) { return(false); } if (IsStruct) { foreach (Signature sig in GetFieldSignatures()) { if (!sig.GetFixedSize(ref size)) { return(false); } } return(true); } // Any other cases? throw new Exception(); }
public void ReadPad(int alignment) { for (int endPos = ProtocolInformation.Padded(_pos, alignment); _pos != endPos; _pos++) { if (_data.Array[_data.Offset + _pos] != 0) { throw new ProtocolException("Read non-zero byte at position " + _pos + " while expecting padding. Value given: " + _data.Array[_data.Offset + _pos]); } } }