From 7c6a958f00e327a8991f48093456de7cb84cf918 Mon Sep 17 00:00:00 2001
From: 554325746@qq.com <554325746@qq.com>
Date: 星期三, 05 二月 2020 20:20:24 +0800
Subject: [PATCH] change log for proto marshal

---
 common/helper.go |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/common/helper.go b/common/helper.go
index dc6f7b0..2e4db0d 100644
--- a/common/helper.go
+++ b/common/helper.go
@@ -1,11 +1,24 @@
 package common
 
 import (
+	"context"
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"strconv"
+	"time"
+
+	"basic.com/pubsub/protomsg.git"
+	"github.com/gogo/protobuf/proto"
 )
+
+// GetIpcAddress get ipc
+func GetIpcAddress(shm bool, id string) string {
+	if shm {
+		return id
+	}
+	return `ipc:///tmp/` + id + `.ipc`
+}
 
 // SubConfig sub
 type SubConfig struct {
@@ -41,3 +54,43 @@
 	i, _ := strconv.Atoi(s)
 	return i
 }
+
+// UnserilizeProto un
+func UnserilizeProto(ctx context.Context, data <-chan []byte, out chan<- protomsg.SdkMessage, fn func(...interface{})) {
+	for {
+		select {
+		case <-ctx.Done():
+			return
+		case d := <-data:
+			if len(d) < 100 {
+				continue
+			}
+			msg := protomsg.SdkMessage{}
+			if err := proto.Unmarshal(d, &msg); err != nil {
+				fn("UnserilizeProto Unmarshal msg 澶勭悊寮傚父:", err)
+				continue
+			}
+
+			out <- msg
+
+		default:
+			time.Sleep(10 * time.Millisecond)
+		}
+	}
+}
+
+// UnpackImage unpack
+func UnpackImage(msg protomsg.SdkMessage, fnName string, fn func(...interface{})) *protomsg.Image {
+	// 鍙嶅簭鍒楀寲鏁版嵁寰楀埌sdk鍏ュ弬
+	i := &protomsg.Image{}
+	err := proto.Unmarshal(msg.Data, i)
+	if err != nil {
+		fn(fnName, " protobuf Unmarshal decode CameraImage error: ", err.Error())
+		return nil
+	}
+	if i.Data == nil {
+		fn(fnName, " protomsg.Image data null")
+		return nil
+	}
+	return i
+}

--
Gitblit v1.8.0