mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-25 15:59:50 +00:00
feat[rust]: cut down rust protocol for HashMap
This commit is contained in:
@@ -56,6 +56,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeIntIntMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeIntIntMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -80,6 +83,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeIntLongMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeIntLongMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -104,6 +110,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeIntStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeIntStringMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeIntStringMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -147,8 +156,7 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Java:
|
||||
builder.append(StringUtils.format("buffer.writeIntPacketMap({}, (short) {});", objectStr, protocolId)).append(LS);
|
||||
return true;
|
||||
case Golang:
|
||||
case Protobuf:
|
||||
case Rust, Golang, Protobuf:
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -158,6 +166,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeLongIntMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeLongIntMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -182,6 +193,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeLongLongMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeLongLongMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -206,6 +220,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeLongStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeLongStringMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeLongStringMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -249,8 +266,7 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Java:
|
||||
builder.append(StringUtils.format("buffer.writeLongPacketMap({}, (short) {});", objectStr, protocolId)).append(LS);
|
||||
return true;
|
||||
case Golang:
|
||||
case Protobuf:
|
||||
case Rust, Golang, Protobuf:
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -260,6 +276,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeStringIntMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeStringIntMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -284,6 +303,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeStringLongMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeStringLongMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -308,6 +330,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("{}.writeStringStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return true;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("buffer.writeStringStringMap(&{});", objectStr)).append(LS);
|
||||
return true;
|
||||
case Kotlin, Scala, GdScript, Python:
|
||||
builder.append(StringUtils.format("buffer.writeStringStringMap({})", objectStr)).append(LS);
|
||||
return true;
|
||||
@@ -351,7 +376,7 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Java:
|
||||
builder.append(StringUtils.format("buffer.writeStringPacketMap({}, (short) {});", objectStr, protocolId)).append(LS);
|
||||
return true;
|
||||
case Golang, Protobuf:
|
||||
case Rust, Golang, Protobuf:
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -377,6 +402,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readIntIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntIntMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -417,6 +445,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readIntLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntLongMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -457,6 +488,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readIntStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readIntStringMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -530,8 +564,7 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case JavaScript, EcmaScript, TypeScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readIntPacketMap({});", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case Golang:
|
||||
case Protobuf:
|
||||
case Rust, Golang, Protobuf:
|
||||
}
|
||||
}
|
||||
} else if (keySerializer == LongSerializer.INSTANCE) {
|
||||
@@ -540,6 +573,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readLongIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongIntMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -580,6 +616,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readLongLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongLongMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -620,6 +659,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readLongStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readLongStringMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -693,8 +735,7 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case JavaScript, EcmaScript, TypeScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readLongPacketMap({});", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case Golang:
|
||||
case Protobuf:
|
||||
case Rust, Golang, Protobuf:
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -704,6 +745,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readStringIntMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringIntMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -744,6 +788,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readStringLongMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringLongMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -784,6 +831,9 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case Enhance:
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
case Rust:
|
||||
builder.append(StringUtils.format("let {} = buffer.readStringStringMap();", map)).append(LS);
|
||||
return map;
|
||||
case GdScript:
|
||||
builder.append(StringUtils.format("var {} = buffer.readStringStringMap()", map)).append(LS);
|
||||
return map;
|
||||
@@ -857,7 +907,7 @@ public class CutDownMapSerializer implements ICutDownSerializer {
|
||||
case JavaScript, EcmaScript, TypeScript:
|
||||
builder.append(StringUtils.format("const {} = buffer.readStringPacketMap({});", map, protocolId)).append(LS);
|
||||
return map;
|
||||
case Golang, Protobuf:
|
||||
case Rust, Golang, Protobuf:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -759,4 +759,229 @@ impl IByteBuffer for ByteBuffer {
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
fn writeIntIntMap(&mut self, map: &HashMap<i32, i32>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeInt(key);
|
||||
self.writeInt(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readIntIntMap(&mut self) -> HashMap<i32, i32> {
|
||||
let mut map: HashMap<i32, i32> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readInt();
|
||||
let value = self.readInt();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
fn writeIntLongMap(&mut self, map: &HashMap<i32, i64>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeInt(key);
|
||||
self.writeLong(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readIntLongMap(&mut self) -> HashMap<i32, i64> {
|
||||
let mut map: HashMap<i32, i64> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readInt();
|
||||
let value = self.readLong();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
fn writeIntStringMap(&mut self, map: &HashMap<i32, String>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeInt(key);
|
||||
self.writeString(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readIntStringMap(&mut self) -> HashMap<i32, String> {
|
||||
let mut map: HashMap<i32, String> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readInt();
|
||||
let value = self.readString();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
fn writeLongIntMap(&mut self, map: &HashMap<i64, i32>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeLong(key);
|
||||
self.writeInt(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readLongIntMap(&mut self) -> HashMap<i64, i32> {
|
||||
let mut map: HashMap<i64, i32> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readLong();
|
||||
let value = self.readInt();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
fn writeLongLongMap(&mut self, map: &HashMap<i64, i64>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeLong(key);
|
||||
self.writeLong(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readLongLongMap(&mut self) -> HashMap<i64, i64> {
|
||||
let mut map: HashMap<i64, i64> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readLong();
|
||||
let value = self.readLong();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
fn writeLongStringMap(&mut self, map: &HashMap<i64, String>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeLong(key);
|
||||
self.writeString(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readLongStringMap(&mut self) -> HashMap<i64, String> {
|
||||
let mut map: HashMap<i64, String> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readLong();
|
||||
let value = self.readString();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
fn writeStringIntMap(&mut self, map: &HashMap<String, i32>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeString(key);
|
||||
self.writeInt(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readStringIntMap(&mut self) -> HashMap<String, i32> {
|
||||
let mut map: HashMap<String, i32> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readString();
|
||||
let value = self.readInt();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
fn writeStringLongMap(&mut self, map: &HashMap<String, i64>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeString(key);
|
||||
self.writeLong(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readStringLongMap(&mut self) -> HashMap<String, i64> {
|
||||
let mut map: HashMap<String, i64> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readString();
|
||||
let value = self.readLong();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
fn writeStringStringMap(&mut self, map: &HashMap<String, String>) {
|
||||
if map.is_empty() {
|
||||
self.writeInt(0);
|
||||
} else {
|
||||
self.writeInt(map.len() as i32);
|
||||
for (key, value) in map.clone() {
|
||||
self.writeString(key);
|
||||
self.writeString(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn readStringStringMap(&mut self) -> HashMap<String, String> {
|
||||
let mut map: HashMap<String, String> = HashMap::new();
|
||||
let length = self.readInt();
|
||||
if length > 0 {
|
||||
for _index in 0..length {
|
||||
let key = self.readString();
|
||||
let value = self.readString();
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -82,4 +82,22 @@ pub trait IByteBuffer {
|
||||
fn readLongSet(&mut self) -> HashSet<i64>;
|
||||
fn writeStringSet(&mut self, set: &HashSet<String>);
|
||||
fn readStringSet(&mut self) -> HashSet<String>;
|
||||
fn writeIntIntMap(&mut self, map: &HashMap<i32, i32>);
|
||||
fn readIntIntMap(&mut self) -> HashMap<i32, i32>;
|
||||
fn writeIntLongMap(&mut self, map: &HashMap<i32, i64>);
|
||||
fn readIntLongMap(&mut self) -> HashMap<i32, i64>;
|
||||
fn writeIntStringMap(&mut self, map: &HashMap<i32, String>);
|
||||
fn readIntStringMap(&mut self) -> HashMap<i32, String>;
|
||||
fn writeLongIntMap(&mut self, map: &HashMap<i64, i32>);
|
||||
fn readLongIntMap(&mut self) -> HashMap<i64, i32>;
|
||||
fn writeLongLongMap(&mut self, map: &HashMap<i64, i64>);
|
||||
fn readLongLongMap(&mut self) -> HashMap<i64, i64>;
|
||||
fn writeLongStringMap(&mut self, map: &HashMap<i64, String>);
|
||||
fn readLongStringMap(&mut self) -> HashMap<i64, String>;
|
||||
fn writeStringIntMap(&mut self, map: &HashMap<String, i32>);
|
||||
fn readStringIntMap(&mut self) -> HashMap<String, i32>;
|
||||
fn writeStringLongMap(&mut self, map: &HashMap<String, i64>);
|
||||
fn readStringLongMap(&mut self) -> HashMap<String, i64>;
|
||||
fn writeStringStringMap(&mut self, map: &HashMap<String, String>);
|
||||
fn readStringStringMap(&mut self) -> HashMap<String, String>;
|
||||
}
|
||||
Reference in New Issue
Block a user