public static DatToken Load(DatBinaryReader reader) { var tokenByte = reader.ReadByte(); if (Enum.IsDefined(typeof(DatTokenType), tokenByte) == false) { throw new Exception($"Unable to parse DatToken with id = {tokenByte}"); } var token = new DatToken { TokenType = (DatTokenType)tokenByte }; switch (token.TokenType) { case DatTokenType.Call: case DatTokenType.CallExternal: case DatTokenType.PushInt: case DatTokenType.PushVar: case DatTokenType.PushInstance: case DatTokenType.Jump: case DatTokenType.JumpIf: case DatTokenType.SetInstance: token.IntParam = reader.ReadInt32(); break; case DatTokenType.PushArrayVar: token.IntParam = reader.ReadInt32(); token.ByteParam = reader.ReadByte(); break; } return(token); }
private IEnumerable <DatToken> LoadTokens(DatBinaryReader reader) { int stackLength = reader.ReadInt32(); List <DatToken> result = new List <DatToken>(); while (stackLength > 0) { var token = DatToken.Load(reader); result.Add(token); stackLength -= token.Size; } return(result); }