public void Byte_Test() { var codeGenerator = new ByteCodeGenerator(); byte value = 245; var fieldCodec = codeGenerator.CreateFieldCodec(1); var stream = new MemoryStream(); var output = new CodedOutputStream(stream, true); fieldCodec.WriteTagAndValue(output, value); output.Flush(); stream.Position = 0; var input = new CodedInputStream(stream); Assert.Equal(WireFormat.MakeTag(1, codeGenerator.WireType), input.ReadTag()); Assert.Equal(value, fieldCodec.Read(input)); }
public static void CompileFile(string[] args) { string sourceFilePath = null; try { sourceFilePath = args[0]; } catch { throw new CommandException("Could not obtain input filename"); } var extension = Path.GetExtension(sourceFilePath); var src = File.ReadAllText(sourceFilePath); var language = LanguageProcessor.GetLanguage(extension); if (language == Language.Unknown) { throw new CommandException("Unsupported smart contract language extension: " + extension); } var processor = LanguageProcessor.GetProcessor(language); var tokens = processor.Lexer.Execute(src); var tree = processor.Parser.Execute(tokens); var compiler = new Compiler(); var instructions = compiler.Execute(tree); var generator = new ByteCodeGenerator(tree, instructions); var outputName = sourceFilePath.Replace(extension, ScriptExtension); try { File.WriteAllBytes(outputName, generator.Script); } catch { throw new CommandException("Error generating " + outputName); } }