Skip to content

Commit

Permalink
Merge pull request #67 from UlfBj/thread-comm
Browse files Browse the repository at this point in the history
timestamp data compression bug fix
  • Loading branch information
UlfBj authored Jan 6, 2025
2 parents ed436f9 + 0cf9727 commit ff8eace
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions server/vissv2server/wsMgr/wsMgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,43 @@ func getDpTsList(dpMap interface{}) []string {
func replaceTs(respMessage string, messageTs string, tsList []string) string {
tsRef, _ := time.Parse(time.RFC3339, messageTs)
refMs := tsRef.UnixMilli()
preIndex := 0
postIndex := len(respMessage)
var respFraction string
messageTsIndex := strings.Index(respMessage, messageTs)
if strings.Count(respMessage[:messageTsIndex], "{") == 1 {
preIndex = messageTsIndex
respFraction = respMessage[:preIndex]
} else {
messageTsIndex = strings.LastIndex(respMessage, messageTs)
postIndex = messageTsIndex
respFraction = respMessage[postIndex:]
}
for i := 0; i < len(tsList); i++ {
tsDp, _ := time.Parse(time.RFC3339, tsList[i])
dpMs := tsDp.UnixMilli()
diffMs := refMs - dpMs
if diffMs > 999999999 || diffMs < -999999999 {
continue // keep iso time
}
if diffMs == 0 { // replace 2nd instance
firstTsIndex := strings.Index(respMessage, tsList[i]) + len(tsList[i]) + 1
respMessage = respMessage[:firstTsIndex] + strings.Replace(respMessage[firstTsIndex:], tsList[i], timeDiff(int(diffMs)), 1)
signedTimeDiffStr := signedTimeDiff(strconv.Itoa(int(diffMs)), diffMs)
if preIndex == 0 {
respMessage = strings.Replace(respMessage[:postIndex], tsList[i], signedTimeDiffStr, 1) + respFraction
} else {
respMessage = strings.Replace(respMessage, tsList[i], timeDiff(int(diffMs)), 1)
respMessage = respFraction + strings.Replace(respMessage[:postIndex], tsList[i], signedTimeDiffStr, 1)
}
postIndex -= len(tsList[i]) - len(signedTimeDiffStr)
}
return respMessage
}

func timeDiff(diffMs int) string {
func signedTimeDiff(diffMsStr string, diffMs int64) string {
if diffMs > 0 {
return "-" + strconv.Itoa(diffMs)
return "-" + diffMsStr
} else if diffMs == 0 {
return "+" + diffMsStr
} else {
return "+" + strconv.Itoa(-diffMs)
return "+" + diffMsStr[1:]
}
}

Expand Down

0 comments on commit ff8eace

Please sign in to comment.