mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-13 02:14:52 +00:00
perf[protocol]: ByteBufUtils增加针对于Map的key为String类型的解析方法
This commit is contained in:
1 parent
d7fef2489b
commit
5b9cbd046d
5 files changed
+452
-64
No files matched your search
@@ -470,48 +470,6 @@ public abstract class ByteBufUtils {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeLongIntMap(ByteBuf byteBuf, Map<Long, Integer> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeLongBox(byteBuf, entry.getKey());
|
||||
writeIntBox(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Long, Integer> readLongIntMap(ByteBuf byteBuf) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<Long, Integer>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readLongBox(byteBuf), readIntBox(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeLongLongMap(ByteBuf byteBuf, Map<Long, Long> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeLongBox(byteBuf, entry.getKey());
|
||||
writeLongBox(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Long, Long> readLongLongMap(ByteBuf byteBuf) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<Long, Long>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readLongBox(byteBuf), readLongBox(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeIntStringMap(ByteBuf byteBuf, Map<Integer, String> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
@@ -554,6 +512,69 @@ public abstract class ByteBufUtils {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeLongIntMap(ByteBuf byteBuf, Map<Long, Integer> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeLongBox(byteBuf, entry.getKey());
|
||||
writeIntBox(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Long, Integer> readLongIntMap(ByteBuf byteBuf) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<Long, Integer>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readLongBox(byteBuf), readIntBox(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeLongLongMap(ByteBuf byteBuf, Map<Long, Long> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeLongBox(byteBuf, entry.getKey());
|
||||
writeLongBox(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Long, Long> readLongLongMap(ByteBuf byteBuf) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<Long, Long>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readLongBox(byteBuf), readLongBox(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeLongStringMap(ByteBuf byteBuf, Map<Long, String> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeLongBox(byteBuf, entry.getKey());
|
||||
writeString(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Long, String> readLongStringMap(ByteBuf byteBuf) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<Long, String>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readLongBox(byteBuf), readString(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeLongPacketMap(ByteBuf byteBuf, Map<Long, ? extends IPacket> map, IProtocolRegistration protocolRegistration) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
@@ -575,6 +596,89 @@ public abstract class ByteBufUtils {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeStringIntMap(ByteBuf byteBuf, Map<String, Integer> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeString(byteBuf, entry.getKey());
|
||||
writeIntBox(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Integer> readStringIntMap(ByteBuf byteBuf) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<String, Integer>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readString(byteBuf), readIntBox(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeStringLongMap(ByteBuf byteBuf, Map<String, Long> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeString(byteBuf, entry.getKey());
|
||||
writeLongBox(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Long> readStringLongMap(ByteBuf byteBuf) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<String, Long>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readString(byteBuf), readLongBox(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeStringStringMap(ByteBuf byteBuf, Map<String, String> map) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeString(byteBuf, entry.getKey());
|
||||
writeString(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, String> readStringStringMap(ByteBuf byteBuf) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<String, String>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readString(byteBuf), readString(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeStringPacketMap(ByteBuf byteBuf, Map<String, ? extends IPacket> map, IProtocolRegistration protocolRegistration) {
|
||||
if (map == null) {
|
||||
byteBuf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
writeInt(byteBuf, map.size());
|
||||
for (var entry : map.entrySet()) {
|
||||
writeString(byteBuf, entry.getKey());
|
||||
protocolRegistration.write(byteBuf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, IPacket> readStringPacketMap(ByteBuf byteBuf, IProtocolRegistration protocolRegistration) {
|
||||
var length = readInt(byteBuf);
|
||||
var map = (Map<String, IPacket>) CollectionUtils.newFixedMap(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
map.put(readString(byteBuf), (IPacket) protocolRegistration.read(byteBuf));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
//---------------------------------boolean--------------------------------------
|
||||
public static void writeBooleanArray(ByteBuf byteBuf, boolean[] array) {
|
||||
|
||||
+50
-22
@@ -39,37 +39,51 @@ public class EnhanceMapSerializer implements IEnhanceSerializer {
|
||||
var mapField = (MapField) fieldRegistration;
|
||||
var keyRegistration = mapField.getMapKeyRegistration();
|
||||
var valueRegistration = mapField.getMapValueRegistration();
|
||||
var keySerializer = keyRegistration.serializer();
|
||||
var valueSerializer = valueRegistration.serializer();
|
||||
|
||||
// 直接在字节码里调用方法是为了减小生成字节码的体积,下面的代码去掉也不会有任何影响
|
||||
if (keyRegistration instanceof BaseField) {
|
||||
if (valueRegistration instanceof BaseField) {
|
||||
var keyBaseRegistration = (BaseField) keyRegistration;
|
||||
var valueBaseRegistration = (BaseField) valueRegistration;
|
||||
if (keyBaseRegistration.serializer() == IntSerializer.getInstance() && valueBaseRegistration.serializer() == IntSerializer.getInstance()) {
|
||||
if (keySerializer == IntSerializer.getInstance() && valueSerializer == IntSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeIntIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
} else if (keyBaseRegistration.serializer() == IntSerializer.getInstance() && valueBaseRegistration.serializer() == LongSerializer.getInstance()) {
|
||||
} else if (keySerializer == IntSerializer.getInstance() && valueSerializer == LongSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeIntLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
} else if (keyBaseRegistration.serializer() == LongSerializer.getInstance() && valueBaseRegistration.serializer() == IntSerializer.getInstance()) {
|
||||
} else if (keySerializer == IntSerializer.getInstance() && valueSerializer == StringSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeIntStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
} else if (keySerializer == LongSerializer.getInstance() && valueSerializer == IntSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeLongIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
} else if (keyBaseRegistration.serializer() == LongSerializer.getInstance() && valueBaseRegistration.serializer() == LongSerializer.getInstance()) {
|
||||
} else if (keySerializer == LongSerializer.getInstance() && valueSerializer == LongSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeLongLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
} else if (keyBaseRegistration.serializer() == IntSerializer.getInstance() && valueBaseRegistration.serializer() == StringSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeIntStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
} else if (keySerializer == LongSerializer.getInstance() && valueSerializer == StringSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeLongStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
} else if (keySerializer == StringSerializer.getInstance() && valueSerializer == IntSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeStringIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
} else if (keySerializer == StringSerializer.getInstance() && valueSerializer == LongSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeStringLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
} else if (keySerializer == StringSerializer.getInstance() && valueSerializer == StringSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeStringStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr));
|
||||
return;
|
||||
}
|
||||
} else if (valueRegistration instanceof ObjectProtocolField) {
|
||||
var keyBaseRegistration = (BaseField) keyRegistration;
|
||||
var valueProtocolRegistration = (ObjectProtocolField) valueRegistration;
|
||||
if (keyBaseRegistration.serializer() == IntSerializer.getInstance() && valueProtocolRegistration.serializer() == ObjectProtocolSerializer.getInstance()) {
|
||||
if (keySerializer == IntSerializer.getInstance() && valueSerializer == ObjectProtocolSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeIntPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(valueProtocolRegistration.getProtocolId())));
|
||||
return;
|
||||
} else if (keyBaseRegistration.serializer() == LongSerializer.getInstance() && valueProtocolRegistration.serializer() == ObjectProtocolSerializer.getInstance()) {
|
||||
} else if (keySerializer == LongSerializer.getInstance() && valueSerializer == ObjectProtocolSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeLongPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(valueProtocolRegistration.getProtocolId())));
|
||||
return;
|
||||
} else if (keySerializer == StringSerializer.getInstance() && valueSerializer == ObjectProtocolSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("{}.writeStringPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(valueProtocolRegistration.getProtocolId())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,38 +116,52 @@ public class EnhanceMapSerializer implements IEnhanceSerializer {
|
||||
var mapField = (MapField) fieldRegistration;
|
||||
var keyRegistration = mapField.getMapKeyRegistration();
|
||||
var valueRegistration = mapField.getMapValueRegistration();
|
||||
var keySerializer = keyRegistration.serializer();
|
||||
var valueSerializer = valueRegistration.serializer();
|
||||
|
||||
var map = "map" + GenerateProtocolFile.index.getAndIncrement();
|
||||
|
||||
if (keyRegistration instanceof BaseField) {
|
||||
if (valueRegistration instanceof BaseField) {
|
||||
var keyBaseRegistration = (BaseField) keyRegistration;
|
||||
var valueBaseRegistration = (BaseField) valueRegistration;
|
||||
if (keyBaseRegistration.serializer() == IntSerializer.getInstance() && valueBaseRegistration.serializer() == IntSerializer.getInstance()) {
|
||||
if (keySerializer == IntSerializer.getInstance() && valueSerializer == IntSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
} else if (keyBaseRegistration.serializer() == IntSerializer.getInstance() && valueBaseRegistration.serializer() == LongSerializer.getInstance()) {
|
||||
} else if (keySerializer == IntSerializer.getInstance() && valueSerializer == LongSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
} else if (keyBaseRegistration.serializer() == LongSerializer.getInstance() && valueBaseRegistration.serializer() == IntSerializer.getInstance()) {
|
||||
} else if (keySerializer == IntSerializer.getInstance() && valueSerializer == StringSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
} else if (keySerializer == LongSerializer.getInstance() && valueSerializer == IntSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
} else if (keyBaseRegistration.serializer() == LongSerializer.getInstance() && valueBaseRegistration.serializer() == LongSerializer.getInstance()) {
|
||||
} else if (keySerializer == LongSerializer.getInstance() && valueSerializer == LongSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
} else if (keyBaseRegistration.serializer() == IntSerializer.getInstance() && valueBaseRegistration.serializer() == StringSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
} else if (keySerializer == LongSerializer.getInstance() && valueSerializer == StringSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
} else if (keySerializer == StringSerializer.getInstance() && valueSerializer == IntSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringIntMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
} else if (keySerializer == StringSerializer.getInstance() && valueSerializer == LongSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringLongMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
} else if (keySerializer == StringSerializer.getInstance() && valueSerializer == StringSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringStringMap($1);", map, EnhanceUtils.byteBufUtils));
|
||||
return map;
|
||||
}
|
||||
} else if (valueRegistration instanceof ObjectProtocolField) {
|
||||
var keyBaseRegistration = (BaseField) keyRegistration;
|
||||
var valueProtocolRegistration = (ObjectProtocolField) valueRegistration;
|
||||
if (keyBaseRegistration.serializer() == IntSerializer.getInstance() && valueProtocolRegistration.serializer() == ObjectProtocolSerializer.getInstance()) {
|
||||
if (keySerializer == IntSerializer.getInstance() && valueSerializer == ObjectProtocolSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readIntPacketMap($1, {});", map, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(valueProtocolRegistration.getProtocolId())));
|
||||
return map;
|
||||
} else if (keyBaseRegistration.serializer() == LongSerializer.getInstance() && valueProtocolRegistration.serializer() == ObjectProtocolSerializer.getInstance()) {
|
||||
} else if (keySerializer == LongSerializer.getInstance() && valueSerializer == ObjectProtocolSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readLongPacketMap($1, {});", map, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(valueProtocolRegistration.getProtocolId())));
|
||||
return map;
|
||||
} else if (keySerializer == StringSerializer.getInstance() && valueSerializer == ObjectProtocolSerializer.getInstance()) {
|
||||
builder.append(StringUtils.format("Map {} = {}.readStringPacketMap($1, {});", map, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(valueProtocolRegistration.getProtocolId())));
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.buffer.model;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class MyObjectA implements IPacket {
|
||||
|
||||
public static final transient short PROTOCOL_ID = 2;
|
||||
|
||||
public int a;
|
||||
|
||||
public Map<Integer, String> b;
|
||||
|
||||
public MyObjectB c;
|
||||
|
||||
@Override
|
||||
public short protocolId() {
|
||||
return PROTOCOL_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MyObjectA myObjectA = (MyObjectA) o;
|
||||
return a == myObjectA.a && Objects.equals(b, myObjectA.b) && Objects.equals(c, myObjectA.c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(a, b, c);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.buffer.model;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class MyObjectB implements IPacket {
|
||||
|
||||
public static final transient short PROTOCOL_ID = 3;
|
||||
|
||||
public boolean a;
|
||||
|
||||
@Override
|
||||
public short protocolId() {
|
||||
return PROTOCOL_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MyObjectB myObjectB = (MyObjectB) o;
|
||||
return a == myObjectB.a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.protocol.buffer.model;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public class MyPacket implements IPacket {
|
||||
|
||||
public static final transient short PROTOCOL_ID = 1;
|
||||
|
||||
// 基础类型
|
||||
public byte base1;
|
||||
public short base2;
|
||||
public int base3;
|
||||
public long base4;
|
||||
public float base5;
|
||||
public double base6;
|
||||
public boolean base7;
|
||||
public char base8;
|
||||
|
||||
// 包装类型
|
||||
public Byte box1;
|
||||
public Short box2;
|
||||
public Integer box3;
|
||||
public Long box4;
|
||||
public Float box5;
|
||||
public Double box6;
|
||||
public Boolean box7;
|
||||
public Character box8;
|
||||
|
||||
// string
|
||||
public String str;
|
||||
public MyObjectA objectA;
|
||||
|
||||
// 数组
|
||||
public byte[] array1;
|
||||
public Byte[] array2;
|
||||
public short[] array3;
|
||||
public Short[] array4;
|
||||
public int[] array5;
|
||||
public Integer[] array6;
|
||||
public long[] array7;
|
||||
public Long[] array8;
|
||||
public float[] array9;
|
||||
public Float[] array10;
|
||||
public double[] array11;
|
||||
public Double[] array12;
|
||||
public boolean[] array13;
|
||||
public Boolean[] array14;
|
||||
public char[] array15;
|
||||
public Character[] array16;
|
||||
public String[] array17;
|
||||
public MyObjectA[] array18;
|
||||
|
||||
// list
|
||||
public List<Byte> list1;
|
||||
public List<Short> list2;
|
||||
public List<Integer> list3;
|
||||
public List<Long> list4;
|
||||
public List<Float> list5;
|
||||
public List<Double> list6;
|
||||
public List<Boolean> list7;
|
||||
public List<Character> list8;
|
||||
public List<String> list9;
|
||||
public List<MyObjectA> list10;
|
||||
|
||||
|
||||
// set
|
||||
public Set<Byte> set1;
|
||||
public Set<Short> set2;
|
||||
public Set<Integer> set3;
|
||||
public Set<Long> set4;
|
||||
public Set<Float> set5;
|
||||
public Set<Double> set6;
|
||||
public Set<Boolean> set7;
|
||||
public Set<Character> set8;
|
||||
public Set<String> set9;
|
||||
public Set<MyObjectA> set10;
|
||||
|
||||
|
||||
// map
|
||||
public Map<Integer, Integer> map1;
|
||||
public Map<Integer, Long> map2;
|
||||
public Map<Integer, String> map3;
|
||||
public Map<Integer, MyObjectA> map4;
|
||||
public Map<Long, Integer> map5;
|
||||
public Map<Long, Long> map6;
|
||||
public Map<Long, String> map7;
|
||||
public Map<Long, MyObjectA> map8;
|
||||
public Map<String, Integer> map9;
|
||||
public Map<String, Long> map10;
|
||||
public Map<String, String> map11;
|
||||
public Map<String, MyObjectA> map12;
|
||||
public Map<Byte, Byte> map15;
|
||||
public Map<Short, Short> map16;
|
||||
public Map<Float, Float> map17;
|
||||
public Map<Double, Double> map18;
|
||||
public Map<Boolean, Boolean> map19;
|
||||
public Map<Character, Character> map20;
|
||||
public Map<MyObjectA, MyObjectA> map21;
|
||||
public Map<MyObjectA, List<Integer>> map22;
|
||||
|
||||
// mix
|
||||
public List<List<Integer>> listList1;
|
||||
public List<List<MyObjectA>> listList2;
|
||||
public List<Set<Integer>> listSet1;
|
||||
public List<Set<MyObjectA>> listSet2;
|
||||
public List<Map<Integer, Integer>> listMap1;
|
||||
public List<Map<MyObjectA, Integer>> listMap2;
|
||||
public List<List<Set<Integer>>> listListSet;
|
||||
public List<List<Map<Integer, Integer>>> listListMap;
|
||||
|
||||
public Set<List<Integer>> setList1;
|
||||
public Set<List<MyObjectA>> setList2;
|
||||
public Set<Set<Integer>> setSet1;
|
||||
public Set<Set<MyObjectA>> setSet2;
|
||||
public Set<Map<Integer, Integer>> setMap1;
|
||||
public Set<Map<MyObjectA, Integer>> setMap2;
|
||||
public Set<List<Set<Integer>>> setListSet;
|
||||
public Set<List<Map<Integer, Integer>>> setListMap;
|
||||
|
||||
public Map<Integer, List<Integer>> mapList1;
|
||||
public Map<MyObjectA, List<MyObjectA>> mapList2;
|
||||
public Map<Set<Integer>, Integer> mapSet1;
|
||||
public Map<Set<MyObjectA>, MyObjectA> mapSet2;
|
||||
public Map<Integer, Map<Integer, Integer>> mapMap1;
|
||||
public Map<MyObjectA, Map<MyObjectA, Integer>> mapMap2;
|
||||
public Map<Integer, List<Set<Integer>>> mapListSet;
|
||||
public Map<MyObjectA, List<Map<Integer, Integer>>> mapListMap;
|
||||
|
||||
@Override
|
||||
public short protocolId() {
|
||||
return PROTOCOL_ID;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user