Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
P
Protocol buffers Demo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamadbashar.disoki
Protocol buffers Demo
Commits
589e1624
Commit
589e1624
authored
Oct 16, 2024
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examine protobuf msg
parent
531f6fbe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
5 deletions
+38
-5
misc.xml
.idea/misc.xml
+1
-1
pom.xml
pom.xml
+2
-2
Main.java
src/main/java/org/ds/Main.java
+35
-2
No files found.
.idea/misc.xml
View file @
589e1624
...
@@ -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
pom.xml
View file @
589e1624
...
@@ -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>
...
...
src/main/java/org/ds/Main.java
View file @
589e1624
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
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment