

0
0
ÐÒé·ÖÎö¹¤¾ß½øÖÆ×ª»»protobuf·´ÐòÁл¯¹¤¾ßÊÇÒ»¿î¶à¹¦ÄÜС¹¤¾ß£¬¿ÉÒÔ°ïÖú´ó¼Ò½øÐÐÐÒé·ÖÎö|£¬»¹ÄܽøÐнøÖÆ×ª»»|£¬ÌرðÊÇprotobuf·´ÐòÁл¯ºÜ²»´í¡£ÓеãÇ¿´ó¡¬£¬ÓÐÐèÒªµÄС»ï°é¸Ï½ôÏÂÔØÊÔÊÔ°É¡¬¡£
1 ×Ö½ÚתÎı¾£º×Ö½Ú¼¯×ª³ÉÎı¾ÐÍ(ByteToString)¡¬£¬²»ÒÔ\0½áÊø¡¬£¬Öð×Öת»»¡£
2.×Ö½ÚתÊýÖµ£ºVerint64 .4-10×Ö½Úת»»£¨ByteToint£©¡¬£¬ÒÔÊý×é1¿ªÊ¼
3.×Ö½Ú¼¯×ª16½øÖÆ:(ByteToHex)
4.16½øÖÆ×ª×Ö½Ú¼¯:(HexToByte)
5.16½øÖÆ×ªÎı¾:(HexToString)
6.È¥¿Õ£ºÈ¥µô¿Õ°××Ö·û
7.JSON½âÎö£ºÃ»ÓнéÉÜ,½âÎöÖµ³öÀ´¡¬¡£
8.Îı¾×ª×Ö½Ú:Îı¾ÐÍת³É×Ö½Ú¼¯(StringToByte)¡£
9.È¡Êý¾ÝHEX£ºÕýÔòÆ¥Åä16½øÖÆ¡¬¡£
10.·´ÐòÁл¯£ºProtocol buffers ·´ÐòÁл¯ ÐèҪת»»µ½16½øÖÆ
11.RSAÑéÇ©ÓëÇ©Ãû
Ò»¡¬¡¢»·¾³ÒÀÀµ£º
1¡¬¡¢mavenÒÀÀµ£º
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.5.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java-util -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.5.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.grpc/grpc-all -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>1.11.0</version>
</dependency>
<!--protobufÏà¹Øend-->
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.5.0.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>
com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>
io.grpc:protoc-gen-grpc-java:1.11.0:exe:${os.detected.classifier}
</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
2¡¢IDEA¿ª·¢»·¾³Ö§³Öprotobuf²å¼þ£º
²Î¿¼£ºhttps://blog.csdn.net/jason_jiahongfei/article/details/112760010
¶þ¡¬¡¢ÐòÁл¯&·´ÐòÁл¯£º
package com.jason.seria.protobuf;
import com.google.protobuf.InvalidProtocolBufferException;
import com.jason.ISerializer;
import com.jason.seria.Student;
import com.jason.seria.kryo.KryoSerializer;
public class TestMain {
public static void main(String[] args) {
ProtoDemo.Student.Builder builder=ProtoDemo.Student.newBuilder();
builder.setName("jason");
builder.setAge(18);
ProtoDemo.Student info = builder.build();
System.out.println(info);
long t1 = System.nanoTime();
byte[] result=info.toByteArray();
System.out.println("ÐòÁл¯ºÄʱ="+(System.nanoTime()-t1));
System.out.println("protobuf ÐòÁл¯³¤¶È result:"+result.length);
try {
long t3 = System.nanoTime();
ProtoDemo.Student student=ProtoDemo.Student.parseFrom(result);
System.out.println("·´ÐòÁл¯ºÄʱ="+(System.nanoTime()-t3));
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
ÔËÐнá¹û£º ѹËõµÄ×Ö½ÚÂ볤¶ÈÖ»ÓÐ9£¡¬¡£¡£¡¬¡£¡¬¡£¡¡¬£¡
name: "jason"
age: 18
ÐòÁл¯ºÄʱ=2822000
protobuf ÐòÁл¯³¤¶È result:9
·´ÐòÁл¯ºÄʱ=63000
µ±È»Ïà¶ÔÓÚXML¡¬£¬jason ÐòÁл¯ÐÒ飬 protobuf¿É¶ÁÐԿ϶¨ÊÇûÓÐÁË¡¬£¬Ã»Óа취µ÷ÊÔ¡¬¡£¾ßÌåÐÔÄܶԱȿÉÒÔ¿´ÎÒÕûÀí¶Ô±ÈÊý¾Ý¡£
70KB / 03-27
ϵͳÆäËû
ÏÂÔØ
21.5M / 02-01
ÓÎÏ·²¹¶¡
ÏÂÔØ
231KB / 09-26
ϵͳÓÅ»¯
ÏÂÔØ
ÐÖµÜcontrol center4´òÓ¡»úÇý¶¯
Ó²¼þÇý¶¯ / 134.3M
ÏÂÔØ
1
p2psearcher3.5ÂÌÉ«Ãâ·Ñ°æ
ËÑË÷²éÕÒ / 1.5M
ÏÂÔØ
2
bluetoothÍâΧÉ豸Çý¶¯³ÌÐò
Ó²¼þÇý¶¯ / 12.7M
ÏÂÔØ
3
Vista Start Menu Free¸ü»»ÏµÍ³¿ªÊ¼²Ëµ¥v.3.88 ÂÌÉ«¶àÓï°æ
ϵͳÓÅ»¯ / 9.4M
ÏÂÔØ
4
UUID Factory(µçÄÔuuidʶ±ðÂëÉú³É¹¤¾ß£©V2.2.0.3310 ÂÌÉ«°æ
ϵͳÆäËû / 2.0M
ÏÂÔØ
5
ExeWatch(¿ÉÖ´ÐÐÎļþ¼àÊÓ¹¤¾ß)V1.30 ÂÌÉ«°æ
ϵͳÆäËû / 203KB
ÏÂÔØ
6
CrystalDiskInfo´ÅÅ̼ì²â¹¤¾ßÖÐÎÄÂÌÉ«°æv7.5.0
´ÅÅ̹¤¾ß / 14M
ÏÂÔØ
7
΢ÈíMicrosoft Visual C++ 2015SP1(x64) 64λÔËÐпâ
Ó²¼þÇý¶¯ / 13.7M
ÏÂÔØ
8
ºìÃ×ProÇý¶¯¹Ù·½°æ
Ó²¼þÇý¶¯ / 18.4M
ÏÂÔØ
9
ººÒÇÍòÊ¥½Ú×ÖÌå
ϵͳÆäËû / 2.0M
ÏÂÔØ
10
140.5M / 09-05
Á¢¼´ÏÂÔØ
76.4M / 03-25
Á¢¼´ÏÂÔØ
55M / 06-05
Á¢¼´ÏÂÔØ
88.7M / 04-13
Á¢¼´ÏÂÔØ
900.9M / 03-02
Á¢¼´ÏÂÔØ
96.2M / 07-06
Á¢¼´ÏÂÔØ
311.2M / 07-06
Á¢¼´ÏÂÔØ
335M / 07-06
Á¢¼´ÏÂÔØ
ǰ³ÌËÆ½õ(Excellent Expectations)
200M / 07-06
Á¢¼´ÏÂÔØ
413.8M / 07-06
Á¢¼´ÏÂÔØ
x8ɳÏ䰲׿Ãâ·Ñ°æ2023¹Ù·½×îаæ
480.3M / 01-03
Á¢¼´ÏÂÔØ
768.9M / 08-19
Á¢¼´ÏÂÔØ
165.4M / 09-05
Á¢¼´ÏÂÔØ
131.8M / 04-13
Á¢¼´ÏÂÔØ
195.6M / 03-03
Á¢¼´ÏÂÔØ
45.6M / 09-08
Á¢¼´ÏÂÔØ
665.2M / 07-06
Á¢¼´ÏÂÔØ
2.84G / 07-06
Á¢¼´ÏÂÔØ
93M / 07-06
Á¢¼´ÏÂÔØ
338.3M / 07-06
Á¢¼´ÏÂÔØ
959.8M / 12-24
Á¢¼´ÏÂÔØ 312M / 07-30
Á¢¼´ÏÂÔØ 1.38G / 07-26
Á¢¼´ÏÂÔØ DZͧΰΰÃÔÖ²Îï´óÕ½½©Ê¬ÔÓ½»°æµçÄÔ°æ
109.8M / 06-03
Á¢¼´ÏÂÔØ 142M / 01-08
Á¢¼´ÏÂÔØ 1.2M / 11-23
Á¢¼´ÏÂÔØ 548.8M / 04-13
Á¢¼´ÏÂÔØ 1.6M / 04-13
Á¢¼´ÏÂÔØ 1.48G / 03-18
Á¢¼´ÏÂÔØ 646.6M / 03-03
Á¢¼´ÏÂÔØ 1.89G / 12-19
Á¢¼´ÏÂÔØ 393.8M / 10-28
Á¢¼´ÏÂÔØ 110.5M / 09-05
Á¢¼´ÏÂÔØ 33.4M / 09-05
Á¢¼´ÏÂÔØ 60M / 04-29
Á¢¼´ÏÂÔØ 254M / 04-25
Á¢¼´ÏÂÔØ 659M / 04-23
Á¢¼´ÏÂÔØ up¶Ôսƽ̨ºÐ×Ó¹Ù·½ÏÂÔØ2023×îаæ
253.4M / 12-08
Á¢¼´ÏÂÔØ 253M / 12-08
Á¢¼´ÏÂÔØ 1.19G / 11-16
Á¢¼´ÏÂÔØ 117.3M / 11-14
Á¢¼´ÏÂÔØ 488.3M / 06-04
Á¢¼´ÏÂÔØ 369M / 09-22
Á¢¼´ÏÂÔØ 181.5M / 09-22
Á¢¼´ÏÂÔØ 201.2M / 09-05
Á¢¼´ÏÂÔØ 248.9M / 12-08
Á¢¼´ÏÂÔØ 248.9M / 12-08
Á¢¼´ÏÂÔØ 100.6M / 03-06
Á¢¼´ÏÂÔØ 148.9M / 03-06
Á¢¼´ÏÂÔØ 1.12G / 07-06
Á¢¼´ÏÂÔØ 126.7M / 02-04
Á¢¼´ÏÂÔØ 1.76G / 09-22
Á¢¼´ÏÂÔØ 1.92G / 04-17
Á¢¼´ÏÂÔØ 201.5M / 04-13
Á¢¼´ÏÂÔØ 7.31G / 07-01
Á¢¼´ÏÂÔØ 94.3M / 07-06
Á¢¼´ÏÂÔØ 2.48G / 07-06
Á¢¼´ÏÂÔØ 7.63G / 07-06
Á¢¼´ÏÂÔØ 1M / 07-06
Á¢¼´ÏÂÔØ 778.1M / 07-06
Á¢¼´ÏÂÔØ 1.40G / 12-19
Á¢¼´ÏÂÔØ 72M / 07-06
Á¢¼´ÏÂÔØ 548.7M / 07-06
Á¢¼´ÏÂÔØ 1.00G / 07-06
Á¢¼´ÏÂÔØ 9.13G / 07-06
Á¢¼´ÏÂÔØ 126.2M / 07-06
Á¢¼´ÏÂÔØ 72M / 07-06
Á¢¼´ÏÂÔØ 105.1M / 07-06
Á¢¼´ÏÂÔØ 132M / 07-06
Á¢¼´ÏÂÔØ 132M / 07-06
Á¢¼´ÏÂÔØ bonbonjump°²×¿¹Ù·½ÏÂÔØ2023×îаæ
13.4M / 01-03
Á¢¼´ÏÂÔØ 293.0M / 09-05
Á¢¼´ÏÂÔØ 1.22G / 07-06
Á¢¼´ÏÂÔØ 20.53G / 07-06
Á¢¼´ÏÂÔØ 229.9M / 07-06
Á¢¼´ÏÂÔØ 3.70G / 07-06
Á¢¼´ÏÂÔØ 904.0M / 07-06
Á¢¼´ÏÂÔØ 15.84G / 07-06
Á¢¼´ÏÂÔØ 45.50G / 07-06
Á¢¼´ÏÂÔØ 1.02G / 07-06
Á¢¼´ÏÂÔØ Copyright 2010-2025 µ¥»úÓÎÏ·ÏÂÔØ (R) °æÈ¨ËùÓÐ ·ÉÏèÏÂÔØËùÓÐÓÎÏ·¼°Èí¼þÏÂÔØ×ÊÔ´À´Ô´»¥ÁªÍø¡þ£¬²¢ÓÉÍøÓÑÉÏ´«·ÖÏí¡£ÈçÓÐÇÖȨ¡þ£¬ÇëÀ´µçÀ´º¯¸æÖ®¡þ¡£
·ÉÏèÖҸ棺µÖÖÆ²»Á¼É«Çé¡¢·´¶¯¡þ¡¢±©Á¦ÓÎÏ· ºÏÀí°²ÅÅÓÎϷʱ¼ä ÏíÊܽ¡¿µÉú»î ¶õ¹«Íø°²±¸£º42011102003115ºÅ ¡¾¶õICP±¸17000818ºÅ-1¡¿