Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

java - Protocol Buffer: Parsing and Compiling a .proto file at runtime

I am trying to serialize an object into a byte array using protocol buffers at runtime. To achieve this I need to parse a string containing the .proto file content(created by mapping java class to proto) and compile it using protoc to generate a message and serialize it.

Is this approach doable? and if so are there any references that I can follow to implement this?

My main requirement is to serialize an object into a byte array using protocol buffers without generating a .proto file. The main method would look something like this.

    Student s1 = new Student('name', 'id');

    proto pr = protoFromClass(Student);
    byte[] serializedPr = pr.serialize(s1);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...