|
@@ -0,0 +1,84 @@
|
|
|
+package com.gyee.edge.gateway.bridge.test;
|
|
|
+
|
|
|
+
|
|
|
+import com.gyee.edge.common.utils.ByteUtil;
|
|
|
+import com.gyee.edge.gateway.protobuf.UserProto;
|
|
|
+
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ThreadLocalRandom;
|
|
|
+
|
|
|
+public class ReadGolden {
|
|
|
+ public static byte[] protoData() throws UnsupportedEncodingException {
|
|
|
+ String[] tagNames = StringKey.key.split(",");
|
|
|
+ List<String> list = Arrays.asList(tagNames);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ Map<byte[], byte[]> bl = ReadGolden.putByte(list);
|
|
|
+ Date ST=new Date();
|
|
|
+ System.out.println("序列化前时间"+(ST.getTime()));
|
|
|
+ UserProto.User.Builder user = UserProto.User.newBuilder();
|
|
|
+ UserProto.User.Datas.Builder objectMap = UserProto.User.Datas.newBuilder();
|
|
|
+ for (Map.Entry<byte[],byte[]> entry:bl.entrySet()){
|
|
|
+ String keys = ReadGolden.byteToString(entry.getKey());
|
|
|
+ double val = ByteUtil.getDouble(entry.getValue(), 0);
|
|
|
+ long ts = ByteUtil.getLong2(entry.getValue(), 8);
|
|
|
+ user.putMap(keys, objectMap.setTs(ts).setValue(val).build());
|
|
|
+ }
|
|
|
+ UserProto.User build = user.build();
|
|
|
+ byte[] s = build.toByteArray();
|
|
|
+ Date ET=new Date();
|
|
|
+ System.out.println("序列化后时间"+(ET.getTime()));
|
|
|
+ System.out.println("序列化时间:"+(ET.getTime()-ST.getTime()));
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static Map<byte[], byte[]> putByte(List<String> lists) throws UnsupportedEncodingException {
|
|
|
+ Map<byte[], byte[]> b = new HashMap<>();
|
|
|
+ byte[][] rawKeys = new byte[lists.size()][];
|
|
|
+ double min = 1.0;
|
|
|
+ double max = 100.0;
|
|
|
+ for (int i = 0; i < lists.size(); i++) {
|
|
|
+ rawKeys[i] = lists.get(i).getBytes("ascii");
|
|
|
+ byte[] bb = {};
|
|
|
+ //随机生成double
|
|
|
+ double generatedDouble = ThreadLocalRandom.current().nextDouble(min, max);
|
|
|
+ byte[] bt1 = ByteUtil.putDouble(bb, generatedDouble, 0);
|
|
|
+ long time = new Date().getTime();
|
|
|
+ byte[] bt2 = ByteUtil.putLong(bb, time, 0);
|
|
|
+ byte[] bt3 = new byte[bt1.length + bt2.length];
|
|
|
+ bt3[0] = bt1[0];
|
|
|
+ bt3[1] = bt1[1];
|
|
|
+ bt3[2] = bt1[2];
|
|
|
+ bt3[3] = bt1[3];
|
|
|
+ bt3[4] = bt1[4];
|
|
|
+ bt3[5] = bt1[5];
|
|
|
+ bt3[6] = bt1[6];
|
|
|
+ bt3[7] = bt1[7];
|
|
|
+ bt3[8] = bt2[0];
|
|
|
+ bt3[9] = bt2[1];
|
|
|
+ bt3[10] = bt2[2];
|
|
|
+ bt3[11] = bt2[3];
|
|
|
+ bt3[12] = bt2[4];
|
|
|
+ bt3[13] = bt2[5];
|
|
|
+ bt3[14] = bt2[6];
|
|
|
+ bt3[15] = bt2[7];
|
|
|
+ b.put(rawKeys[i], bt3);
|
|
|
+ }
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String byteToString (byte[] bytes) {
|
|
|
+ if (null == bytes || bytes.length == 0) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String strContent = "";
|
|
|
+ try {
|
|
|
+ strContent = new String(bytes, "utf-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return strContent;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|