public TypeLength(Stream source)
{
// TODO: missing support for TypeLengths that span multiple bytes
var reader = new BinaryReader(source);
var value = reader.ReadByte();
if ((value & ExtraByteMask) != 0)
throw new NotImplementedException("Found multi-byte TypeLength which is currently not supported");
Type = (SMLType)((value & TypeMask) >> 4);
// no idea why this oddity is necessary..
Length = (value & LengthMask) - (Type != SMLType.List ? 1 : 0);
}