Hi,
I have a requirement : 1. I have converted Example.proto file to Example.cs file code using the protoc.exe command. 2. I want to read Example.cs file using FileStream and create the Example object or atleast the TypeOf<Example Object>. I do not want to include it in my project as I want to make it generic. Could you please let me know how to achieve this. Thanks & Regards Raghu -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: Example.proto
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace ConsoleApplication1 {
/// <summary>Holder for reflection information generated from Example.proto</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public static partial class ExampleReflection {
#region Descriptor
/// <summary>File descriptor for Example.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static ExampleReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"Cg1FeGFtcGxlLnByb3RvEhNDb25zb2xlQXBwbGljYXRpb24xGhlnb29nbGUv",
"cHJvdG9idWYvYW55LnByb3RvIo0CCgZQZXJzb24SDAoEbmFtZRgBIAEoCRIK",
"CgJpZBgCIAEoBRINCgVlbWFpbBgDIAEoCRI2CgVwaG9uZRgEIAMoCzInLkNv",
"bnNvbGVBcHBsaWNhdGlvbjEuUGVyc29uLlBob25lTnVtYmVyEiEKA0FueRgF",
"IAEoCzIULmdvb2dsZS5wcm90b2J1Zi5BbnkaUgoLUGhvbmVOdW1iZXISDgoG",
"bnVtYmVyGAEgASgJEjMKBHR5cGUYAiABKA4yJS5Db25zb2xlQXBwbGljYXRp",
"b24xLlBlcnNvbi5QaG9uZVR5cGUiKwoJUGhvbmVUeXBlEgoKBk1PQklMRRAA",
"EggKBEhPTUUQARIICgRXT1JLEAJCFqoCE0NvbnNvbGVBcHBsaWNhdGlvbjFi",
"BnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.AnyReflection.Descriptor, },
new pbr::GeneratedCodeInfo(null, new pbr::GeneratedCodeInfo[] {
new pbr::GeneratedCodeInfo(typeof(global::ConsoleApplication1.Person), global::ConsoleApplication1.Person.Parser, new[]{ "Name", "Id", "Email", "Phone", "Any" }, null, new[]{ typeof(global::ConsoleApplication1.Person.Types.PhoneType) }, new pbr::GeneratedCodeInfo[] { new pbr::GeneratedCodeInfo(typeof(global::ConsoleApplication1.Person.Types.PhoneNumber), global::ConsoleApplication1.Person.Types.PhoneNumber.Parser, new[]{ "Number", "Type" }, null, null, null)})
}));
}
#endregion
}
#region Messages
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public sealed partial class Person : pb::IMessage<Person> {
private static readonly pb::MessageParser<Person> _parser = new pb::MessageParser<Person>(() => new Person());
public static pb::MessageParser<Person> Parser { get { return _parser; } }
public static pbr::MessageDescriptor Descriptor {
get { return global::ConsoleApplication1.ExampleReflection.Descriptor.MessageTypes[0]; }
}
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
public Person() {
OnConstruction();
}
partial void OnConstruction();
public Person(Person other) : this() {
name_ = other.name_;
id_ = other.id_;
email_ = other.email_;
phone_ = other.phone_.Clone();
Any = other.any_ != null ? other.Any.Clone() : null;
}
public Person Clone() {
return new Person(this);
}
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
private string name_ = "";
public string Name {
get { return name_; }
set {
name_ = pb::Preconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "id" field.</summary>
public const int IdFieldNumber = 2;
private int id_;
public int Id {
get { return id_; }
set {
id_ = value;
}
}
/// <summary>Field number for the "email" field.</summary>
public const int EmailFieldNumber = 3;
private string email_ = "";
public string Email {
get { return email_; }
set {
email_ = pb::Preconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "phone" field.</summary>
public const int PhoneFieldNumber = 4;
private static readonly pb::FieldCodec<global::ConsoleApplication1.Person.Types.PhoneNumber> _repeated_phone_codec
= pb::FieldCodec.ForMessage(34, global::ConsoleApplication1.Person.Types.PhoneNumber.Parser);
private readonly pbc::RepeatedField<global::ConsoleApplication1.Person.Types.PhoneNumber> phone_ = new pbc::RepeatedField<global::ConsoleApplication1.Person.Types.PhoneNumber>();
public pbc::RepeatedField<global::ConsoleApplication1.Person.Types.PhoneNumber> Phone {
get { return phone_; }
}
/// <summary>Field number for the "Any" field.</summary>
public const int AnyFieldNumber = 5;
private global::Google.Protobuf.WellKnownTypes.Any any_;
public global::Google.Protobuf.WellKnownTypes.Any Any {
get { return any_; }
set {
any_ = value;
}
}
public override bool Equals(object other) {
return Equals(other as Person);
}
public bool Equals(Person other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Name != other.Name) return false;
if (Id != other.Id) return false;
if (Email != other.Email) return false;
if(!phone_.Equals(other.phone_)) return false;
if (!object.Equals(Any, other.Any)) return false;
return true;
}
public override int GetHashCode() {
int hash = 1;
if (Name.Length != 0) hash ^= Name.GetHashCode();
if (Id != 0) hash ^= Id.GetHashCode();
if (Email.Length != 0) hash ^= Email.GetHashCode();
hash ^= phone_.GetHashCode();
if (any_ != null) hash ^= Any.GetHashCode();
return hash;
}
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
public void WriteTo(pb::CodedOutputStream output) {
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
}
if (Id != 0) {
output.WriteRawTag(16);
output.WriteInt32(Id);
}
if (Email.Length != 0) {
output.WriteRawTag(26);
output.WriteString(Email);
}
phone_.WriteTo(output, _repeated_phone_codec);
if (any_ != null) {
output.WriteRawTag(42);
output.WriteMessage(Any);
}
}
public int CalculateSize() {
int size = 0;
if (Name.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
if (Id != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Id);
}
if (Email.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Email);
}
size += phone_.CalculateSize(_repeated_phone_codec);
if (any_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Any);
}
return size;
}
public void MergeFrom(Person other) {
if (other == null) {
return;
}
if (other.Name.Length != 0) {
Name = other.Name;
}
if (other.Id != 0) {
Id = other.Id;
}
if (other.Email.Length != 0) {
Email = other.Email;
}
phone_.Add(other.phone_);
if (other.any_ != null) {
if (any_ == null) {
any_ = new global::Google.Protobuf.WellKnownTypes.Any();
}
Any.MergeFrom(other.Any);
}
}
public void MergeFrom(pb::CodedInputStream input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
input.SkipLastField();
break;
case 10: {
Name = input.ReadString();
break;
}
case 16: {
Id = input.ReadInt32();
break;
}
case 26: {
Email = input.ReadString();
break;
}
case 34: {
phone_.AddEntriesFrom(input, _repeated_phone_codec);
break;
}
case 42: {
if (any_ == null) {
any_ = new global::Google.Protobuf.WellKnownTypes.Any();
}
input.ReadMessage(any_);
break;
}
}
}
}
#region Nested types
/// <summary>Container for nested types declared in the Person message type.</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public static partial class Types {
public enum PhoneType {
MOBILE = 0,
HOME = 1,
WORK = 2,
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
private static readonly pb::MessageParser<PhoneNumber> _parser = new pb::MessageParser<PhoneNumber>(() => new PhoneNumber());
public static pb::MessageParser<PhoneNumber> Parser { get { return _parser; } }
public static pbr::MessageDescriptor Descriptor {
get { return global::ConsoleApplication1.Person.Descriptor.NestedTypes[0]; }
}
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
public PhoneNumber() {
OnConstruction();
}
partial void OnConstruction();
public PhoneNumber(PhoneNumber other) : this() {
number_ = other.number_;
type_ = other.type_;
}
public PhoneNumber Clone() {
return new PhoneNumber(this);
}
/// <summary>Field number for the "number" field.</summary>
public const int NumberFieldNumber = 1;
private string number_ = "";
public string Number {
get { return number_; }
set {
number_ = pb::Preconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "type" field.</summary>
public const int TypeFieldNumber = 2;
private global::ConsoleApplication1.Person.Types.PhoneType type_ = global::ConsoleApplication1.Person.Types.PhoneType.MOBILE;
public global::ConsoleApplication1.Person.Types.PhoneType Type {
get { return type_; }
set {
type_ = value;
}
}
public override bool Equals(object other) {
return Equals(other as PhoneNumber);
}
public bool Equals(PhoneNumber other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Number != other.Number) return false;
if (Type != other.Type) return false;
return true;
}
public override int GetHashCode() {
int hash = 1;
if (Number.Length != 0) hash ^= Number.GetHashCode();
if (Type != global::ConsoleApplication1.Person.Types.PhoneType.MOBILE) hash ^= Type.GetHashCode();
return hash;
}
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
public void WriteTo(pb::CodedOutputStream output) {
if (Number.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Number);
}
if (Type != global::ConsoleApplication1.Person.Types.PhoneType.MOBILE) {
output.WriteRawTag(16);
output.WriteEnum((int) Type);
}
}
public int CalculateSize() {
int size = 0;
if (Number.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Number);
}
if (Type != global::ConsoleApplication1.Person.Types.PhoneType.MOBILE) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type);
}
return size;
}
public void MergeFrom(PhoneNumber other) {
if (other == null) {
return;
}
if (other.Number.Length != 0) {
Number = other.Number;
}
if (other.Type != global::ConsoleApplication1.Person.Types.PhoneType.MOBILE) {
Type = other.Type;
}
}
public void MergeFrom(pb::CodedInputStream input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
input.SkipLastField();
break;
case 10: {
Number = input.ReadString();
break;
}
case 16: {
type_ = (global::ConsoleApplication1.Person.Types.PhoneType) input.ReadEnum();
break;
}
}
}
}
}
}
#endregion
}
#endregion
}
#endregion Designer generated code
Example.proto
Description: Binary data
