reid from https://github.com/michuanhaohao/reid-strong-baseline
zhangmeng
2020-01-20 4324306f529b9bc62d7e818c0b12ff822687bb47
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(err, " msg 处理异常")
            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 decode CameraImage error: ", err.Error())
      return nil
   }
   if i.Data == nil {
      fn(fnName, " protomsg.Image data null")
      return nil
   }
   return i
}