You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tubemq.apache.org by gx...@apache.org on 2020/09/15 11:46:59 UTC

[incubator-tubemq] 43/50: [TUBEMQ-288]C++ SDK Codec interface (#254)

This is an automated email from the ASF dual-hosted git repository.

gxcheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git

commit 09d2c9bf02aad92d1ecfbd41960f44eda24102fa
Author: charlely <41...@users.noreply.github.com>
AuthorDate: Sat Sep 12 09:36:40 2020 +0800

    [TUBEMQ-288]C++ SDK Codec interface (#254)
    
    Co-authored-by: charleli <ch...@tencent.com>
---
 .../tubemq-client-cpp/src/codec_protocol.h         | 58 ++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/tubemq-client-twins/tubemq-client-cpp/src/codec_protocol.h b/tubemq-client-twins/tubemq-client-cpp/src/codec_protocol.h
new file mode 100644
index 0000000..82e68e7
--- /dev/null
+++ b/tubemq-client-twins/tubemq-client-cpp/src/codec_protocol.h
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _TUBEMQ_CODEC_PROTOCOL_H_
+#define _TUBEMQ_CODEC_PROTOCOL_H_
+
+#include <list>
+#include <memory>
+#include <string>
+
+#include "any.h"
+#include "buffer.h"
+
+namespace tubemq {
+
+class CodecProtocol {
+ public:
+  CodecProtocol() {}
+
+  virtual ~CodecProtocol() {}
+
+  virtual std::string Name() const = 0;
+
+  virtual bool Decode(const BufferPtr &buff, Any &out) = 0;
+
+  virtual bool Encode(const Any &in, BufferPtr &buff) = 0;
+
+  // return code: -1 failed; 0-Unfinished; > 0 package buffer size
+  virtual int32_t Check(BufferPtr &in, Any &out, uint32_t &request_id, bool &has_request_id,
+                        size_t &package_length) = 0;
+
+  // get protocol request id
+  virtual int32_t GetRequestId(uint32_t &request_id, const Any &rsp) const { return -1; }
+
+  // set protocol request request id
+  virtual int32_t SetRequestId(uint32_t request_id, Any &req) { return -1; }
+};
+
+using CodecProtocolPtr = std::shared_ptr<CodecProtocol>;
+
+}  // namespace tubemq
+#endif  // _TUBEMQ_CODEC_PROTOCOL_H_