Commit 589e1624 authored by Mohamad Bashar Desoki's avatar Mohamad Bashar Desoki

examine protobuf msg

parent 531f6fbe
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21 (5)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
......
package org.ds; package org.ds;
import com.google.protobuf.InvalidProtocolBufferException;
import org.ds.proto.Student;
import org.ds.proto.Students;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) throws InvalidProtocolBufferException {
System.out.println("Hello world!"); byte[] msg = sender();
receiver(msg);
}
private static void receiver(byte[] msg) throws InvalidProtocolBufferException {
System.out.println("Received Data:");
for (int i = 0; i < msg.length; i++) {
System.out.print(msg[i] + " ");
}
System.out.println();
System.out.println(msg.length);
var students = Students.parseFrom(msg);
System.out.println(students.getStudentsList());
}
private static byte[] sender() {
Student student1 = Student.newBuilder().setName("Mohamad").setAge(40).build(); //builder pattern
Student student2 = Student.newBuilder().setName("Ahmad").setAge(40).build(); //builder pattern
Students students = Students.newBuilder().addStudents(student1).addStudents(student2).build();
byte[] arrayToSend = students.toByteArray();
for (int i = 0; i < arrayToSend.length; i++) {
System.out.print(arrayToSend[i] + " ");
}
System.out.println();
System.out.println(arrayToSend.length);
return arrayToSend;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment