diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..4d39e213a265e9d29f57566eb278e7dbfec94cc1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+# Log file
+*.log
+logs
+*.db
+.idea
+*.iml
+target/
+/output/*.CIME
diff --git a/adapter/pom.xml b/adapter/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..48349ffca5ed6e3da18283337e2f08fe8815e908
--- /dev/null
+++ b/adapter/pom.xml
@@ -0,0 +1,144 @@
+
+
+
+ lite-adapter
+ org.taj
+ 1.0
+
+
+ 4.0.0
+
+ adapter
+
+
+ 11
+ 11
+
+
+
+
+ org.taj
+ common
+ 1.0
+
+
+ org.taj
+ spring-boot-starter
+ 1.0
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+
+
+
+
+ com.squareup.okhttp3
+ okhttp
+
+
+ com.squareup.okhttp3
+ okhttp-sse
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.53
+
+
+
+ org.zeromq
+ jeromq
+ 0.5.3
+
+
+
+
+ ${project.artifactId}
+
+
+ src/main/java
+
+ **/*.properties
+ **/*.xml
+
+ false
+
+
+ src/main/resources
+
+ **/*
+
+
+ tessdata-4.1.0/**
+
+ false
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 11
+ 11
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ 2.6.4
+
+ true
+
+
+ org.projectlombok
+ lombok
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+
+
+
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 3.1.0
+
+
+ copy-resource
+ package
+
+ copy-resources
+
+
+ ../target
+
+
+
+ ${basedir}/target/
+
+ *.jar
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/adapter/src/main/java/org/taj/adapter/AdapterApplication.java b/adapter/src/main/java/org/taj/adapter/AdapterApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..a62c2cc71b7e16498d242a60550cc76635590180
--- /dev/null
+++ b/adapter/src/main/java/org/taj/adapter/AdapterApplication.java
@@ -0,0 +1,17 @@
+package org.taj.adapter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+
+@SpringBootApplication
+public class AdapterApplication {
+ private static Logger LOG = LoggerFactory.getLogger(AdapterApplication.class);
+
+ public static void main(String[] args) {
+ new SpringApplicationBuilder(AdapterApplication.class).web(WebApplicationType.NONE).run(args);
+ LOG.info("GPT-Lite-Adapter 启动成功...");
+ }
+}
diff --git a/adapter/src/main/java/org/taj/adapter/llama/LLaMAClient.java b/adapter/src/main/java/org/taj/adapter/llama/LLaMAClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..4e4aaccf712a43334e1a98d36016824639d64da9
--- /dev/null
+++ b/adapter/src/main/java/org/taj/adapter/llama/LLaMAClient.java
@@ -0,0 +1,79 @@
+package org.taj.adapter.llama;
+
+import com.alibaba.fastjson2.JSON;
+import okhttp3.*;
+import okhttp3.sse.EventSource;
+import okhttp3.sse.EventSourceListener;
+import okhttp3.sse.EventSources;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.taj.adapter.server.Session;
+import org.zeromq.ZMQ;
+
+import java.util.List;
+
+@Component
+public class LLaMAClient {
+ private OkHttpClient client = new OkHttpClient();
+ @Value("${llama.host}")
+ private String host;
+ @Value("${llama.port}")
+ private String port;
+
+ public void send(Session session, ZMQ.Socket pubSocket, String sessionId) {
+ StringBuilder respBuffer = new StringBuilder();
+ RequestBody body = RequestBody.create(session.toString(), MediaType.parse("application/json"));
+ Request req = new Request.Builder().url("http://" + host + ":" + port + "/v1/chat/completions").post(body).build();
+ EventSource.Factory factory = EventSources.createFactory(client);
+ factory.newEventSource(req, new EventSourceListener() {
+ @Override
+ public void onOpen(EventSource eventSource, Response response) {
+ System.out.println("SSE连接已开启");
+ }
+
+ @Override
+ public void onEvent(EventSource eventSource, String id, String type, String data) {
+ if (data.equals("[DONE]")) {
+ eventSource.cancel();
+ } else {
+ LLaMAResponse response = JSON.parseObject(data, LLaMAResponse.class);
+ List choices = response.getChoices();
+ LLaMAResponse.Choice choice = choices.get(0);
+ if (choice.getFinishReason() != null && choice.getFinishReason().equals("stop")) {
+ session.addAssistantResponse(respBuffer.toString());
+ if(response.getTimings() != null) {
+ LLaMAResponse.Timing timings = response.getTimings();
+ long promptN = timings.getPromptN();
+ double promptMs = timings.getPromptMs();
+ long predictedN = timings.getPredictedN();
+ double predictedMs = timings.getPredictedMs();
+ session.setTimings(promptN, promptMs, predictedN, predictedMs);
+ }
+ pubSocket.send(sessionId);
+ System.out.println();
+ } else {
+ String content = choice.getDelta().getContent();
+ respBuffer.append(content);
+ pubSocket.sendMore(sessionId);
+ pubSocket.send(content);
+ System.out.print(content);
+ }
+ }
+ }
+
+ @Override
+ public void onClosed(EventSource eventSource) {
+ System.out.println("SSE连接已关闭");
+ }
+
+ @Override
+ public void onFailure(EventSource eventSource, Throwable t, Response response) {
+ System.err.println("SSE连接失败: " + t.getMessage());
+ if (response != null) {
+ System.err.println("Response Code: " + response.code());
+ }
+ }
+ });
+
+ }
+}
diff --git a/adapter/src/main/java/org/taj/adapter/llama/LLaMARequest.java b/adapter/src/main/java/org/taj/adapter/llama/LLaMARequest.java
new file mode 100644
index 0000000000000000000000000000000000000000..982d8e4d94b95661e51633814934655741348a00
--- /dev/null
+++ b/adapter/src/main/java/org/taj/adapter/llama/LLaMARequest.java
@@ -0,0 +1,423 @@
+package org.taj.adapter.llama;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.annotation.JSONField;
+import okhttp3.*;
+import okhttp3.sse.EventSource;
+import okhttp3.sse.EventSourceListener;
+import okhttp3.sse.EventSources;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public class LLaMARequest {
+ public static class Message {
+ @JSONField(name = "id")
+ private long id;
+ @JSONField(name = "role")
+ private String role;
+ @JSONField(name = "content")
+ private String content;
+
+ public Message(long id, String role, String content) {
+ this.id = id;
+ this.role = role;
+ this.content = content;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getRole() {
+ return role;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+ }
+
+ public static class Tool {
+ @JSONField(name = "type")
+ private String type;
+ @JSONField(name = "function")
+ private Function function;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Function getFunction() {
+ return function;
+ }
+
+ public void setFunction(Function function) {
+ this.function = function;
+ }
+ }
+
+ public static class Function {
+ @JSONField(name = "name")
+ private String name;
+ @JSONField(name = "description")
+ private String description;
+ @JSONField(name = "parameters")
+ private Parameter parameters;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Parameter getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(Parameter parameters) {
+ this.parameters = parameters;
+ }
+ }
+
+ public static class Parameter {
+ @JSONField(name = "type")
+ private String type;
+ @JSONField(name = "required")
+ private List required;
+ @JSONField(name = "additionalProperties")
+ private boolean additionalProperties;
+ @JSONField(name = "properties")
+ private Map properties = new HashMap<>();
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public List getRequired() {
+ return required;
+ }
+
+ public void setRequired(List required) {
+ this.required = required;
+ }
+
+ public boolean isAdditionalProperties() {
+ return additionalProperties;
+ }
+
+ public void setAdditionalProperties(boolean additionalProperties) {
+ this.additionalProperties = additionalProperties;
+ }
+
+ public Map getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map properties) {
+ this.properties = properties;
+ }
+
+ public void addProperty(String key, PropertyItem propertyItem) {
+ this.properties.put(key, propertyItem);
+ }
+ }
+
+ public static class PropertyItem {
+ @JSONField(name = "type")
+ private String type;
+ @JSONField(name = "description")
+ private String description;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ }
+
+ @JSONField(name = "messages")
+ private List messages;
+ @JSONField(name = "tools")
+ private List tools;
+ @JSONField(name = "stream")
+ private boolean stream;
+ @JSONField(name = "cache_prompt")
+ private boolean cachePrompt;
+ @JSONField(name = "samplers")
+ private String samplers;
+ @JSONField(name = "temperature")
+ private double temperature;
+ @JSONField(name = "dynatemp_range")
+ private double dynatempRange;
+ @JSONField(name = "dynatemp_exponent")
+ private double dynatempExponent;
+ @JSONField(name = "top_k")
+ private int topK;
+ @JSONField(name = "top_p")
+ private double topP;
+ @JSONField(name = "min_p")
+ private double minP;
+ @JSONField(name = "typical_p")
+ private int typicalP;
+ @JSONField(name = "xtc_probability")
+ private int xtcProbability;
+ @JSONField(name = "xtc_threshold")
+ private double xtcThreshold;
+ @JSONField(name = "repeat_last_n")
+ private int repeatLastN;
+ @JSONField(name = "repeat_penalty")
+ private int repeatPenalty;
+ @JSONField(name = "presence_penalty")
+ private int presencePenalty;
+ @JSONField(name = "frequency_penalty")
+ private int frequencyPenalty;
+ @JSONField(name = "dry_multiplier")
+ private int dryMultiplier;
+ @JSONField(name = "dry_base")
+ private double dryBase;
+ @JSONField(name = "dry_allowed_length")
+ private int dryAllowedLength;
+ @JSONField(name = "dry_penalty_last_n")
+ private int dryPenaltyLastN;
+ @JSONField(name = "max_tokens")
+ private int maxTokens;
+ @JSONField(name = "timings_per_token")
+ private boolean timingsPerToken;
+
+ public LLaMARequest(List messages) {
+ this(messages, null, true, true, "edkypmxt", 0.8, 0.0, 1.0, 40, 0.95,
+ 0.05, 1, 0, 0.1, 64, 1, 0, 0, 0,
+ 1.75, 2, -1, -1, false);
+ }
+
+ public LLaMARequest(List messages, List tools) {
+ this(messages, tools, true, true, "edkypmxt", 0.8, 0.0, 1.0, 40, 0.95,
+ 0.05, 1, 0, 0.1, 64, 1, 0, 0, 0,
+ 1.75, 2, -1, -1, false);
+ this.stream = false;
+ }
+
+ public LLaMARequest(List messages, List tools,
+ boolean stream, boolean cachePrompt, String samplers, double temperature,
+ double dynatempRange, double dynatempExponent,
+ int topK, double topP, double minP, int typicalP, int xtcProbability,
+ double xtcThreshold, int repeatLastN, int repeatPenalty, int presencePenalty,
+ int frequencyPenalty, int dryMultiplier, double dryBase, int dryAllowedLength,
+ int dryPenaltyLastN, int maxTokens, boolean timingsPerToken) {
+ this.stream = stream;
+ this.cachePrompt = cachePrompt;
+ this.samplers = samplers;
+ this.temperature = temperature;
+ this.dynatempRange = dynatempRange;
+ this.dynatempExponent = dynatempExponent;
+ this.topK = topK;
+ this.topP = topP;
+ this.minP = minP;
+ this.typicalP = typicalP;
+ this.xtcProbability = xtcProbability;
+ this.xtcThreshold = xtcThreshold;
+ this.repeatLastN = repeatLastN;
+ this.repeatPenalty = repeatPenalty;
+ this.presencePenalty = presencePenalty;
+ this.frequencyPenalty = frequencyPenalty;
+ this.dryMultiplier = dryMultiplier;
+ this.dryBase = dryBase;
+ this.dryAllowedLength = dryAllowedLength;
+ this.dryPenaltyLastN = dryPenaltyLastN;
+ this.maxTokens = maxTokens;
+ this.timingsPerToken = timingsPerToken;
+ this.messages = messages;
+ this.tools = tools;
+ }
+
+ public List getMessages() {
+ return messages;
+ }
+
+ public List getTools() {
+ return tools;
+ }
+
+ public boolean isStream() {
+ return stream;
+ }
+
+ public boolean isCachePrompt() {
+ return cachePrompt;
+ }
+
+ public String getSamplers() {
+ return samplers;
+ }
+
+ public double getTemperature() {
+ return temperature;
+ }
+
+ public double getDynatempRange() {
+ return dynatempRange;
+ }
+
+ public double getDynatempExponent() {
+ return dynatempExponent;
+ }
+
+ public int getTopK() {
+ return topK;
+ }
+
+ public double getTopP() {
+ return topP;
+ }
+
+ public double getMinP() {
+ return minP;
+ }
+
+ public int getTypicalP() {
+ return typicalP;
+ }
+
+ public int getXtcProbability() {
+ return xtcProbability;
+ }
+
+ public double getXtcThreshold() {
+ return xtcThreshold;
+ }
+
+ public int getRepeatLastN() {
+ return repeatLastN;
+ }
+
+ public int getRepeatPenalty() {
+ return repeatPenalty;
+ }
+
+ public int getPresencePenalty() {
+ return presencePenalty;
+ }
+
+ public int getFrequencyPenalty() {
+ return frequencyPenalty;
+ }
+
+ public int getDryMultiplier() {
+ return dryMultiplier;
+ }
+
+ public double getDryBase() {
+ return dryBase;
+ }
+
+ public int getDryAllowedLength() {
+ return dryAllowedLength;
+ }
+
+ public int getDryPenaltyLastN() {
+ return dryPenaltyLastN;
+ }
+
+ public int getMaxTokens() {
+ return maxTokens;
+ }
+
+ public boolean isTimingsPerToken() {
+ return timingsPerToken;
+ }
+
+ public static void main(String[] args) throws InterruptedException {
+ List tools = new ArrayList<>();
+ Tool tool = new Tool();
+ tool.setType("function");
+ Function function = new Function();
+ function.setName("get_current_weather");
+ function.setDescription("Get the current weather in a given location");
+ Parameter parameter = new Parameter();
+ parameter.setType("object");
+ parameter.setRequired(List.of("location", "date"));
+ PropertyItem location = new PropertyItem();
+ location.setType("string");
+ location.setDescription("The city and state, e.g. San Francisco, CA");
+ PropertyItem date = new PropertyItem();
+ date.setType("string");
+ date.setDescription("The date, in YYYY-MM-DD format");
+ parameter.addProperty("location", location);
+ parameter.addProperty("date", date);
+ function.setParameters(parameter);
+ tool.setFunction(function);
+ tools.add(tool);
+
+ LLaMARequest request = new LLaMARequest(
+ List.of(new Message(0, "user", "南京2025年3月5日的是否下雨?")), tools
+ );
+
+ String json = JSON.toJSONString(request);
+ RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));
+ Request req = new Request.Builder().url("http://192.168.2.246:8080/v1/chat/completions").post(body).build();
+ OkHttpClient client = new OkHttpClient();
+ EventSource.Factory factory = EventSources.createFactory(client);
+ factory.newEventSource(req, new EventSourceListener() {
+ @Override
+ public void onOpen(EventSource eventSource, Response response) {
+ System.out.println("SSE连接已开启");
+ }
+
+ @Override
+ public void onEvent(EventSource eventSource, String id, String type, String data) {
+ System.out.println("SSE数据: " + data);
+ }
+
+ @Override
+ public void onClosed(EventSource eventSource) {
+ System.out.println("SSE连接已关闭");
+ }
+
+ @Override
+ public void onFailure(EventSource eventSource, Throwable t, Response response) {
+ System.err.println("SSE连接失败: " + t.getMessage());
+ if (response != null) {
+ System.err.println("Response Code: " + response.code());
+ }
+ }
+ });
+
+ TimeUnit.SECONDS.sleep(100);
+ }
+}
diff --git a/adapter/src/main/java/org/taj/adapter/llama/LLaMAResponse.java b/adapter/src/main/java/org/taj/adapter/llama/LLaMAResponse.java
new file mode 100644
index 0000000000000000000000000000000000000000..3782a4207bbb25ca07cdc9819ab07668d2799f4a
--- /dev/null
+++ b/adapter/src/main/java/org/taj/adapter/llama/LLaMAResponse.java
@@ -0,0 +1,251 @@
+package org.taj.adapter.llama;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class LLaMAResponse {
+ public static class Delta {
+ @JSONField(name = "content")
+ private String content;
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+ }
+
+ public static class Choice {
+ @JSONField(name = "finish_reason")
+ private String finishReason;
+ @JSONField(name = "index")
+ private long index;
+ @JSONField(name = "delta")
+ private Delta delta;
+
+ public String getFinishReason() {
+ return finishReason;
+ }
+
+ public void setFinishReason(String finishReason) {
+ this.finishReason = finishReason;
+ }
+
+ public long getIndex() {
+ return index;
+ }
+
+ public void setIndex(long index) {
+ this.index = index;
+ }
+
+ public Delta getDelta() {
+ return delta;
+ }
+
+ public void setDelta(Delta delta) {
+ this.delta = delta;
+ }
+ }
+
+ public static class Usage {
+ @JSONField(name = "completion_tokens")
+ private long completionTokens;
+ @JSONField(name = "prompt_tokens")
+ private long promptTokens;
+ @JSONField(name = "total_tokens")
+ private long totalTokens;
+
+ public long getCompletionTokens() {
+ return completionTokens;
+ }
+
+ public void setCompletionTokens(long completionTokens) {
+ this.completionTokens = completionTokens;
+ }
+
+ public long getPromptTokens() {
+ return promptTokens;
+ }
+
+ public void setPromptTokens(long promptTokens) {
+ this.promptTokens = promptTokens;
+ }
+
+ public long getTotalTokens() {
+ return totalTokens;
+ }
+
+ public void setTotalTokens(long totalTokens) {
+ this.totalTokens = totalTokens;
+ }
+ }
+
+ public static class Timing {
+ @JSONField(name = "prompt_n")
+ private long promptN;
+ @JSONField(name = "prompt_ms")
+ private double promptMs;
+ @JSONField(name = "prompt_per_token_ms")
+ private double promptPerTokenMs;
+ @JSONField(name = "prompt_per_second")
+ private double promptPerSecond;
+ @JSONField(name = "predicted_n")
+ private long predictedN;
+ @JSONField(name = "predicted_ms")
+ private double predictedMs;
+ @JSONField(name = "predicted_per_token_ms")
+ private double predictedPreTokenMs;
+ @JSONField(name = "predicted_per_second")
+ private double predictedPreSecond;
+
+ public long getPromptN() {
+ return promptN;
+ }
+
+ public void setPromptN(long promptN) {
+ this.promptN = promptN;
+ }
+
+ public double getPromptMs() {
+ return promptMs;
+ }
+
+ public void setPromptMs(double promptMs) {
+ this.promptMs = promptMs;
+ }
+
+ public double getPromptPerTokenMs() {
+ return promptPerTokenMs;
+ }
+
+ public void setPromptPerTokenMs(double promptPerTokenMs) {
+ this.promptPerTokenMs = promptPerTokenMs;
+ }
+
+ public double getPromptPerSecond() {
+ return promptPerSecond;
+ }
+
+ public void setPromptPerSecond(double promptPerSecond) {
+ this.promptPerSecond = promptPerSecond;
+ }
+
+ public long getPredictedN() {
+ return predictedN;
+ }
+
+ public void setPredictedN(long predictedN) {
+ this.predictedN = predictedN;
+ }
+
+ public double getPredictedMs() {
+ return predictedMs;
+ }
+
+ public void setPredictedMs(double predictedMs) {
+ this.predictedMs = predictedMs;
+ }
+
+ public double getPredictedPreTokenMs() {
+ return predictedPreTokenMs;
+ }
+
+ public void setPredictedPreTokenMs(double predictedPreTokenMs) {
+ this.predictedPreTokenMs = predictedPreTokenMs;
+ }
+
+ public double getPredictedPreSecond() {
+ return predictedPreSecond;
+ }
+
+ public void setPredictedPreSecond(double predictedPreSecond) {
+ this.predictedPreSecond = predictedPreSecond;
+ }
+ }
+
+ @JSONField(name = "choices")
+ private List choices = new ArrayList<>();
+ @JSONField(name = "created")
+ private long created;
+ @JSONField(name = "id")
+ private String id;
+ @JSONField(name = "model")
+ private String model;
+ @JSONField(name = "system_fingerprint")
+ private String systemFingerprint;
+ @JSONField(name = "object")
+ private String object;
+ @JSONField(name = "usage")
+ private Usage usage;
+ @JSONField(name = "timings")
+ private Timing timings;
+
+ public List getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List choices) {
+ this.choices = choices;
+ }
+
+ public long getCreated() {
+ return created;
+ }
+
+ public void setCreated(long created) {
+ this.created = created;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+
+ public String getSystemFingerprint() {
+ return systemFingerprint;
+ }
+
+ public void setSystemFingerprint(String systemFingerprint) {
+ this.systemFingerprint = systemFingerprint;
+ }
+
+ public String getObject() {
+ return object;
+ }
+
+ public void setObject(String object) {
+ this.object = object;
+ }
+
+ public Usage getUsage() {
+ return usage;
+ }
+
+ public void setUsage(Usage usage) {
+ this.usage = usage;
+ }
+
+ public Timing getTimings() {
+ return timings;
+ }
+
+ public void setTimings(Timing timings) {
+ this.timings = timings;
+ }
+}
diff --git a/adapter/src/main/java/org/taj/adapter/server/Server.java b/adapter/src/main/java/org/taj/adapter/server/Server.java
new file mode 100644
index 0000000000000000000000000000000000000000..6a6295565e513cbbd002ba16dd3fe71a99f51e29
--- /dev/null
+++ b/adapter/src/main/java/org/taj/adapter/server/Server.java
@@ -0,0 +1,67 @@
+package org.taj.adapter.server;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.taj.adapter.llama.LLaMAClient;
+import org.zeromq.SocketType;
+import org.zeromq.ZContext;
+import org.zeromq.ZMQ;
+
+import javax.annotation.PostConstruct;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+@Component
+public class Server {
+ private ZContext ctx;
+ @Value("${adapter.req-port}")
+ private int reqPort;
+ @Value("${adapter.pub-port}")
+ private int pubPort;
+ @Autowired
+ private LLaMAClient client;
+
+ private AtomicLong sessionId = new AtomicLong(0);
+
+ private Map sessionHolder = new HashMap<>();
+
+ @PostConstruct
+ public void start() {
+ ctx = new ZContext();
+ ZMQ.Socket repSocket = ctx.createSocket(SocketType.REP);
+ repSocket.bind("tcp://*:" + reqPort);
+ ZMQ.Socket pubSocket = ctx.createSocket(SocketType.PUB);
+ pubSocket.bind("tcp://*:" + pubPort);
+ while (true) {
+ String header = repSocket.recvStr();
+ String body = repSocket.recvStr();
+ JSONObject jsonBody = JSON.parseObject(body);
+ String systemPrompt = jsonBody.getString("systemPrompt");
+ String userInput = jsonBody.getString("userInput");
+ Session session;
+ if(header.equals("00000000")) {
+ do {
+ header = String.format("%08d", sessionId.addAndGet(1));
+ } while (sessionHolder.containsKey(header));
+ session = new Session();
+ sessionHolder.put(header, session);
+ }
+ else if(sessionHolder.containsKey(header)) {
+ session = sessionHolder.get(header);
+ } else {
+ session = new Session();
+ sessionHolder.put(header, session);
+ }
+ repSocket.send(header, ZMQ.DONTWAIT);
+ session.setPrompt(systemPrompt);
+ session.addUserInput(userInput);
+ client.send(session, pubSocket, header);
+
+
+ }
+ }
+}
diff --git a/adapter/src/main/java/org/taj/adapter/server/Session.java b/adapter/src/main/java/org/taj/adapter/server/Session.java
new file mode 100644
index 0000000000000000000000000000000000000000..7dbc9ecc77a1d7bebfab1a5c37c526a214446af1
--- /dev/null
+++ b/adapter/src/main/java/org/taj/adapter/server/Session.java
@@ -0,0 +1,53 @@
+package org.taj.adapter.server;
+
+import com.alibaba.fastjson2.JSON;
+import org.taj.adapter.llama.LLaMAClient;
+import org.taj.adapter.llama.LLaMARequest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Session {
+ private LLaMARequest.Message prompt;
+ private List history;
+ private long created;
+ private long promptN;
+ private double promptElapsedSecond;
+ private long predictedN;
+ private double predictedElapsedSecond;
+
+ public Session() {
+ history = new ArrayList<>();
+ prompt = new LLaMARequest.Message(0, "system", "");
+ history.add(prompt);
+ created = System.currentTimeMillis();
+ }
+
+ public void setPrompt(String prompt) {
+ this.prompt.setContent(prompt);
+ }
+
+ public void addUserInput(String input) {
+ LLaMARequest.Message message = new LLaMARequest.Message(System.currentTimeMillis(), "user", input);
+ history.add(message);
+ }
+
+ public void addAssistantResponse(String response) {
+ LLaMARequest.Message message = new LLaMARequest.Message(System.currentTimeMillis(), "assistant", response);
+ history.add(message);
+ }
+
+ public void setTimings(long promptN, double promptElapsedSecond, long predictedN, double predictedElapsedSecond) {
+ this.promptN += promptN;
+ this.promptElapsedSecond += promptElapsedSecond;
+ this.predictedN += predictedN;
+ this.predictedElapsedSecond += predictedElapsedSecond;
+ }
+
+ public String toString() {
+ LLaMARequest request = new LLaMARequest(history);
+ return JSON.toJSONString(request);
+ }
+
+
+}
diff --git a/adapter/src/main/resources/application.yaml b/adapter/src/main/resources/application.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..b0497cdb5ca37fefd84b28964e7157ef9519f2a6
--- /dev/null
+++ b/adapter/src/main/resources/application.yaml
@@ -0,0 +1,15 @@
+spring:
+ application:
+ name: gpt-lite-adapter
+ jackson:
+ time-zone: GMT+8
+ flyway:
+ enabled: false
+logging:
+ config: classpath:log4j2.xml
+adapter:
+ req-port: 7890
+ pub-port: 7891
+llama:
+ host: 192.168.2.246
+ port: 8080
\ No newline at end of file
diff --git a/adapter/src/main/resources/log4j2.xml b/adapter/src/main/resources/log4j2.xml
new file mode 100644
index 0000000000000000000000000000000000000000..6abbf976d86513220fd9e155f9b8c4565e273249
--- /dev/null
+++ b/adapter/src/main/resources/log4j2.xml
@@ -0,0 +1,63 @@
+
+
+
+ logs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/common/pom.xml b/common/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..5ebb9e83949e416b765d2e9ec4933c2ad3c6282c
--- /dev/null
+++ b/common/pom.xml
@@ -0,0 +1,51 @@
+
+
+
+ lite-adapter
+ org.taj
+ 1.0
+
+ 4.0.0
+
+ common
+
+
+ 11
+ 11
+
+
+
+
+ org.taj
+ hutool
+ 1.0
+
+
+ org.taj
+ spring-boot-starter
+ 1.0
+
+
+
+ com.squareup.okhttp3
+ okhttp
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+ org.zeromq
+ jeromq
+
+
+
+ com.google.protobuf
+ protobuf-java
+
+
+
\ No newline at end of file
diff --git a/common/src/main/java/org/taj/common/http/HttpClient.java b/common/src/main/java/org/taj/common/http/HttpClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..5a76455fe09136750b6d5936553ec0084c63ae93
--- /dev/null
+++ b/common/src/main/java/org/taj/common/http/HttpClient.java
@@ -0,0 +1,82 @@
+package org.taj.common.http;
+
+import cn.hutool.json.JSONUtil;
+import okhttp3.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Objects;
+
+public class HttpClient {
+ public synchronized static Response uploadFiles(String url, File... files) {
+ try {
+ OkHttpClient client = new OkHttpClient();
+ MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
+ for (File f : files) {
+ builder.addFormDataPart("files", f.getName(),
+ RequestBody.create(f, MediaType.parse("multipart/form-data")));
+ }
+
+ RequestBody requestBody = builder.build();
+ Request req = new Request.Builder()
+ .url(url)
+ .post(requestBody)
+ .build();
+
+ Response resp = client.newCall(req).execute();
+ if (resp.isSuccessful()) {
+ return resp;
+ }
+ return null;
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+
+ public synchronized static Response get(String url, Map params) {
+ try {
+ OkHttpClient client = new OkHttpClient();
+ HttpUrl.Builder urlBuilder = Objects.requireNonNull(HttpUrl.parse(url)).newBuilder();
+ if (params != null) {
+ for (Map.Entry entry : params.entrySet()) {
+ urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
+ }
+ }
+ Request request = new Request.Builder()
+ .url(urlBuilder.build().toString())
+ .get()
+ .build();
+ Response resp = client.newCall(request).execute();
+ if (resp.isSuccessful()) {
+ return resp;
+ }
+ return null;
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
+ public synchronized static byte[] downloadGet(String url, Map params) {
+ OkHttpClient client = new OkHttpClient();
+ HttpUrl.Builder urlBuilder = Objects.requireNonNull(HttpUrl.parse(url)).newBuilder();
+ if (params != null) {
+ for (Map.Entry entry : params.entrySet()) {
+ urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
+ }
+ }
+ Request request = new Request.Builder()
+ .url(urlBuilder.build().toString())
+ .get()
+ .build();
+ try {
+ Response resp = client.newCall(request).execute();
+ return Objects.requireNonNull(resp.body()).bytes();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/common/src/main/java/org/taj/common/launch/CryptoLauncher.java b/common/src/main/java/org/taj/common/launch/CryptoLauncher.java
new file mode 100644
index 0000000000000000000000000000000000000000..34a582304d01efa783bf9985ba29ec0a1da14b26
--- /dev/null
+++ b/common/src/main/java/org/taj/common/launch/CryptoLauncher.java
@@ -0,0 +1,27 @@
+package org.taj.common.launch;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
+import org.springframework.boot.SpringApplication;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.ResourceLoader;
+
+import java.io.IOException;
+import java.util.function.Function;
+
+public class CryptoLauncher {
+ private static Logger logger = LoggerFactory.getLogger(CryptoLauncher.class);
+
+ public static void loadResources(SpringApplication app, String[] cryptos, Function decryptFunc) throws IOException {
+ ResourceLoader resourceLoader = app.getResourceLoader();
+ for (String crypto : cryptos) {
+ byte[] bytes = resourceLoader.getResource(crypto).getInputStream().readAllBytes();
+ byte[] apply = decryptFunc.apply(bytes);
+ logger.info("apply crypto:\n{}\n", new String(apply));
+ YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
+ yamlPropertiesFactoryBean.setResources(new ByteArrayResource(apply));
+ app.setDefaultProperties(yamlPropertiesFactoryBean.getObject());
+ }
+ }
+}
diff --git a/common/src/main/java/org/taj/common/task/CronTask.java b/common/src/main/java/org/taj/common/task/CronTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..9c61db11abd82e7c07153355d0f52a691d3671b2
--- /dev/null
+++ b/common/src/main/java/org/taj/common/task/CronTask.java
@@ -0,0 +1,34 @@
+package org.taj.common.task;
+
+import org.springframework.scheduling.support.CronExpression;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class CronTask extends TaskExecutor {
+ public CronTask(String taskName, String cronExpression) {
+ super(taskName, cronExpression);
+ }
+
+ @Override
+ public TaskType taskType() {
+ return TaskType.CRON;
+ }
+
+ @Override
+ public void notifySuccess() {
+
+ }
+
+ @Override
+ public List computeFireTimesBetween(LocalDateTime from, LocalDateTime to) {
+ CronExpression parse = CronExpression.parse(getCronExpression());
+ List lst = new ArrayList<>();
+ LocalDateTime next = parse.next(from);
+ while(next != null && next.isBefore(to)) {
+ lst.add(next);
+ }
+ return lst;
+ }
+}
diff --git a/common/src/main/java/org/taj/common/task/DelayedTask.java b/common/src/main/java/org/taj/common/task/DelayedTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..aa47a7f31ce28c83a72da26b0f9fe9e50f490e98
--- /dev/null
+++ b/common/src/main/java/org/taj/common/task/DelayedTask.java
@@ -0,0 +1,51 @@
+package org.taj.common.task;
+
+import java.time.LocalDateTime;
+import java.time.temporal.TemporalUnit;
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.time.temporal.ChronoUnit.*;
+
+public abstract class DelayedTask extends TaskExecutor {
+ private long delaySecond;
+
+ public DelayedTask(String taskName, long second) {
+ super(taskName, second * 1000);
+ this.delaySecond = 0;
+ }
+
+ public DelayedTask(String taskName, long second, long delaySecond) {
+ super(taskName, second * 1000);
+ this.delaySecond = delaySecond * 1000;
+ }
+
+ public long getDelaySecond() {
+ return delaySecond;
+ }
+
+ @Override
+ public TaskType taskType() {
+ return TaskType.DELAYED;
+ }
+
+ @Override
+ public void notifySuccess() {
+
+ }
+
+ @Override
+ public List computeFireTimesBetween(LocalDateTime from, LocalDateTime to) {
+ List lst = new ArrayList<>();
+ LocalDateTime ldt = getLastSuccessExecuteDateTime();
+ while(true) {
+ ldt = ldt.plus(getElapsed(), MILLIS).plus(getSecond(), SECONDS);
+ if(ldt.isAfter(from) && ldt.isBefore(to)) {
+ lst.add(ldt);
+ continue;
+ }
+ break;
+ }
+ return lst;
+ }
+}
diff --git a/common/src/main/java/org/taj/common/task/IntervalTask.java b/common/src/main/java/org/taj/common/task/IntervalTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..693aa347db04c4fea268c567f3beb779ff93ba29
--- /dev/null
+++ b/common/src/main/java/org/taj/common/task/IntervalTask.java
@@ -0,0 +1,50 @@
+package org.taj.common.task;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.time.temporal.ChronoUnit.SECONDS;
+
+public abstract class IntervalTask extends TaskExecutor {
+ private long delaySecond;
+
+ public IntervalTask(String taskName, long second) {
+ super(taskName, second * 1000);
+ this.delaySecond = 0;
+ }
+
+ public IntervalTask(String taskName, long second, long delaySecond) {
+ super(taskName, second * 1000);
+ this.delaySecond = delaySecond * 1000;
+ }
+
+ public long getDelaySecond() {
+ return delaySecond;
+ }
+
+ @Override
+ public TaskType taskType() {
+ return TaskType.INTERVAL;
+ }
+
+ @Override
+ public void notifySuccess() {
+
+ }
+
+ @Override
+ public List computeFireTimesBetween(LocalDateTime from, LocalDateTime to) {
+ List lst = new ArrayList<>();
+ LocalDateTime ldt = getLastSuccessExecuteDateTime();
+ while(true) {
+ ldt = ldt.plus(getSecond(), SECONDS);
+ if(ldt.isAfter(from) && ldt.isBefore(to)) {
+ lst.add(ldt);
+ continue;
+ }
+ break;
+ }
+ return lst;
+ }
+}
diff --git a/common/src/main/java/org/taj/common/task/OnceTask.java b/common/src/main/java/org/taj/common/task/OnceTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..fa458bf50abd32ab0480056708d909bc78bbf3bb
--- /dev/null
+++ b/common/src/main/java/org/taj/common/task/OnceTask.java
@@ -0,0 +1,33 @@
+package org.taj.common.task;
+
+import java.time.LocalDateTime;
+import java.util.Collections;
+import java.util.List;
+
+public abstract class OnceTask extends TaskExecutor {
+ private long delaySecond;
+
+ public OnceTask(String taskName, long second) {
+ super(taskName, second * 1000);
+ this.delaySecond = second * 1000;
+ }
+
+ public long getDelaySecond() {
+ return delaySecond;
+ }
+
+ @Override
+ public TaskType taskType() {
+ return TaskType.ONCE;
+ }
+
+ @Override
+ public void notifySuccess() {
+ getTaskLauncher().removeTask(getTaskName());
+ }
+
+ @Override
+ public List computeFireTimesBetween(LocalDateTime from, LocalDateTime to) {
+ return Collections.emptyList();
+ }
+}
diff --git a/common/src/main/java/org/taj/common/task/TaskExecutor.java b/common/src/main/java/org/taj/common/task/TaskExecutor.java
new file mode 100644
index 0000000000000000000000000000000000000000..ad4e18ea7f180048606d180fc7b9ccde517b1c77
--- /dev/null
+++ b/common/src/main/java/org/taj/common/task/TaskExecutor.java
@@ -0,0 +1,97 @@
+package org.taj.common.task;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.concurrent.ScheduledFuture;
+
+public abstract class TaskExecutor implements Runnable {
+ private String taskName;
+ private long second;
+ private String cronExpression;
+ private int continuousFailureTimes;
+ private int continuousSuccessTimes;
+ private long elapsed;
+ private LocalDateTime lastSuccessExecuteDateTime;
+ private TaskLauncher taskLauncher;
+ private ScheduledFuture> future;
+
+ public enum TaskType {
+ DELAYED, INTERVAL, ONCE, CRON
+ }
+
+ public TaskExecutor(String taskName, long second) {
+ this.taskName = taskName;
+ this.second = second;
+ }
+
+ public TaskExecutor(String taskName, String cronExpression) {
+ this.taskName = taskName;
+ this.cronExpression = cronExpression;
+ }
+
+ @Override
+ public void run() {
+ try {
+ long start = System.currentTimeMillis();
+ execute(taskName, taskLauncher);
+ elapsed = System.currentTimeMillis() - start;
+ continuousFailureTimes = 0;
+ continuousSuccessTimes++;
+ notifySuccess();
+ lastSuccessExecuteDateTime = LocalDateTime.now();
+ } catch (Exception ex) {
+ continuousFailureTimes++;
+ continuousSuccessTimes = 0;
+ notifyFailure(taskName, continuousFailureTimes, taskLauncher, ex);
+ }
+ }
+
+ public abstract void execute(String taskName, TaskLauncher launcher) throws Exception;
+
+ public abstract void notifyFailure(String taskName, int consecutiveFailures, TaskLauncher launcher, Exception ex);
+
+ public abstract void notifySuccess();
+
+ abstract TaskType taskType();
+
+ public abstract List computeFireTimesBetween(LocalDateTime from, LocalDateTime to);
+
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ if (future != null) {
+ return future.cancel(mayInterruptIfRunning);
+ }
+ return false;
+ }
+
+ public long getSecond() {
+ return second;
+ }
+
+ public String getCronExpression() {
+ return cronExpression;
+ }
+
+ public String getTaskName() {
+ return taskName;
+ }
+
+ public void setFuture(ScheduledFuture> future) {
+ this.future = future;
+ }
+
+ protected void setTaskLauncher(TaskLauncher taskLauncher) {
+ this.taskLauncher = taskLauncher;
+ }
+
+ protected TaskLauncher getTaskLauncher() {
+ return this.taskLauncher;
+ }
+
+ public LocalDateTime getLastSuccessExecuteDateTime() {
+ return lastSuccessExecuteDateTime;
+ }
+
+ public long getElapsed() {
+ return elapsed;
+ }
+}
diff --git a/common/src/main/java/org/taj/common/task/TaskLauncher.java b/common/src/main/java/org/taj/common/task/TaskLauncher.java
new file mode 100644
index 0000000000000000000000000000000000000000..b524594e8672ab268e6df61361c460693501eb55
--- /dev/null
+++ b/common/src/main/java/org/taj/common/task/TaskLauncher.java
@@ -0,0 +1,67 @@
+package org.taj.common.task;
+
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.scheduling.support.CronTrigger;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ScheduledFuture;
+
+public class TaskLauncher {
+ private final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
+ private Map taskTable = new ConcurrentHashMap<>();
+
+ public TaskLauncher(int poolSize) {
+ scheduler.setThreadNamePrefix("task-");
+ scheduler.setPoolSize(poolSize);
+ scheduler.setRemoveOnCancelPolicy(true);
+ scheduler.setWaitForTasksToCompleteOnShutdown(true);
+ scheduler.setAwaitTerminationSeconds(60);
+ scheduler.initialize();
+ }
+
+ public void addTask(TaskExecutor task) {
+ task.setTaskLauncher(this);
+ if (task.taskType() == TaskExecutor.TaskType.INTERVAL) {
+ Date startTime = new Date(System.currentTimeMillis() + ((IntervalTask) task).getDelaySecond());
+ ScheduledFuture> scheduledFuture = scheduler.scheduleAtFixedRate(task, startTime, task.getSecond());
+ task.setFuture(scheduledFuture);
+ }
+ if (task.taskType() == TaskExecutor.TaskType.DELAYED) {
+ Date startTime = new Date(System.currentTimeMillis() + ((DelayedTask) task).getDelaySecond());
+ ScheduledFuture> scheduledFuture = scheduler.scheduleWithFixedDelay(task, startTime, task.getSecond());
+ task.setFuture(scheduledFuture);
+ }
+ if (task.taskType() == TaskExecutor.TaskType.ONCE) {
+ Date startTime = new Date(System.currentTimeMillis() + ((OnceTask) task).getDelaySecond());
+ ScheduledFuture> scheduledFuture = scheduler.scheduleAtFixedRate(task, startTime, task.getSecond());
+ task.setFuture(scheduledFuture);
+ }
+ if (task.taskType() == TaskExecutor.TaskType.CRON) {
+ ScheduledFuture> scheduledFuture = scheduler.schedule(task, new CronTrigger(task.getCronExpression()));
+ task.setFuture(scheduledFuture);
+ }
+ taskTable.put(task.getTaskName(), task);
+ }
+
+ public boolean removeTask(String taskName) {
+ TaskExecutor taskExecutor = taskTable.remove(taskName);
+ if (taskExecutor == null) {
+ return false;
+ }
+ if (taskExecutor.cancel(false)) {
+ return scheduler.getScheduledThreadPoolExecutor().remove(taskExecutor);
+ }
+ return false;
+ }
+
+ public Set taskNames() {
+ return taskTable.keySet();
+ }
+
+ public TaskExecutor getTaskExecutor(String taskName) {
+ return taskTable.get(taskName);
+ }
+}
diff --git a/common/src/main/java/org/taj/common/tcp/Message.java b/common/src/main/java/org/taj/common/tcp/Message.java
new file mode 100644
index 0000000000000000000000000000000000000000..c02b8c3afb0b6f5a47b3847d60929aa3a71e251a
--- /dev/null
+++ b/common/src/main/java/org/taj/common/tcp/Message.java
@@ -0,0 +1,2309 @@
+package org.taj.common.tcp;// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: message.proto
+
+public final class Message {
+ private Message() {}
+ public static void registerAllExtensions(
+ com.google.protobuf.ExtensionRegistryLite registry) {
+ }
+
+ public static void registerAllExtensions(
+ com.google.protobuf.ExtensionRegistry registry) {
+ registerAllExtensions(
+ (com.google.protobuf.ExtensionRegistryLite) registry);
+ }
+ public interface ErrorOrBuilder extends
+ // @@protoc_insertion_point(interface_extends:Error)
+ com.google.protobuf.MessageOrBuilder {
+
+ /**
+ * uint32 code = 1;
+ * @return The code.
+ */
+ int getCode();
+
+ /**
+ * string msg = 2;
+ * @return The msg.
+ */
+ String getMsg();
+ /**
+ * string msg = 2;
+ * @return The bytes for msg.
+ */
+ com.google.protobuf.ByteString
+ getMsgBytes();
+ }
+ /**
+ * Protobuf type {@code Error}
+ */
+ public static final class Error extends
+ com.google.protobuf.GeneratedMessageV3 implements
+ // @@protoc_insertion_point(message_implements:Error)
+ ErrorOrBuilder {
+ private static final long serialVersionUID = 0L;
+ // Use Error.newBuilder() to construct.
+ private Error(com.google.protobuf.GeneratedMessageV3.Builder> builder) {
+ super(builder);
+ }
+ private Error() {
+ msg_ = "";
+ }
+
+ @Override
+ @SuppressWarnings({"unused"})
+ protected Object newInstance(
+ UnusedPrivateParameter unused) {
+ return new Error();
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return Message.internal_static_Error_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return Message.internal_static_Error_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ Error.class, Builder.class);
+ }
+
+ public static final int CODE_FIELD_NUMBER = 1;
+ private int code_ = 0;
+ /**
+ * uint32 code = 1;
+ * @return The code.
+ */
+ @Override
+ public int getCode() {
+ return code_;
+ }
+
+ public static final int MSG_FIELD_NUMBER = 2;
+ @SuppressWarnings("serial")
+ private volatile Object msg_ = "";
+ /**
+ * string msg = 2;
+ * @return The msg.
+ */
+ @Override
+ public String getMsg() {
+ Object ref = msg_;
+ if (ref instanceof String) {
+ return (String) ref;
+ } else {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ String s = bs.toStringUtf8();
+ msg_ = s;
+ return s;
+ }
+ }
+ /**
+ * string msg = 2;
+ * @return The bytes for msg.
+ */
+ @Override
+ public com.google.protobuf.ByteString
+ getMsgBytes() {
+ Object ref = msg_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (String) ref);
+ msg_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
+ private byte memoizedIsInitialized = -1;
+ @Override
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized == 1) return true;
+ if (isInitialized == 0) return false;
+
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ @Override
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ if (code_ != 0) {
+ output.writeUInt32(1, code_);
+ }
+ if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msg_)) {
+ com.google.protobuf.GeneratedMessageV3.writeString(output, 2, msg_);
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (code_ != 0) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeUInt32Size(1, code_);
+ }
+ if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msg_)) {
+ size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, msg_);
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSize = size;
+ return size;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof Error)) {
+ return super.equals(obj);
+ }
+ Error other = (Error) obj;
+
+ if (getCode()
+ != other.getCode()) return false;
+ if (!getMsg()
+ .equals(other.getMsg())) return false;
+ if (!getUnknownFields().equals(other.getUnknownFields())) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ if (memoizedHashCode != 0) {
+ return memoizedHashCode;
+ }
+ int hash = 41;
+ hash = (19 * hash) + getDescriptor().hashCode();
+ hash = (37 * hash) + CODE_FIELD_NUMBER;
+ hash = (53 * hash) + getCode();
+ hash = (37 * hash) + MSG_FIELD_NUMBER;
+ hash = (53 * hash) + getMsg().hashCode();
+ hash = (29 * hash) + getUnknownFields().hashCode();
+ memoizedHashCode = hash;
+ return hash;
+ }
+
+ public static Error parseFrom(
+ java.nio.ByteBuffer data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Error parseFrom(
+ java.nio.ByteBuffer data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Error parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Error parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Error parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Error parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Error parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input);
+ }
+ public static Error parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input, extensionRegistry);
+ }
+
+ public static Error parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseDelimitedWithIOException(PARSER, input);
+ }
+
+ public static Error parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
+ }
+ public static Error parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input);
+ }
+ public static Error parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input, extensionRegistry);
+ }
+
+ @Override
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder() {
+ return DEFAULT_INSTANCE.toBuilder();
+ }
+ public static Builder newBuilder(Error prototype) {
+ return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
+ }
+ @Override
+ public Builder toBuilder() {
+ return this == DEFAULT_INSTANCE
+ ? new Builder() : new Builder().mergeFrom(this);
+ }
+
+ @Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code Error}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessageV3.Builder implements
+ // @@protoc_insertion_point(builder_implements:Error)
+ ErrorOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return Message.internal_static_Error_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return Message.internal_static_Error_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ Error.class, Builder.class);
+ }
+
+ // Construct using Message.Error.newBuilder()
+ private Builder() {
+
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
+ super(parent);
+
+ }
+ @Override
+ public Builder clear() {
+ super.clear();
+ bitField0_ = 0;
+ code_ = 0;
+ msg_ = "";
+ return this;
+ }
+
+ @Override
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return Message.internal_static_Error_descriptor;
+ }
+
+ @Override
+ public Error getDefaultInstanceForType() {
+ return Error.getDefaultInstance();
+ }
+
+ @Override
+ public Error build() {
+ Error result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ @Override
+ public Error buildPartial() {
+ Error result = new Error(this);
+ if (bitField0_ != 0) { buildPartial0(result); }
+ onBuilt();
+ return result;
+ }
+
+ private void buildPartial0(Error result) {
+ int from_bitField0_ = bitField0_;
+ if (((from_bitField0_ & 0x00000001) != 0)) {
+ result.code_ = code_;
+ }
+ if (((from_bitField0_ & 0x00000002) != 0)) {
+ result.msg_ = msg_;
+ }
+ }
+
+ @Override
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof Error) {
+ return mergeFrom((Error)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(Error other) {
+ if (other == Error.getDefaultInstance()) return this;
+ if (other.getCode() != 0) {
+ setCode(other.getCode());
+ }
+ if (!other.getMsg().isEmpty()) {
+ msg_ = other.msg_;
+ bitField0_ |= 0x00000002;
+ onChanged();
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ onChanged();
+ return this;
+ }
+
+ @Override
+ public final boolean isInitialized() {
+ return true;
+ }
+
+ @Override
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ if (extensionRegistry == null) {
+ throw new NullPointerException();
+ }
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ case 8: {
+ code_ = input.readUInt32();
+ bitField0_ |= 0x00000001;
+ break;
+ } // case 8
+ case 18: {
+ msg_ = input.readStringRequireUtf8();
+ bitField0_ |= 0x00000002;
+ break;
+ } // case 18
+ default: {
+ if (!super.parseUnknownField(input, extensionRegistry, tag)) {
+ done = true; // was an endgroup tag
+ }
+ break;
+ } // default:
+ } // switch (tag)
+ } // while (!done)
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ } finally {
+ onChanged();
+ } // finally
+ return this;
+ }
+ private int bitField0_;
+
+ private int code_ ;
+ /**
+ * uint32 code = 1;
+ * @return The code.
+ */
+ @Override
+ public int getCode() {
+ return code_;
+ }
+ /**
+ * uint32 code = 1;
+ * @param value The code to set.
+ * @return This builder for chaining.
+ */
+ public Builder setCode(int value) {
+
+ code_ = value;
+ bitField0_ |= 0x00000001;
+ onChanged();
+ return this;
+ }
+ /**
+ * uint32 code = 1;
+ * @return This builder for chaining.
+ */
+ public Builder clearCode() {
+ bitField0_ = (bitField0_ & ~0x00000001);
+ code_ = 0;
+ onChanged();
+ return this;
+ }
+
+ private Object msg_ = "";
+ /**
+ * string msg = 2;
+ * @return The msg.
+ */
+ public String getMsg() {
+ Object ref = msg_;
+ if (!(ref instanceof String)) {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ String s = bs.toStringUtf8();
+ msg_ = s;
+ return s;
+ } else {
+ return (String) ref;
+ }
+ }
+ /**
+ * string msg = 2;
+ * @return The bytes for msg.
+ */
+ public com.google.protobuf.ByteString
+ getMsgBytes() {
+ Object ref = msg_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (String) ref);
+ msg_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+ /**
+ * string msg = 2;
+ * @param value The msg to set.
+ * @return This builder for chaining.
+ */
+ public Builder setMsg(
+ String value) {
+ if (value == null) { throw new NullPointerException(); }
+ msg_ = value;
+ bitField0_ |= 0x00000002;
+ onChanged();
+ return this;
+ }
+ /**
+ * string msg = 2;
+ * @return This builder for chaining.
+ */
+ public Builder clearMsg() {
+ msg_ = getDefaultInstance().getMsg();
+ bitField0_ = (bitField0_ & ~0x00000002);
+ onChanged();
+ return this;
+ }
+ /**
+ * string msg = 2;
+ * @param value The bytes for msg to set.
+ * @return This builder for chaining.
+ */
+ public Builder setMsgBytes(
+ com.google.protobuf.ByteString value) {
+ if (value == null) { throw new NullPointerException(); }
+ checkByteStringIsUtf8(value);
+ msg_ = value;
+ bitField0_ |= 0x00000002;
+ onChanged();
+ return this;
+ }
+ @Override
+ public final Builder setUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return super.setUnknownFields(unknownFields);
+ }
+
+ @Override
+ public final Builder mergeUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return super.mergeUnknownFields(unknownFields);
+ }
+
+
+ // @@protoc_insertion_point(builder_scope:Error)
+ }
+
+ // @@protoc_insertion_point(class_scope:Error)
+ private static final Error DEFAULT_INSTANCE;
+ static {
+ DEFAULT_INSTANCE = new Error();
+ }
+
+ public static Error getDefaultInstance() {
+ return DEFAULT_INSTANCE;
+ }
+
+ private static final com.google.protobuf.Parser
+ PARSER = new com.google.protobuf.AbstractParser() {
+ @Override
+ public Error parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ Builder builder = newBuilder();
+ try {
+ builder.mergeFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(builder.buildPartial());
+ } catch (com.google.protobuf.UninitializedMessageException e) {
+ throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(e)
+ .setUnfinishedMessage(builder.buildPartial());
+ }
+ return builder.buildPartial();
+ }
+ };
+
+ public static com.google.protobuf.Parser parser() {
+ return PARSER;
+ }
+
+ @Override
+ public com.google.protobuf.Parser getParserForType() {
+ return PARSER;
+ }
+
+ @Override
+ public Error getDefaultInstanceForType() {
+ return DEFAULT_INSTANCE;
+ }
+
+ }
+
+ public interface HeaderOrBuilder extends
+ // @@protoc_insertion_point(interface_extends:Header)
+ com.google.protobuf.MessageOrBuilder {
+
+ /**
+ * uint32 code = 1;
+ * @return The code.
+ */
+ int getCode();
+
+ /**
+ * bytes buf0 = 2;
+ * @return The buf0.
+ */
+ com.google.protobuf.ByteString getBuf0();
+
+ /**
+ * bytes buf1 = 3;
+ * @return The buf1.
+ */
+ com.google.protobuf.ByteString getBuf1();
+
+ /**
+ * bytes buf2 = 4;
+ * @return The buf2.
+ */
+ com.google.protobuf.ByteString getBuf2();
+
+ /**
+ * bytes buf3 = 5;
+ * @return The buf3.
+ */
+ com.google.protobuf.ByteString getBuf3();
+
+ /**
+ * bytes buf4 = 6;
+ * @return The buf4.
+ */
+ com.google.protobuf.ByteString getBuf4();
+ }
+ /**
+ * Protobuf type {@code Header}
+ */
+ public static final class Header extends
+ com.google.protobuf.GeneratedMessageV3 implements
+ // @@protoc_insertion_point(message_implements:Header)
+ HeaderOrBuilder {
+ private static final long serialVersionUID = 0L;
+ // Use Header.newBuilder() to construct.
+ private Header(com.google.protobuf.GeneratedMessageV3.Builder> builder) {
+ super(builder);
+ }
+ private Header() {
+ buf0_ = com.google.protobuf.ByteString.EMPTY;
+ buf1_ = com.google.protobuf.ByteString.EMPTY;
+ buf2_ = com.google.protobuf.ByteString.EMPTY;
+ buf3_ = com.google.protobuf.ByteString.EMPTY;
+ buf4_ = com.google.protobuf.ByteString.EMPTY;
+ }
+
+ @Override
+ @SuppressWarnings({"unused"})
+ protected Object newInstance(
+ UnusedPrivateParameter unused) {
+ return new Header();
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return Message.internal_static_Header_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return Message.internal_static_Header_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ Header.class, Builder.class);
+ }
+
+ public static final int CODE_FIELD_NUMBER = 1;
+ private int code_ = 0;
+ /**
+ * uint32 code = 1;
+ * @return The code.
+ */
+ @Override
+ public int getCode() {
+ return code_;
+ }
+
+ public static final int BUF0_FIELD_NUMBER = 2;
+ private com.google.protobuf.ByteString buf0_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf0 = 2;
+ * @return The buf0.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf0() {
+ return buf0_;
+ }
+
+ public static final int BUF1_FIELD_NUMBER = 3;
+ private com.google.protobuf.ByteString buf1_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf1 = 3;
+ * @return The buf1.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf1() {
+ return buf1_;
+ }
+
+ public static final int BUF2_FIELD_NUMBER = 4;
+ private com.google.protobuf.ByteString buf2_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf2 = 4;
+ * @return The buf2.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf2() {
+ return buf2_;
+ }
+
+ public static final int BUF3_FIELD_NUMBER = 5;
+ private com.google.protobuf.ByteString buf3_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf3 = 5;
+ * @return The buf3.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf3() {
+ return buf3_;
+ }
+
+ public static final int BUF4_FIELD_NUMBER = 6;
+ private com.google.protobuf.ByteString buf4_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf4 = 6;
+ * @return The buf4.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf4() {
+ return buf4_;
+ }
+
+ private byte memoizedIsInitialized = -1;
+ @Override
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized == 1) return true;
+ if (isInitialized == 0) return false;
+
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ @Override
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ if (code_ != 0) {
+ output.writeUInt32(1, code_);
+ }
+ if (!buf0_.isEmpty()) {
+ output.writeBytes(2, buf0_);
+ }
+ if (!buf1_.isEmpty()) {
+ output.writeBytes(3, buf1_);
+ }
+ if (!buf2_.isEmpty()) {
+ output.writeBytes(4, buf2_);
+ }
+ if (!buf3_.isEmpty()) {
+ output.writeBytes(5, buf3_);
+ }
+ if (!buf4_.isEmpty()) {
+ output.writeBytes(6, buf4_);
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (code_ != 0) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeUInt32Size(1, code_);
+ }
+ if (!buf0_.isEmpty()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(2, buf0_);
+ }
+ if (!buf1_.isEmpty()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(3, buf1_);
+ }
+ if (!buf2_.isEmpty()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(4, buf2_);
+ }
+ if (!buf3_.isEmpty()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(5, buf3_);
+ }
+ if (!buf4_.isEmpty()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(6, buf4_);
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSize = size;
+ return size;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof Header)) {
+ return super.equals(obj);
+ }
+ Header other = (Header) obj;
+
+ if (getCode()
+ != other.getCode()) return false;
+ if (!getBuf0()
+ .equals(other.getBuf0())) return false;
+ if (!getBuf1()
+ .equals(other.getBuf1())) return false;
+ if (!getBuf2()
+ .equals(other.getBuf2())) return false;
+ if (!getBuf3()
+ .equals(other.getBuf3())) return false;
+ if (!getBuf4()
+ .equals(other.getBuf4())) return false;
+ if (!getUnknownFields().equals(other.getUnknownFields())) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ if (memoizedHashCode != 0) {
+ return memoizedHashCode;
+ }
+ int hash = 41;
+ hash = (19 * hash) + getDescriptor().hashCode();
+ hash = (37 * hash) + CODE_FIELD_NUMBER;
+ hash = (53 * hash) + getCode();
+ hash = (37 * hash) + BUF0_FIELD_NUMBER;
+ hash = (53 * hash) + getBuf0().hashCode();
+ hash = (37 * hash) + BUF1_FIELD_NUMBER;
+ hash = (53 * hash) + getBuf1().hashCode();
+ hash = (37 * hash) + BUF2_FIELD_NUMBER;
+ hash = (53 * hash) + getBuf2().hashCode();
+ hash = (37 * hash) + BUF3_FIELD_NUMBER;
+ hash = (53 * hash) + getBuf3().hashCode();
+ hash = (37 * hash) + BUF4_FIELD_NUMBER;
+ hash = (53 * hash) + getBuf4().hashCode();
+ hash = (29 * hash) + getUnknownFields().hashCode();
+ memoizedHashCode = hash;
+ return hash;
+ }
+
+ public static Header parseFrom(
+ java.nio.ByteBuffer data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Header parseFrom(
+ java.nio.ByteBuffer data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Header parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Header parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Header parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Header parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Header parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input);
+ }
+ public static Header parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input, extensionRegistry);
+ }
+
+ public static Header parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseDelimitedWithIOException(PARSER, input);
+ }
+
+ public static Header parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
+ }
+ public static Header parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input);
+ }
+ public static Header parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input, extensionRegistry);
+ }
+
+ @Override
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder() {
+ return DEFAULT_INSTANCE.toBuilder();
+ }
+ public static Builder newBuilder(Header prototype) {
+ return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
+ }
+ @Override
+ public Builder toBuilder() {
+ return this == DEFAULT_INSTANCE
+ ? new Builder() : new Builder().mergeFrom(this);
+ }
+
+ @Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code Header}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessageV3.Builder implements
+ // @@protoc_insertion_point(builder_implements:Header)
+ HeaderOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return Message.internal_static_Header_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return Message.internal_static_Header_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ Header.class, Builder.class);
+ }
+
+ // Construct using Message.Header.newBuilder()
+ private Builder() {
+
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
+ super(parent);
+
+ }
+ @Override
+ public Builder clear() {
+ super.clear();
+ bitField0_ = 0;
+ code_ = 0;
+ buf0_ = com.google.protobuf.ByteString.EMPTY;
+ buf1_ = com.google.protobuf.ByteString.EMPTY;
+ buf2_ = com.google.protobuf.ByteString.EMPTY;
+ buf3_ = com.google.protobuf.ByteString.EMPTY;
+ buf4_ = com.google.protobuf.ByteString.EMPTY;
+ return this;
+ }
+
+ @Override
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return Message.internal_static_Header_descriptor;
+ }
+
+ @Override
+ public Header getDefaultInstanceForType() {
+ return Header.getDefaultInstance();
+ }
+
+ @Override
+ public Header build() {
+ Header result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ @Override
+ public Header buildPartial() {
+ Header result = new Header(this);
+ if (bitField0_ != 0) { buildPartial0(result); }
+ onBuilt();
+ return result;
+ }
+
+ private void buildPartial0(Header result) {
+ int from_bitField0_ = bitField0_;
+ if (((from_bitField0_ & 0x00000001) != 0)) {
+ result.code_ = code_;
+ }
+ if (((from_bitField0_ & 0x00000002) != 0)) {
+ result.buf0_ = buf0_;
+ }
+ if (((from_bitField0_ & 0x00000004) != 0)) {
+ result.buf1_ = buf1_;
+ }
+ if (((from_bitField0_ & 0x00000008) != 0)) {
+ result.buf2_ = buf2_;
+ }
+ if (((from_bitField0_ & 0x00000010) != 0)) {
+ result.buf3_ = buf3_;
+ }
+ if (((from_bitField0_ & 0x00000020) != 0)) {
+ result.buf4_ = buf4_;
+ }
+ }
+
+ @Override
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof Header) {
+ return mergeFrom((Header)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(Header other) {
+ if (other == Header.getDefaultInstance()) return this;
+ if (other.getCode() != 0) {
+ setCode(other.getCode());
+ }
+ if (other.getBuf0() != com.google.protobuf.ByteString.EMPTY) {
+ setBuf0(other.getBuf0());
+ }
+ if (other.getBuf1() != com.google.protobuf.ByteString.EMPTY) {
+ setBuf1(other.getBuf1());
+ }
+ if (other.getBuf2() != com.google.protobuf.ByteString.EMPTY) {
+ setBuf2(other.getBuf2());
+ }
+ if (other.getBuf3() != com.google.protobuf.ByteString.EMPTY) {
+ setBuf3(other.getBuf3());
+ }
+ if (other.getBuf4() != com.google.protobuf.ByteString.EMPTY) {
+ setBuf4(other.getBuf4());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ onChanged();
+ return this;
+ }
+
+ @Override
+ public final boolean isInitialized() {
+ return true;
+ }
+
+ @Override
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ if (extensionRegistry == null) {
+ throw new NullPointerException();
+ }
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ case 8: {
+ code_ = input.readUInt32();
+ bitField0_ |= 0x00000001;
+ break;
+ } // case 8
+ case 18: {
+ buf0_ = input.readBytes();
+ bitField0_ |= 0x00000002;
+ break;
+ } // case 18
+ case 26: {
+ buf1_ = input.readBytes();
+ bitField0_ |= 0x00000004;
+ break;
+ } // case 26
+ case 34: {
+ buf2_ = input.readBytes();
+ bitField0_ |= 0x00000008;
+ break;
+ } // case 34
+ case 42: {
+ buf3_ = input.readBytes();
+ bitField0_ |= 0x00000010;
+ break;
+ } // case 42
+ case 50: {
+ buf4_ = input.readBytes();
+ bitField0_ |= 0x00000020;
+ break;
+ } // case 50
+ default: {
+ if (!super.parseUnknownField(input, extensionRegistry, tag)) {
+ done = true; // was an endgroup tag
+ }
+ break;
+ } // default:
+ } // switch (tag)
+ } // while (!done)
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ } finally {
+ onChanged();
+ } // finally
+ return this;
+ }
+ private int bitField0_;
+
+ private int code_ ;
+ /**
+ * uint32 code = 1;
+ * @return The code.
+ */
+ @Override
+ public int getCode() {
+ return code_;
+ }
+ /**
+ * uint32 code = 1;
+ * @param value The code to set.
+ * @return This builder for chaining.
+ */
+ public Builder setCode(int value) {
+
+ code_ = value;
+ bitField0_ |= 0x00000001;
+ onChanged();
+ return this;
+ }
+ /**
+ * uint32 code = 1;
+ * @return This builder for chaining.
+ */
+ public Builder clearCode() {
+ bitField0_ = (bitField0_ & ~0x00000001);
+ code_ = 0;
+ onChanged();
+ return this;
+ }
+
+ private com.google.protobuf.ByteString buf0_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf0 = 2;
+ * @return The buf0.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf0() {
+ return buf0_;
+ }
+ /**
+ * bytes buf0 = 2;
+ * @param value The buf0 to set.
+ * @return This builder for chaining.
+ */
+ public Builder setBuf0(com.google.protobuf.ByteString value) {
+ if (value == null) { throw new NullPointerException(); }
+ buf0_ = value;
+ bitField0_ |= 0x00000002;
+ onChanged();
+ return this;
+ }
+ /**
+ * bytes buf0 = 2;
+ * @return This builder for chaining.
+ */
+ public Builder clearBuf0() {
+ bitField0_ = (bitField0_ & ~0x00000002);
+ buf0_ = getDefaultInstance().getBuf0();
+ onChanged();
+ return this;
+ }
+
+ private com.google.protobuf.ByteString buf1_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf1 = 3;
+ * @return The buf1.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf1() {
+ return buf1_;
+ }
+ /**
+ * bytes buf1 = 3;
+ * @param value The buf1 to set.
+ * @return This builder for chaining.
+ */
+ public Builder setBuf1(com.google.protobuf.ByteString value) {
+ if (value == null) { throw new NullPointerException(); }
+ buf1_ = value;
+ bitField0_ |= 0x00000004;
+ onChanged();
+ return this;
+ }
+ /**
+ * bytes buf1 = 3;
+ * @return This builder for chaining.
+ */
+ public Builder clearBuf1() {
+ bitField0_ = (bitField0_ & ~0x00000004);
+ buf1_ = getDefaultInstance().getBuf1();
+ onChanged();
+ return this;
+ }
+
+ private com.google.protobuf.ByteString buf2_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf2 = 4;
+ * @return The buf2.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf2() {
+ return buf2_;
+ }
+ /**
+ * bytes buf2 = 4;
+ * @param value The buf2 to set.
+ * @return This builder for chaining.
+ */
+ public Builder setBuf2(com.google.protobuf.ByteString value) {
+ if (value == null) { throw new NullPointerException(); }
+ buf2_ = value;
+ bitField0_ |= 0x00000008;
+ onChanged();
+ return this;
+ }
+ /**
+ * bytes buf2 = 4;
+ * @return This builder for chaining.
+ */
+ public Builder clearBuf2() {
+ bitField0_ = (bitField0_ & ~0x00000008);
+ buf2_ = getDefaultInstance().getBuf2();
+ onChanged();
+ return this;
+ }
+
+ private com.google.protobuf.ByteString buf3_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf3 = 5;
+ * @return The buf3.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf3() {
+ return buf3_;
+ }
+ /**
+ * bytes buf3 = 5;
+ * @param value The buf3 to set.
+ * @return This builder for chaining.
+ */
+ public Builder setBuf3(com.google.protobuf.ByteString value) {
+ if (value == null) { throw new NullPointerException(); }
+ buf3_ = value;
+ bitField0_ |= 0x00000010;
+ onChanged();
+ return this;
+ }
+ /**
+ * bytes buf3 = 5;
+ * @return This builder for chaining.
+ */
+ public Builder clearBuf3() {
+ bitField0_ = (bitField0_ & ~0x00000010);
+ buf3_ = getDefaultInstance().getBuf3();
+ onChanged();
+ return this;
+ }
+
+ private com.google.protobuf.ByteString buf4_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes buf4 = 6;
+ * @return The buf4.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBuf4() {
+ return buf4_;
+ }
+ /**
+ * bytes buf4 = 6;
+ * @param value The buf4 to set.
+ * @return This builder for chaining.
+ */
+ public Builder setBuf4(com.google.protobuf.ByteString value) {
+ if (value == null) { throw new NullPointerException(); }
+ buf4_ = value;
+ bitField0_ |= 0x00000020;
+ onChanged();
+ return this;
+ }
+ /**
+ * bytes buf4 = 6;
+ * @return This builder for chaining.
+ */
+ public Builder clearBuf4() {
+ bitField0_ = (bitField0_ & ~0x00000020);
+ buf4_ = getDefaultInstance().getBuf4();
+ onChanged();
+ return this;
+ }
+ @Override
+ public final Builder setUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return super.setUnknownFields(unknownFields);
+ }
+
+ @Override
+ public final Builder mergeUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return super.mergeUnknownFields(unknownFields);
+ }
+
+
+ // @@protoc_insertion_point(builder_scope:Header)
+ }
+
+ // @@protoc_insertion_point(class_scope:Header)
+ private static final Header DEFAULT_INSTANCE;
+ static {
+ DEFAULT_INSTANCE = new Header();
+ }
+
+ public static Header getDefaultInstance() {
+ return DEFAULT_INSTANCE;
+ }
+
+ private static final com.google.protobuf.Parser
+ PARSER = new com.google.protobuf.AbstractParser() {
+ @Override
+ public Header parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ Builder builder = newBuilder();
+ try {
+ builder.mergeFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(builder.buildPartial());
+ } catch (com.google.protobuf.UninitializedMessageException e) {
+ throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(e)
+ .setUnfinishedMessage(builder.buildPartial());
+ }
+ return builder.buildPartial();
+ }
+ };
+
+ public static com.google.protobuf.Parser parser() {
+ return PARSER;
+ }
+
+ @Override
+ public com.google.protobuf.Parser getParserForType() {
+ return PARSER;
+ }
+
+ @Override
+ public Header getDefaultInstanceForType() {
+ return DEFAULT_INSTANCE;
+ }
+
+ }
+
+ public interface MessengerOrBuilder extends
+ // @@protoc_insertion_point(interface_extends:Messenger)
+ com.google.protobuf.MessageOrBuilder {
+
+ /**
+ * .Header header = 1;
+ * @return Whether the header field is set.
+ */
+ boolean hasHeader();
+ /**
+ * .Header header = 1;
+ * @return The header.
+ */
+ Header getHeader();
+ /**
+ * .Header header = 1;
+ */
+ HeaderOrBuilder getHeaderOrBuilder();
+
+ /**
+ * .Error error = 2;
+ * @return Whether the error field is set.
+ */
+ boolean hasError();
+ /**
+ * .Error error = 2;
+ * @return The error.
+ */
+ Error getError();
+ /**
+ * .Error error = 2;
+ */
+ ErrorOrBuilder getErrorOrBuilder();
+
+ /**
+ * bytes body = 3;
+ * @return The body.
+ */
+ com.google.protobuf.ByteString getBody();
+ }
+ /**
+ * Protobuf type {@code Messenger}
+ */
+ public static final class Messenger extends
+ com.google.protobuf.GeneratedMessageV3 implements
+ // @@protoc_insertion_point(message_implements:Messenger)
+ MessengerOrBuilder {
+ private static final long serialVersionUID = 0L;
+ // Use Messenger.newBuilder() to construct.
+ private Messenger(com.google.protobuf.GeneratedMessageV3.Builder> builder) {
+ super(builder);
+ }
+ private Messenger() {
+ body_ = com.google.protobuf.ByteString.EMPTY;
+ }
+
+ @Override
+ @SuppressWarnings({"unused"})
+ protected Object newInstance(
+ UnusedPrivateParameter unused) {
+ return new Messenger();
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return Message.internal_static_Messenger_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return Message.internal_static_Messenger_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ Messenger.class, Builder.class);
+ }
+
+ public static final int HEADER_FIELD_NUMBER = 1;
+ private Header header_;
+ /**
+ * .Header header = 1;
+ * @return Whether the header field is set.
+ */
+ @Override
+ public boolean hasHeader() {
+ return header_ != null;
+ }
+ /**
+ * .Header header = 1;
+ * @return The header.
+ */
+ @Override
+ public Header getHeader() {
+ return header_ == null ? Header.getDefaultInstance() : header_;
+ }
+ /**
+ * .Header header = 1;
+ */
+ @Override
+ public HeaderOrBuilder getHeaderOrBuilder() {
+ return header_ == null ? Header.getDefaultInstance() : header_;
+ }
+
+ public static final int ERROR_FIELD_NUMBER = 2;
+ private Error error_;
+ /**
+ * .Error error = 2;
+ * @return Whether the error field is set.
+ */
+ @Override
+ public boolean hasError() {
+ return error_ != null;
+ }
+ /**
+ * .Error error = 2;
+ * @return The error.
+ */
+ @Override
+ public Error getError() {
+ return error_ == null ? Error.getDefaultInstance() : error_;
+ }
+ /**
+ * .Error error = 2;
+ */
+ @Override
+ public ErrorOrBuilder getErrorOrBuilder() {
+ return error_ == null ? Error.getDefaultInstance() : error_;
+ }
+
+ public static final int BODY_FIELD_NUMBER = 3;
+ private com.google.protobuf.ByteString body_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes body = 3;
+ * @return The body.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBody() {
+ return body_;
+ }
+
+ private byte memoizedIsInitialized = -1;
+ @Override
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized == 1) return true;
+ if (isInitialized == 0) return false;
+
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ @Override
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ if (header_ != null) {
+ output.writeMessage(1, getHeader());
+ }
+ if (error_ != null) {
+ output.writeMessage(2, getError());
+ }
+ if (!body_.isEmpty()) {
+ output.writeBytes(3, body_);
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (header_ != null) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(1, getHeader());
+ }
+ if (error_ != null) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(2, getError());
+ }
+ if (!body_.isEmpty()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(3, body_);
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSize = size;
+ return size;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof Messenger)) {
+ return super.equals(obj);
+ }
+ Messenger other = (Messenger) obj;
+
+ if (hasHeader() != other.hasHeader()) return false;
+ if (hasHeader()) {
+ if (!getHeader()
+ .equals(other.getHeader())) return false;
+ }
+ if (hasError() != other.hasError()) return false;
+ if (hasError()) {
+ if (!getError()
+ .equals(other.getError())) return false;
+ }
+ if (!getBody()
+ .equals(other.getBody())) return false;
+ if (!getUnknownFields().equals(other.getUnknownFields())) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ if (memoizedHashCode != 0) {
+ return memoizedHashCode;
+ }
+ int hash = 41;
+ hash = (19 * hash) + getDescriptor().hashCode();
+ if (hasHeader()) {
+ hash = (37 * hash) + HEADER_FIELD_NUMBER;
+ hash = (53 * hash) + getHeader().hashCode();
+ }
+ if (hasError()) {
+ hash = (37 * hash) + ERROR_FIELD_NUMBER;
+ hash = (53 * hash) + getError().hashCode();
+ }
+ hash = (37 * hash) + BODY_FIELD_NUMBER;
+ hash = (53 * hash) + getBody().hashCode();
+ hash = (29 * hash) + getUnknownFields().hashCode();
+ memoizedHashCode = hash;
+ return hash;
+ }
+
+ public static Messenger parseFrom(
+ java.nio.ByteBuffer data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Messenger parseFrom(
+ java.nio.ByteBuffer data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Messenger parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Messenger parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Messenger parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static Messenger parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static Messenger parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input);
+ }
+ public static Messenger parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input, extensionRegistry);
+ }
+
+ public static Messenger parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseDelimitedWithIOException(PARSER, input);
+ }
+
+ public static Messenger parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
+ }
+ public static Messenger parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input);
+ }
+ public static Messenger parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3
+ .parseWithIOException(PARSER, input, extensionRegistry);
+ }
+
+ @Override
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder() {
+ return DEFAULT_INSTANCE.toBuilder();
+ }
+ public static Builder newBuilder(Messenger prototype) {
+ return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
+ }
+ @Override
+ public Builder toBuilder() {
+ return this == DEFAULT_INSTANCE
+ ? new Builder() : new Builder().mergeFrom(this);
+ }
+
+ @Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code Messenger}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessageV3.Builder implements
+ // @@protoc_insertion_point(builder_implements:Messenger)
+ MessengerOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return Message.internal_static_Messenger_descriptor;
+ }
+
+ @Override
+ protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return Message.internal_static_Messenger_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ Messenger.class, Builder.class);
+ }
+
+ // Construct using Message.Messenger.newBuilder()
+ private Builder() {
+
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
+ super(parent);
+
+ }
+ @Override
+ public Builder clear() {
+ super.clear();
+ bitField0_ = 0;
+ header_ = null;
+ if (headerBuilder_ != null) {
+ headerBuilder_.dispose();
+ headerBuilder_ = null;
+ }
+ error_ = null;
+ if (errorBuilder_ != null) {
+ errorBuilder_.dispose();
+ errorBuilder_ = null;
+ }
+ body_ = com.google.protobuf.ByteString.EMPTY;
+ return this;
+ }
+
+ @Override
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return Message.internal_static_Messenger_descriptor;
+ }
+
+ @Override
+ public Messenger getDefaultInstanceForType() {
+ return Messenger.getDefaultInstance();
+ }
+
+ @Override
+ public Messenger build() {
+ Messenger result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ @Override
+ public Messenger buildPartial() {
+ Messenger result = new Messenger(this);
+ if (bitField0_ != 0) { buildPartial0(result); }
+ onBuilt();
+ return result;
+ }
+
+ private void buildPartial0(Messenger result) {
+ int from_bitField0_ = bitField0_;
+ if (((from_bitField0_ & 0x00000001) != 0)) {
+ result.header_ = headerBuilder_ == null
+ ? header_
+ : headerBuilder_.build();
+ }
+ if (((from_bitField0_ & 0x00000002) != 0)) {
+ result.error_ = errorBuilder_ == null
+ ? error_
+ : errorBuilder_.build();
+ }
+ if (((from_bitField0_ & 0x00000004) != 0)) {
+ result.body_ = body_;
+ }
+ }
+
+ @Override
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof Messenger) {
+ return mergeFrom((Messenger)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(Messenger other) {
+ if (other == Messenger.getDefaultInstance()) return this;
+ if (other.hasHeader()) {
+ mergeHeader(other.getHeader());
+ }
+ if (other.hasError()) {
+ mergeError(other.getError());
+ }
+ if (other.getBody() != com.google.protobuf.ByteString.EMPTY) {
+ setBody(other.getBody());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ onChanged();
+ return this;
+ }
+
+ @Override
+ public final boolean isInitialized() {
+ return true;
+ }
+
+ @Override
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ if (extensionRegistry == null) {
+ throw new NullPointerException();
+ }
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ case 10: {
+ input.readMessage(
+ getHeaderFieldBuilder().getBuilder(),
+ extensionRegistry);
+ bitField0_ |= 0x00000001;
+ break;
+ } // case 10
+ case 18: {
+ input.readMessage(
+ getErrorFieldBuilder().getBuilder(),
+ extensionRegistry);
+ bitField0_ |= 0x00000002;
+ break;
+ } // case 18
+ case 26: {
+ body_ = input.readBytes();
+ bitField0_ |= 0x00000004;
+ break;
+ } // case 26
+ default: {
+ if (!super.parseUnknownField(input, extensionRegistry, tag)) {
+ done = true; // was an endgroup tag
+ }
+ break;
+ } // default:
+ } // switch (tag)
+ } // while (!done)
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ } finally {
+ onChanged();
+ } // finally
+ return this;
+ }
+ private int bitField0_;
+
+ private Header header_;
+ private com.google.protobuf.SingleFieldBuilderV3<
+ Header, Header.Builder, HeaderOrBuilder> headerBuilder_;
+ /**
+ * .Header header = 1;
+ * @return Whether the header field is set.
+ */
+ public boolean hasHeader() {
+ return ((bitField0_ & 0x00000001) != 0);
+ }
+ /**
+ * .Header header = 1;
+ * @return The header.
+ */
+ public Header getHeader() {
+ if (headerBuilder_ == null) {
+ return header_ == null ? Header.getDefaultInstance() : header_;
+ } else {
+ return headerBuilder_.getMessage();
+ }
+ }
+ /**
+ * .Header header = 1;
+ */
+ public Builder setHeader(Header value) {
+ if (headerBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ header_ = value;
+ } else {
+ headerBuilder_.setMessage(value);
+ }
+ bitField0_ |= 0x00000001;
+ onChanged();
+ return this;
+ }
+ /**
+ * .Header header = 1;
+ */
+ public Builder setHeader(
+ Header.Builder builderForValue) {
+ if (headerBuilder_ == null) {
+ header_ = builderForValue.build();
+ } else {
+ headerBuilder_.setMessage(builderForValue.build());
+ }
+ bitField0_ |= 0x00000001;
+ onChanged();
+ return this;
+ }
+ /**
+ * .Header header = 1;
+ */
+ public Builder mergeHeader(Header value) {
+ if (headerBuilder_ == null) {
+ if (((bitField0_ & 0x00000001) != 0) &&
+ header_ != null &&
+ header_ != Header.getDefaultInstance()) {
+ getHeaderBuilder().mergeFrom(value);
+ } else {
+ header_ = value;
+ }
+ } else {
+ headerBuilder_.mergeFrom(value);
+ }
+ bitField0_ |= 0x00000001;
+ onChanged();
+ return this;
+ }
+ /**
+ * .Header header = 1;
+ */
+ public Builder clearHeader() {
+ bitField0_ = (bitField0_ & ~0x00000001);
+ header_ = null;
+ if (headerBuilder_ != null) {
+ headerBuilder_.dispose();
+ headerBuilder_ = null;
+ }
+ onChanged();
+ return this;
+ }
+ /**
+ * .Header header = 1;
+ */
+ public Header.Builder getHeaderBuilder() {
+ bitField0_ |= 0x00000001;
+ onChanged();
+ return getHeaderFieldBuilder().getBuilder();
+ }
+ /**
+ * .Header header = 1;
+ */
+ public HeaderOrBuilder getHeaderOrBuilder() {
+ if (headerBuilder_ != null) {
+ return headerBuilder_.getMessageOrBuilder();
+ } else {
+ return header_ == null ?
+ Header.getDefaultInstance() : header_;
+ }
+ }
+ /**
+ * .Header header = 1;
+ */
+ private com.google.protobuf.SingleFieldBuilderV3<
+ Header, Header.Builder, HeaderOrBuilder>
+ getHeaderFieldBuilder() {
+ if (headerBuilder_ == null) {
+ headerBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
+ Header, Header.Builder, HeaderOrBuilder>(
+ getHeader(),
+ getParentForChildren(),
+ isClean());
+ header_ = null;
+ }
+ return headerBuilder_;
+ }
+
+ private Error error_;
+ private com.google.protobuf.SingleFieldBuilderV3<
+ Error, Error.Builder, ErrorOrBuilder> errorBuilder_;
+ /**
+ * .Error error = 2;
+ * @return Whether the error field is set.
+ */
+ public boolean hasError() {
+ return ((bitField0_ & 0x00000002) != 0);
+ }
+ /**
+ * .Error error = 2;
+ * @return The error.
+ */
+ public Error getError() {
+ if (errorBuilder_ == null) {
+ return error_ == null ? Error.getDefaultInstance() : error_;
+ } else {
+ return errorBuilder_.getMessage();
+ }
+ }
+ /**
+ * .Error error = 2;
+ */
+ public Builder setError(Error value) {
+ if (errorBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ error_ = value;
+ } else {
+ errorBuilder_.setMessage(value);
+ }
+ bitField0_ |= 0x00000002;
+ onChanged();
+ return this;
+ }
+ /**
+ * .Error error = 2;
+ */
+ public Builder setError(
+ Error.Builder builderForValue) {
+ if (errorBuilder_ == null) {
+ error_ = builderForValue.build();
+ } else {
+ errorBuilder_.setMessage(builderForValue.build());
+ }
+ bitField0_ |= 0x00000002;
+ onChanged();
+ return this;
+ }
+ /**
+ * .Error error = 2;
+ */
+ public Builder mergeError(Error value) {
+ if (errorBuilder_ == null) {
+ if (((bitField0_ & 0x00000002) != 0) &&
+ error_ != null &&
+ error_ != Error.getDefaultInstance()) {
+ getErrorBuilder().mergeFrom(value);
+ } else {
+ error_ = value;
+ }
+ } else {
+ errorBuilder_.mergeFrom(value);
+ }
+ bitField0_ |= 0x00000002;
+ onChanged();
+ return this;
+ }
+ /**
+ * .Error error = 2;
+ */
+ public Builder clearError() {
+ bitField0_ = (bitField0_ & ~0x00000002);
+ error_ = null;
+ if (errorBuilder_ != null) {
+ errorBuilder_.dispose();
+ errorBuilder_ = null;
+ }
+ onChanged();
+ return this;
+ }
+ /**
+ * .Error error = 2;
+ */
+ public Error.Builder getErrorBuilder() {
+ bitField0_ |= 0x00000002;
+ onChanged();
+ return getErrorFieldBuilder().getBuilder();
+ }
+ /**
+ * .Error error = 2;
+ */
+ public ErrorOrBuilder getErrorOrBuilder() {
+ if (errorBuilder_ != null) {
+ return errorBuilder_.getMessageOrBuilder();
+ } else {
+ return error_ == null ?
+ Error.getDefaultInstance() : error_;
+ }
+ }
+ /**
+ * .Error error = 2;
+ */
+ private com.google.protobuf.SingleFieldBuilderV3<
+ Error, Error.Builder, ErrorOrBuilder>
+ getErrorFieldBuilder() {
+ if (errorBuilder_ == null) {
+ errorBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
+ Error, Error.Builder, ErrorOrBuilder>(
+ getError(),
+ getParentForChildren(),
+ isClean());
+ error_ = null;
+ }
+ return errorBuilder_;
+ }
+
+ private com.google.protobuf.ByteString body_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * bytes body = 3;
+ * @return The body.
+ */
+ @Override
+ public com.google.protobuf.ByteString getBody() {
+ return body_;
+ }
+ /**
+ * bytes body = 3;
+ * @param value The body to set.
+ * @return This builder for chaining.
+ */
+ public Builder setBody(com.google.protobuf.ByteString value) {
+ if (value == null) { throw new NullPointerException(); }
+ body_ = value;
+ bitField0_ |= 0x00000004;
+ onChanged();
+ return this;
+ }
+ /**
+ * bytes body = 3;
+ * @return This builder for chaining.
+ */
+ public Builder clearBody() {
+ bitField0_ = (bitField0_ & ~0x00000004);
+ body_ = getDefaultInstance().getBody();
+ onChanged();
+ return this;
+ }
+ @Override
+ public final Builder setUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return super.setUnknownFields(unknownFields);
+ }
+
+ @Override
+ public final Builder mergeUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return super.mergeUnknownFields(unknownFields);
+ }
+
+
+ // @@protoc_insertion_point(builder_scope:Messenger)
+ }
+
+ // @@protoc_insertion_point(class_scope:Messenger)
+ private static final Messenger DEFAULT_INSTANCE;
+ static {
+ DEFAULT_INSTANCE = new Messenger();
+ }
+
+ public static Messenger getDefaultInstance() {
+ return DEFAULT_INSTANCE;
+ }
+
+ private static final com.google.protobuf.Parser
+ PARSER = new com.google.protobuf.AbstractParser() {
+ @Override
+ public Messenger parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ Builder builder = newBuilder();
+ try {
+ builder.mergeFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(builder.buildPartial());
+ } catch (com.google.protobuf.UninitializedMessageException e) {
+ throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(e)
+ .setUnfinishedMessage(builder.buildPartial());
+ }
+ return builder.buildPartial();
+ }
+ };
+
+ public static com.google.protobuf.Parser parser() {
+ return PARSER;
+ }
+
+ @Override
+ public com.google.protobuf.Parser getParserForType() {
+ return PARSER;
+ }
+
+ @Override
+ public Messenger getDefaultInstanceForType() {
+ return DEFAULT_INSTANCE;
+ }
+
+ }
+
+ private static final com.google.protobuf.Descriptors.Descriptor
+ internal_static_Error_descriptor;
+ private static final
+ com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internal_static_Error_fieldAccessorTable;
+ private static final com.google.protobuf.Descriptors.Descriptor
+ internal_static_Header_descriptor;
+ private static final
+ com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internal_static_Header_fieldAccessorTable;
+ private static final com.google.protobuf.Descriptors.Descriptor
+ internal_static_Messenger_descriptor;
+ private static final
+ com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internal_static_Messenger_fieldAccessorTable;
+
+ public static com.google.protobuf.Descriptors.FileDescriptor
+ getDescriptor() {
+ return descriptor;
+ }
+ private static com.google.protobuf.Descriptors.FileDescriptor
+ descriptor;
+ static {
+ String[] descriptorData = {
+ "\n\rmessage.proto\"\"\n\005Error\022\014\n\004code\030\001 \001(\r\022\013" +
+ "\n\003msg\030\002 \001(\t\"\\\n\006Header\022\014\n\004code\030\001 \001(\r\022\014\n\004b" +
+ "uf0\030\002 \001(\014\022\014\n\004buf1\030\003 \001(\014\022\014\n\004buf2\030\004 \001(\014\022\014\n" +
+ "\004buf3\030\005 \001(\014\022\014\n\004buf4\030\006 \001(\014\"I\n\tMessenger\022\027" +
+ "\n\006header\030\001 \001(\0132\007.Header\022\025\n\005error\030\002 \001(\0132\006" +
+ ".Error\022\014\n\004body\030\003 \001(\014b\006proto3"
+ };
+ descriptor = com.google.protobuf.Descriptors.FileDescriptor
+ .internalBuildGeneratedFileFrom(descriptorData,
+ new com.google.protobuf.Descriptors.FileDescriptor[] {
+ });
+ internal_static_Error_descriptor =
+ getDescriptor().getMessageTypes().get(0);
+ internal_static_Error_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
+ internal_static_Error_descriptor,
+ new String[] { "Code", "Msg", });
+ internal_static_Header_descriptor =
+ getDescriptor().getMessageTypes().get(1);
+ internal_static_Header_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
+ internal_static_Header_descriptor,
+ new String[] { "Code", "Buf0", "Buf1", "Buf2", "Buf3", "Buf4", });
+ internal_static_Messenger_descriptor =
+ getDescriptor().getMessageTypes().get(2);
+ internal_static_Messenger_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
+ internal_static_Messenger_descriptor,
+ new String[] { "Header", "Error", "Body", });
+ }
+
+ // @@protoc_insertion_point(outer_class_scope)
+}
diff --git a/common/src/main/java/org/taj/common/tcp/ResponseCallback.java b/common/src/main/java/org/taj/common/tcp/ResponseCallback.java
new file mode 100644
index 0000000000000000000000000000000000000000..474617d4e88aaaf5de6bc8951944b0e7db5be88f
--- /dev/null
+++ b/common/src/main/java/org/taj/common/tcp/ResponseCallback.java
@@ -0,0 +1,5 @@
+package org.taj.common.tcp;
+
+public interface ResponseCallback {
+ byte[] recv(String topic, byte[] req);
+}
diff --git a/common/src/main/java/org/taj/common/tcp/TcpClient.java b/common/src/main/java/org/taj/common/tcp/TcpClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..9094a66a29cd1cba3dc1ad59d99c890e6d05d1cb
--- /dev/null
+++ b/common/src/main/java/org/taj/common/tcp/TcpClient.java
@@ -0,0 +1,154 @@
+package org.taj.common.tcp;
+
+import org.taj.common.tcp.exception.ConnectionException;
+import org.taj.common.tcp.exception.MessageException;
+import com.google.protobuf.ByteString;
+import com.google.protobuf.InvalidProtocolBufferException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.zeromq.SocketType;
+import org.zeromq.ZContext;
+import org.zeromq.ZMQ;
+import org.zeromq.ZMQException;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+/**
+ * 客户端
+ */
+public class TcpClient implements Closeable {
+ private static final Logger logger = LogManager.getLogger(TcpClient.class);
+ private final String connIP;
+ private final int connPort;
+ private final int subPort;
+ private final ZContext ctx;
+ private ZMQ.Socket connSocket;
+ private ZMQ.Socket subSocket;
+ private ResponseCallback cb;
+ private ZMQ.Poller poller;
+ private final String appName;
+
+ public TcpClient(String ip, int port, String appName) {
+ this.connIP = ip;
+ this.connPort = port;
+ this.subPort = port + 1;
+ ctx = new ZContext();
+ poller = ctx.createPoller(1);
+ this.appName = appName;
+ }
+
+ public boolean connect() {
+ try {
+ connSocket = ctx.createSocket(SocketType.DEALER);
+ boolean b = connSocket.connect("tcp://" + connIP + ":" + connPort);
+ subSocket = ctx.createSocket(SocketType.SUB);
+ b &= subSocket.connect("tcp://" + connIP + ":" + subPort);
+ poller = ctx.createPoller(2);
+ poller.register(connSocket, ZMQ.Poller.POLLIN);
+ poller.register(subSocket, ZMQ.Poller.POLLIN);
+ new Thread(() -> {
+ while (!Thread.currentThread().isInterrupted()) {
+ poller.poll();
+ if(poller.pollin(0)) {
+ byte[] data = connSocket.recv();
+ if (cb != null) {
+ cb.recv("-", data);
+ }
+ }
+ if (poller.pollin(1)) {
+ String topic = subSocket.recvStr(); // 接收主题
+ byte[] data = recvBytes();
+ if (cb != null) {
+ cb.recv(topic, data);
+ }
+ }
+ }
+ }).start();
+ if(b) {
+ b = connSocket.send(appName);
+ }
+ return b;
+ } catch (ZMQException ex) {
+ throw new ConnectionException(ex);
+ }
+ }
+
+ /**
+ * 发送消息
+ */
+ public boolean sendBytes(byte[] data) {
+ Message.Messenger.Builder msgBuilder = Message.Messenger.newBuilder();
+ Message.Messenger messenger = msgBuilder
+ .setHeader(Message.Header.newBuilder().setCode(1).build())
+ .setError(Message.Error.newBuilder().setCode(0))
+ .setBody(ByteString.copyFrom(data)).build();
+ return connSocket.send(messenger.toByteArray());
+ }
+
+
+ /**
+ * 元数据接受
+ */
+ private byte[] recvRawBytes() {
+ byte[] res = connSocket.recv();
+ Message.Messenger.Builder msgBuilder = Message.Messenger.newBuilder();
+// if (res.length == 1) {
+// Message.Messenger messenger = msgBuilder
+// .setHeader(Message.Header.newBuilder()
+// .setCode(0)
+// .setBuf0(ByteString.copyFrom("single byte message", StandardCharsets.UTF_8))
+// .build())
+// .setBody(ByteString.copyFrom(res)).build();
+// return messenger.toByteArray();
+// }
+ return res;
+ }
+
+ /**
+ * 消息接受
+ */
+ public byte[] recvBytes() {
+ byte[] res = connSocket.recv();
+ try {
+ Message.Messenger messenger = Message.Messenger.parseFrom(res);
+ if (messenger.hasHeader()) {
+ // TODO: 处理消息头
+ }
+ if (messenger.hasError()) {
+ // TODO: 处理错误
+ }
+ return messenger.getBody().toByteArray();
+ } catch (InvalidProtocolBufferException ex) {
+ throw new MessageException(ex);
+ }
+ }
+
+ public byte[] sendBytesWaitAck(byte[] data) {
+ if (this.sendBytes(data)) {
+ return recvBytes();
+ }
+ return new byte[0];
+ }
+
+ public boolean subscribe(String topic) {
+ return subSocket.subscribe(topic);
+ }
+
+ public boolean unsubscribe(String topic) {
+ return subSocket.unsubscribe(topic);
+ }
+
+ public void setTopicCallback(ResponseCallback cb) {
+ this.cb = cb;
+ }
+
+ @Override
+ public void close() throws IOException {
+ logger.info("客户端主动关闭");
+ connSocket.send(new byte[0]);
+ connSocket.close();
+ subSocket.close();
+ ctx.close();
+ }
+}
diff --git a/common/src/main/java/org/taj/common/tcp/TcpServer.java b/common/src/main/java/org/taj/common/tcp/TcpServer.java
new file mode 100644
index 0000000000000000000000000000000000000000..6cf80ab443c3a60bdb10c39c500678c362056053
--- /dev/null
+++ b/common/src/main/java/org/taj/common/tcp/TcpServer.java
@@ -0,0 +1,97 @@
+package org.taj.common.tcp;
+
+import org.taj.common.tcp.exception.MessageException;
+import com.google.protobuf.InvalidProtocolBufferException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.zeromq.SocketType;
+import org.zeromq.ZContext;
+import org.zeromq.ZMQ;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 服务端
+ */
+public class TcpServer implements Closeable {
+ private static final Logger logger = LogManager.getLogger(TcpServer.class);
+ private final int routerPort;
+ private final int pubPort;
+ private final Map identities = Collections.synchronizedMap(new HashMap<>());
+ private ZContext context;
+ private ZMQ.Socket routerSocket;
+ private ZMQ.Socket pubSocket;
+ public ResponseCallback cb;
+
+ public TcpServer(int port) {
+ this.routerPort = port;
+ this.pubPort = port + 1;
+ }
+
+ public void start() {
+ context = new ZContext();
+ routerSocket = context.createSocket(SocketType.ROUTER);
+ routerSocket.bind("tcp://*:" + routerPort);
+
+ // 创建发布-订阅模式的套接字
+ pubSocket = context.createSocket(SocketType.PUB);
+ pubSocket.bind("tcp://*:" + pubPort);
+
+ ZMQ.Poller poller = context.createPoller(1);
+ poller.register(routerSocket, ZMQ.Poller.POLLIN);
+ ExecutorService executor = Executors.newFixedThreadPool(1);
+ executor.execute(() -> {
+ while (!Thread.currentThread().isInterrupted()) {
+ poller.poll();
+ if (poller.pollin(0)) {
+ // 处理路由模式的消息
+ boolean isNewClient = true;
+ byte[] identity = routerSocket.recv();
+ for (byte[] id : identities.values()) {
+ if (Arrays.equals(id, identity)) {
+ isNewClient = false;
+ break;
+ }
+ }
+ if (isNewClient) {
+ String appName = routerSocket.recvStr();
+ identities.put(appName, identity);
+ continue;
+ }
+ byte[] data = routerSocket.recv();
+ try {
+ Message.Messenger messenger = Message.Messenger.parseFrom(data);
+ if(cb != null) {
+ cb.recv("-", messenger.getBody().toByteArray());
+ }
+ } catch (InvalidProtocolBufferException ex) {
+ throw new MessageException(ex);
+ }
+ }
+ }
+ });
+ executor.shutdown();
+ }
+
+ public void send(String appName, byte[] data) {
+ byte[] identity = identities.get(appName);
+ if(identity != null) {
+ routerSocket.sendMore(identity);
+ routerSocket.send(data);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ routerSocket.close();
+ pubSocket.close();
+ context.close();
+ }
+}
diff --git a/common/src/main/java/org/taj/common/tcp/exception/ConnectionException.java b/common/src/main/java/org/taj/common/tcp/exception/ConnectionException.java
new file mode 100644
index 0000000000000000000000000000000000000000..77e028363c5bea734eebb8e9005e74b48466faf9
--- /dev/null
+++ b/common/src/main/java/org/taj/common/tcp/exception/ConnectionException.java
@@ -0,0 +1,11 @@
+package org.taj.common.tcp.exception;
+
+public class ConnectionException extends PiplineException {
+ public ConnectionException(String msg) {
+ super(msg);
+ }
+
+ public ConnectionException(Exception ex) {
+ super(ex);
+ }
+}
diff --git a/common/src/main/java/org/taj/common/tcp/exception/MessageException.java b/common/src/main/java/org/taj/common/tcp/exception/MessageException.java
new file mode 100644
index 0000000000000000000000000000000000000000..a4b890e867e66cb3da77dcf74d9ca216a86d2a30
--- /dev/null
+++ b/common/src/main/java/org/taj/common/tcp/exception/MessageException.java
@@ -0,0 +1,11 @@
+package org.taj.common.tcp.exception;
+
+public class MessageException extends PiplineException {
+ public MessageException(String msg) {
+ super(msg);
+ }
+
+ public MessageException(Exception ex) {
+ super(ex);
+ }
+}
diff --git a/common/src/main/java/org/taj/common/tcp/exception/PiplineException.java b/common/src/main/java/org/taj/common/tcp/exception/PiplineException.java
new file mode 100644
index 0000000000000000000000000000000000000000..deb9512bf32a0a65fa02e32d4140384445af9407
--- /dev/null
+++ b/common/src/main/java/org/taj/common/tcp/exception/PiplineException.java
@@ -0,0 +1,11 @@
+package org.taj.common.tcp.exception;
+
+public class PiplineException extends RuntimeException {
+ public PiplineException(String msg) {
+ super(msg);
+ }
+
+ public PiplineException(Exception ex) {
+ super(ex);
+ }
+}
diff --git a/dependencies/hutool/pom.xml b/dependencies/hutool/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..2ab9efa9109c23a2a9c6220f950ffefa80c617c7
--- /dev/null
+++ b/dependencies/hutool/pom.xml
@@ -0,0 +1,39 @@
+
+
+
+ dependencies
+ org.taj
+ 1.0
+
+ 4.0.0
+
+ hutool
+
+
+ 11
+ 11
+
+
+
+
+
+ cn.hutool
+ hutool-all
+
+
+ org.bouncycastle
+ bcprov-jdk15to18
+
+
+
+ org.apache.poi
+ poi-ooxml
+
+
+ org.apache.poi
+ poi-scratchpad
+
+
+
\ No newline at end of file
diff --git a/dependencies/junit/pom.xml b/dependencies/junit/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..703e49186dcfef16ba4d5747d6fe6cfc8760ae48
--- /dev/null
+++ b/dependencies/junit/pom.xml
@@ -0,0 +1,36 @@
+
+
+
+ dependencies
+ org.taj
+ 1.0
+
+ 4.0.0
+
+ junit
+
+
+ 11
+ 11
+
+
+
+
+
+ junit
+ junit
+
+
+ org.springframework.boot
+ spring-boot-test
+ test
+
+
+ org.springframework
+ spring-test
+ test
+
+
+
\ No newline at end of file
diff --git a/dependencies/mybatis/pom.xml b/dependencies/mybatis/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..19b9a2b16bcc498e6c715b9396929302c4e8a7c1
--- /dev/null
+++ b/dependencies/mybatis/pom.xml
@@ -0,0 +1,42 @@
+
+
+
+ dependencies
+ org.taj
+ 1.0
+
+ 4.0.0
+
+ mybatis
+
+
+ 11
+ 11
+
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+
+
+ com.github.jsqlparser
+ jsqlparser
+
+
+
+ org.flywaydb
+ flyway-core
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+ org.springframework.boot
+ spring-boot-starter-jta-atomikos
+
+
+
\ No newline at end of file
diff --git a/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/AtomikosConfig.java b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/AtomikosConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..c8d83932ca48832c5a4de693b4fe636888965725
--- /dev/null
+++ b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/AtomikosConfig.java
@@ -0,0 +1,22 @@
+package org.taj.dependencies.mybatis;
+
+import com.atomikos.icatch.jta.UserTransactionImp;
+import com.atomikos.icatch.jta.UserTransactionManager;
+import org.springframework.context.annotation.Bean;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.jta.JtaTransactionManager;
+
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+public class AtomikosConfig {
+
+ @Bean(name = "transactionManager")
+ public PlatformTransactionManager transactionManager() throws SystemException {
+ final UserTransaction userTransaction = new UserTransactionImp();
+ userTransaction.setTransactionTimeout(20000);
+ final UserTransactionManager userTransactionManager = new UserTransactionManager();
+ userTransactionManager.setForceShutdown(false);
+ return new JtaTransactionManager(userTransaction, userTransactionManager);
+ }
+}
diff --git a/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/FactoryBeanBuilder.java b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/FactoryBeanBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..b0d37a8c5cd4bbd3293b1fd4d3f7ab30acd437ea
--- /dev/null
+++ b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/FactoryBeanBuilder.java
@@ -0,0 +1,53 @@
+package org.taj.dependencies.mybatis;
+
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.Resource;
+
+import javax.sql.DataSource;
+import java.util.function.Function;
+
+public class FactoryBeanBuilder {
+ private static final Logger logger = LoggerFactory.getLogger(FactoryBeanBuilder.class);
+
+ private ApplicationContext ctx;
+ private DataSource dataSource;
+
+ public static FactoryBeanBuilder getInstance(ApplicationContext ctx) {
+ FactoryBeanBuilder builder = new FactoryBeanBuilder();
+ builder.ctx = ctx;
+ return builder;
+ }
+
+ public FactoryBeanBuilder setDataSource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ return this;
+ }
+
+ public SqlSessionFactoryBean getBean(String locationPattern) throws Exception {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource);
+ Resource[] resources = ctx.getResources(locationPattern);
+ for (Resource resource : resources) {
+ logger.info(resource.getFilename());
+ }
+ factoryBean.setMapperLocations(resources);
+ return factoryBean;
+ }
+
+ public SqlSessionFactoryBean getBean(String locationPattern, Function decryptFunc) throws Exception {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource);
+ Resource[] resources = ctx.getResources(locationPattern);
+ for (int i = 0; i < resources.length; i++) {
+ byte[] bytes = resources[i].getInputStream().readAllBytes();
+ byte[] plainText = decryptFunc.apply(bytes);
+ resources[i] = new ByteArrayResource(plainText);
+ }
+ factoryBean.setMapperLocations(resources);
+ return factoryBean;
+ }
+}
diff --git a/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/FlywayConfig.java b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/FlywayConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..8a1bb8f13ff69eb5f51da46cfc5a04b7d134712a
--- /dev/null
+++ b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/FlywayConfig.java
@@ -0,0 +1,32 @@
+package org.taj.dependencies.mybatis;
+
+import org.flywaydb.core.Flyway;
+import org.flywaydb.core.api.FlywayException;
+import org.flywaydb.core.api.configuration.ClassicConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.annotation.Order;
+
+import javax.annotation.PostConstruct;
+import javax.sql.DataSource;
+
+@Order(1)
+public class FlywayConfig {
+ @Autowired
+ @Qualifier("localDataSource")
+ private DataSource dataSource;
+
+ @PostConstruct
+ public void init() {
+ ClassicConfiguration conf = new ClassicConfiguration();
+ conf.setDataSource(dataSource);
+ conf.setOutOfOrder(true);
+ Flyway flyway = new Flyway(conf);
+ try {
+ flyway.migrate();
+ } catch (FlywayException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/annotation/XDataSourceTransaction.java b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/annotation/XDataSourceTransaction.java
new file mode 100644
index 0000000000000000000000000000000000000000..2acfb0d8300961daab7396ff9a85d10be9ad5860
--- /dev/null
+++ b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/annotation/XDataSourceTransaction.java
@@ -0,0 +1,11 @@
+package org.taj.dependencies.mybatis.annotation;
+
+import java.lang.annotation.*;
+
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@Documented
+public @interface XDataSourceTransaction {
+ String[] txManagers();
+}
diff --git a/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/annotation/XDataSourceTransactionAspect.java b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/annotation/XDataSourceTransactionAspect.java
new file mode 100644
index 0000000000000000000000000000000000000000..edf384edbd22f32c3158d918f06024bd3c708a26
--- /dev/null
+++ b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/annotation/XDataSourceTransactionAspect.java
@@ -0,0 +1,65 @@
+package org.taj.dependencies.mybatis.annotation;
+
+import org.aspectj.lang.annotation.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.DefaultTransactionDefinition;
+
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.Stack;
+
+@Aspect
+public class XDataSourceTransactionAspect {
+ @Autowired
+ private ApplicationContext ctx;
+
+ private static final ThreadLocal>> txMgrs = new ThreadLocal<>();
+
+ @Pointcut("@annotation(org.taj.dependencies.mybatis.annotation.XDataSourceTransaction)")
+ public void pointcut() {}
+
+ @Before("pointcut() && @annotation(transaction)")
+ public void before(XDataSourceTransaction transaction) {
+ String[] txmBeans = transaction.txManagers();
+ DefaultTransactionDefinition def = new DefaultTransactionDefinition();
+ def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
+ def.setIsolationLevel(TransactionDefinition.ISOLATION_DEFAULT);
+ def.setReadOnly(false);
+
+ // 创建一个栈,用于存储PlatformTransactionManager和TransactionStatus
+ Stack> txm = new Stack<>();
+
+ // 将PlatformTransactionManager和TransactionStatus放入栈中
+ for(String txmBean : txmBeans) {
+ PlatformTransactionManager bean = ctx.getBean(txmBean, PlatformTransactionManager.class);
+ txm.push(new AbstractMap.SimpleEntry<>(bean, bean.getTransaction(def)));
+ }
+ txMgrs.set(txm);
+ }
+
+ @AfterReturning("pointcut()")
+ public void afterReturning() {
+ Stack> entries = txMgrs.get();
+ // 如果没有发生异常,则提交
+ while(!entries.isEmpty()) {
+ Map.Entry entry = entries.pop();
+ entry.getKey().commit(entry.getValue());
+ }
+ txMgrs.remove();
+ }
+
+ @AfterThrowing("pointcut()")
+ public void afterThrowing() {
+ Stack> entries = txMgrs.get();
+ // 如果有发生异常,则回滚
+ while(!entries.isEmpty()) {
+ Map.Entry entry = entries.pop();
+ entry.getKey().rollback(entry.getValue());
+ }
+ txMgrs.remove();
+ }
+}
diff --git a/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/plugins/binlog/DDLInterceptor.java b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/plugins/binlog/DDLInterceptor.java
new file mode 100644
index 0000000000000000000000000000000000000000..7c86418c50f12a14e47ace31138e45eb8c09f77e
--- /dev/null
+++ b/dependencies/mybatis/src/main/java/org/taj/dependencies/mybatis/plugins/binlog/DDLInterceptor.java
@@ -0,0 +1,49 @@
+package org.taj.dependencies.mybatis.plugins.binlog;
+
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.ParameterMapping;
+import org.apache.ibatis.mapping.SqlCommandType;
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.plugin.Intercepts;
+import org.apache.ibatis.plugin.Invocation;
+import org.apache.ibatis.plugin.Signature;
+import org.apache.ibatis.reflection.MetaObject;
+import org.apache.ibatis.session.Configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 拦截所有DDL语句
+ */
+@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
+public class DDLInterceptor implements Interceptor {
+ @Override
+ public Object intercept(Invocation invocation) throws Throwable {
+ Object result = invocation.proceed();
+ Object[] args = invocation.getArgs();
+ if (args[0] instanceof MappedStatement) {
+ MappedStatement statement = (MappedStatement) args[0];
+ SqlCommandType type = statement.getSqlCommandType();
+ Object parameter = invocation.getArgs()[1];
+ BoundSql boundSql = statement.getBoundSql(parameter);
+ String sql = boundSql.getSql();
+ Configuration configuration = statement.getConfiguration();
+ List