Posted Java3y
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了相关的知识,希望对你有一定的参考价值。
鏈枃鍏紬鍙锋潵婧愶細JavaKeeper 浣滆€咃細Java澶х尶甯?/span>
馃懆鈥嶐煉?灞€闀垮璇伙細鈥?/span>Google Protocol Buffer( 绠€绉?Protobuf) 鏄?Google 鍏徃鍐呴儴鐨勬贩鍚堣瑷€鏁版嵁鏍囧噯 ,鏄竴绉嶈交渚块珮鏁堢殑缁撴瀯鍖栨暟鎹瓨鍌ㄦ牸寮忥紝鍙互鐢ㄤ簬缁撴瀯鍖栨暟鎹覆琛屽寲锛屾垨鑰呰搴忓垪鍖?灏?鏁版嵁缁撴瀯鎴栧璞?杞崲鎴?浜岃繘鍒朵覆 鐨勮繃绋?)銆傚畠寰堥€傚悎鍋?span>鏁版嵁瀛樺偍鎴?RPC 鏁版嵁浜ゆ崲鏍煎紡銆傚彲鐢ㄤ簬閫氳鍗忚銆佹暟鎹瓨鍌ㄧ瓑棰嗗煙鐨勮瑷€鏃犲叧銆佸钩鍙版棤鍏炽€佸彲鎵╁睍鐨勫簭鍒楀寲缁撴瀯鏁版嵁鏍煎紡
鈥?/span>
protocol buffers 璇炵敓涔嬪垵鏄负浜嗚В鍐虫湇鍔″櫒绔柊鏃у崗璁?楂樹綆鐗堟湰)鍏煎鎬ч棶棰橈紝鍚嶅瓧涔熷緢浣撹创锛屸€滃崗璁紦鍐插尯鈥濄€傚彧涓嶈繃鍚庢湡鎱㈡參鍙戝睍鎴愮敤浜庝紶杈撴暟鎹€?/em>
绗旇€呮墍鍦ㄧ殑360骞垮憡鎶曟斁锛?浜挎潯鍟嗗搧淇℃伅鐨勬暟鎹叏閮ㄩ噰鐢≒B鏍煎紡瀛樺偍銆佷紶杈撱€?/p>
Protobuf 鐨勪紭鐐?/span>
-
鏇村皬鈥斺€斿簭鍒楀寲鍚庯紝鏁版嵁澶у皬鍙缉灏忕害3鍊?/p>
-
鏇村揩鈥斺€斿簭鍒楀寲閫熷害鏇村揩锛屾瘮xml鍜孞SON蹇?0-100鍊嶏紝浣撶Н缂╁皬鍚庯紝浼犺緭鏃讹紝甯﹀涔熶細浼樺寲
-
鏇寸畝鍗曗€斺€攑roto缂栬瘧鍣紝鑷姩杩涜搴忓垪鍖栧拰鍙嶅簭鍒楀寲
-
缁存姢鎴愭湰浣庘€斺€旇法骞冲彴銆佽法璇█锛屽骞冲彴浠呴渶瑕佺淮鎶や竴濂楀璞″崗璁紙.proto锛?/p>
-
鍙墿灞曗€斺€斺€滃悜鍚庘€濆吋瀹规€уソ锛屼笉蹇呯牬鍧忓凡閮ㄧ讲鐨勩€佷緷闈犫€滆€佲€濇暟鎹牸寮忕殑绋嬪簭灏卞彲浠ュ鏁版嵁缁撴瀯杩涜鍗囩骇
-
鍔犲瘑鎬уソ鈥斺€擧TTP浼犺緭鍐呭鎶撳寘鍙兘鐪嬪埌瀛楄妭
鍦ㄤ紶杈撴暟鎹噺澶с€佺綉缁滅幆澧冧笉绋冲畾鐨勬暟鎹瓨鍌ㄥ拰RPC鏁版嵁浜ゆ崲鍦烘櫙姣旇緝鍚堥€?/p>
Protobuf 鐨勪笉瓒?/span>
-
鍔熻兘绠€鍗曪紝鏃犳硶鐢ㄦ潵琛ㄧず澶嶆潅鐨勬蹇? -
閫氱敤鎬ц緝宸紝XML鍜孞SON宸叉垚涓哄绉嶈涓氭爣鍑嗙殑缂栧啓宸ュ叿锛宲b鍙槸geogle鍐呴儴浣跨敤 -
鑷В閲婃€у樊锛屼互浜岃繘鍒舵暟鎹祦鏂瑰紡瀛樺偍锛堜笉鍙锛夛紝闇€瑕侀€氳繃.proto鏂囦欢鎵嶅彲浠?
瀹樼綉 Protocol Buffer Basics: Java https://developers.google.com/protocol-buffers/docs/javatutorial
Hello World
1. 瀹氫箟 .proto
鏂囦欢鐨勬秷鎭牸寮忥紙浣犲笇鏈涘瓨鍌ㄧ殑鏁版嵁鏍煎紡鎻忚堪鏂囦欢锛?/h5>
syntax = "proto2";
package tutorial;
option java_package = "com.example.tutorial";
option java_outer_classname = "AddressBookProtos";
//娑堟伅妯″瀷
message Person {
//娑堟伅瀵硅薄鐨勫瓧娈碉細瀛楁淇グ绗?瀛楁绫诲瀷+瀛楁鍚嶇О+鏍囪瘑鍙凤紙閫氳繃浜岃繘鍒舵牸寮忓敮涓€鏍囪瘑姣忎釜瀛楁锛屼笉鍙樺彲锛?br> required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phones = 4;
}
message AddressBook {
repeated Person people = 1;
}
syntax = "proto2";
package tutorial;
option java_package = "com.example.tutorial";
option java_outer_classname = "AddressBookProtos";
//娑堟伅妯″瀷
message Person {
//娑堟伅瀵硅薄鐨勫瓧娈碉細瀛楁淇グ绗?瀛楁绫诲瀷+瀛楁鍚嶇О+鏍囪瘑鍙凤紙閫氳繃浜岃繘鍒舵牸寮忓敮涓€鏍囪瘑姣忎釜瀛楁锛屼笉鍙樺彲锛?br> required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phones = 4;
}
message AddressBook {
repeated Person people = 1;
}
鈽嗏槅鈽嗘敞锛?/p>
-
syntax = "proto2"锛氭寚鏄庣増鏈? -
package锛歅B鐨勮嚜宸辩殑鍖呭悕锛岄槻姝笉鍚?nbsp; .proto
椤圭洰闂村懡鍚?鍙戠敓鍐茬獊 -
java_package锛氱敓鎴恓ava绫荤殑鍖呭悕,濡備笉鏄惧紡鎸囧畾锛岄粯璁ゅ寘鍚嶄负锛氭寜鐓у簲鐢ㄥ悕绉板€掑簭鏂瑰紡杩涜鎺掑簭 -
java_outer_classname锛氱敓鎴?java绫荤殑绫诲悕,濡備笉鏄惧紡鎸囧畾锛屽垯榛樿涓烘妸.proto鏂囦欢鍚嶈浆鎹负棣栧瓧姣嶅ぇ鍐欐潵鐢熸垚 -
message: 浣犵殑娑堟伅鏍煎紡锛屽悇鏁版嵁绫诲瀷锛? bool
,int32
,float
,double
,string
锛?enum
... 锛夊瓧娈电殑闆嗗悎锛屽湪涓€涓?proto鏂囦欢涓彲浠ュ畾涔夊涓猰essage锛屼竴涓猰essage閲屼篃鍙互瀹氫箟鍙﹀涓€涓猰essage(鐩稿綋浜巎ava鐨勭被锛屽綋鐒朵篃鍙互鏈夊唴閮ㄧ被) -
褰撶劧PB涔熸槸鏀寔鍜宩ava涓€鏍风殑 import
鐨勶紝import "xxx.proto";
-
鍍忔瘡涓瓧娈典篃蹇呴』鏈変慨楗扮锛孭B鎻愪緵鐨勫瓧娈典慨楗扮鏈?绉? -
required锛氬繀濉? -
optional锛氬彲閫? -
repeated 锛氬彲閲嶅瀛楁锛屽彲鏀鹃泦鍚? -
鏍囪瘑鍙凤細閫氳繃浜岃繘鍒舵牸寮忓敮涓€鏍囪瘑姣忎釜瀛楁 锛屼娇鐢ㄥ悗灏变笉鑳藉鍐嶆敼鍙? -
鑼冨洿 [1,15] 鏍囪瘑鍙风殑瀛楁 鍦ㄧ紪鐮佹椂鍗犵敤1涓瓧鑺傦紱 -
鑼冨洿 [16,2047] 鏍囪瘑鍙风殑瀛楁 鍦ㄧ紪鐮佹椂鍗犵敤2涓瓧鑺? -
涓洪绻佸嚭鐜扮殑 娑堟伅瀛楁 淇濈暀 [1,15] 鐨勬爣璇嗗彿 -
鏍囪瘑鍙蜂娇鐢ㄨ寖鍥达細[1,2鐨?9娆℃柟 - 1] -
涓嶅彲浣跨敤 [19000锛?9999] 鏍囪瘑鍙凤紝 鍥犱负 Protobuf
鍗忚瀹炵幇涓杩欎簺鏍囪瘑鍙疯繘琛屼簡棰勭暀銆傚亣鑻ヤ娇鐢紝鍒欎細鎶ラ敊 -
姣忎釜瀛楁鍦ㄨ繘琛岀紪鐮佹椂閮戒細鍗犵敤鍐呭瓨锛岃€?鍗犵敤鍐呭瓨澶у皬 鍙栧喅浜?鏍囪瘑鍙凤細
鍚勭被鐭ヨ瘑鐐规€荤粨
涓嬮潰鐨勬枃绔犻兘鏈夊搴旂殑鍘熷垱绮剧編PDF锛屽湪鎸佺画鏇存柊涓紝鍙互鏉ユ壘鎴戝偓鏇磣
-
-
-
-
-
-
-
-
-
-
-
-
Hibernate -
AJAX -
Redis -
......
鍘熷垱鐢靛瓙涔?/span>
鍘熷垱鎬濈淮瀵煎浘
以上是关于的主要内容,如果未能解决你的问题,请参考以下文章