public static void GenerateProtoFile(RuntimeTypeModel model, string path) { using (StreamWriter writer = File.CreateText(path)) { writer.Write(model.GetSchema(null)); } }
private static void CreateProtoFile() { RuntimeTypeModel typeModel = GetModel(); using (FileStream stream = File.Open("model.proto", FileMode.Create)) { byte[] protoBytes = Encoding.UTF8.GetBytes(typeModel.GetSchema(null)); stream.Write(protoBytes, 0, protoBytes.Length); } }
private static Serializer CreateSerializer(RuntimeTypeModel model) { var recordMetadata = model.Add(typeof(OperationCommittedRecord), true); recordMetadata.AddSubType(10, typeof(OperationCommittedRecord <TOperation>)); model.Add(typeof(EpochSurrogate), true); model.Add(typeof(Epoch), true).SetSurrogate(typeof(EpochSurrogate)); Debug.WriteLine( model.GetSchema(typeof(OperationCommittedRecord <TOperation>))); return(new Serializer(model)); }
static RuntimeTypeModel GetProtobufModel() { if (_pbModel == null) { _pbModel = TypeModel.Create(); _pbModel.AllowParseableTypes = true; _pbModel.Add(typeof(Font), false).SetSurrogate(typeof(ProtoFont)); _pbModel.Add(typeof(Color), false).SetSurrogate(typeof(ProtoColor)); _pbModel.Add(typeof(StringFormat), false).SetSurrogate(typeof(ProtoStringFormat)); _pbModel.Add(typeof(Point <float>), true).Add("X", "Y"); _pbModel.Add(typeof(DrawStyle), true).AddSubType(100, typeof(DiagramDrawStyle)); _pbModel[typeof(BoundingBox <float>)].Add("X1", "X2", "Y1", "Y2"); _pbModel[typeof(BoundingBox <float>)].UseConstructor = false; Debug.WriteLine(_pbModel.GetSchema(typeof(DiagramDocumentCore))); } return(_pbModel); }
private void WriteProto(Assembly assembly, TextWriter output) { var dynamicModuleBuilder = CreateModuleBuilder("RequestResponseTypes", "RequestResponseTypes.dll", false); StringBuilder serviceBuilder = new StringBuilder(); RuntimeTypeModel typeModel = RuntimeTypeModel.Create(); foreach (var exportedType in assembly.GetExportedTypes()) { var serviceInfo = RpcBuilderUtil.TryGetServiceInfoFromType(exportedType); if (serviceInfo != null && serviceInfo.DefinitionSide != RpcServiceDefinitionSide.Client) { serviceBuilder.AppendLine(); serviceBuilder.AppendLine($"service {serviceInfo.Name} {{"); foreach (var rpcMemberInfo in RpcBuilderUtil.EnumOperationHandlers(serviceInfo, true)) { if (rpcMemberInfo is RpcOperationInfo rpcOpInfo) { var namedRequestType = this.CreateRequestType(dynamicModuleBuilder, rpcOpInfo); var namedResponseType = this.CreateResponseType(dynamicModuleBuilder, rpcOpInfo); if (namedRequestType == null || namedResponseType == null) { continue; // Should probably stop generator. } typeModel.Add(namedRequestType, true); typeModel.Add(namedResponseType, true); serviceBuilder.AppendLine( $"\trpc {rpcOpInfo.Name} ({namedRequestType.Name}) returns ({namedResponseType.Name});"); } } serviceBuilder.AppendLine("}"); } } string schema = typeModel.GetSchema(null, ProtoSyntax.Proto3); output.WriteLine(schema); output.WriteLine(serviceBuilder.ToString()); }
public void TestNullValues() { RuntimeTypeModel tm = TypeModel.Create(); tm.SkipCompiledVsNotCheck = true; string proto = tm.GetSchema(typeof(NullValues)); Assert.AreEqual(@"package Examples.DesignIdeas; message NullValues { optional blah Foo = 1 [default = Default]; optional bool Bar = 2; } enum blah { Default = 2; FOO = 3; ChangeValue = 19; LeaveAlone = 22; BAR = 92; } ", proto); }
public string GetProtoManifest() { return(_model.GetSchema(null)); }
public void SchemaValidation() { var result = model.GetSchema(typeof(FlagTestEnumInt32)); result.Should().BeEquivalentTo(SchemaString); }