technically it syncs!! but it's still not correct
This commit is contained in:
parent
d178a46605
commit
b4e554866e
|
@ -2,15 +2,16 @@ package main
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"strconv"
|
||||
"strings"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"encoding/base64"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"mast/db"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
sqlite3 "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
@ -80,7 +81,7 @@ type CRSQLChange struct {
|
|||
Value []byte
|
||||
ColVersion int64
|
||||
DBVersion int64
|
||||
SiteID []int
|
||||
SiteID []byte
|
||||
CL int64
|
||||
Seq int64
|
||||
}
|
||||
|
@ -97,18 +98,18 @@ func mapToCRSQLChange(m map[string]interface{}) (CRSQLChange, error) {
|
|||
change.Seq = int64(m["Seq"].(float64))
|
||||
|
||||
// Handle []byte fields
|
||||
change.PK, err = base64.URLEncoding.DecodeString(m["PK"].(string))
|
||||
change.PK, err = decodeBase64ToByteArray(m["PK"].(string))
|
||||
if err != nil {
|
||||
return change, err
|
||||
}
|
||||
//fmt.Println(m["PK"])
|
||||
//fmt.Println(m["PK"].(string))
|
||||
//fmt.Println(base64.URLEncoding.DecodeString(m["PK"].(string)))
|
||||
change.Value, err = base64.URLEncoding.DecodeString(m["Value"].(string))
|
||||
change.Value, err = decodeBase64ToByteArray(m["Value"].(string))
|
||||
if err != nil {
|
||||
return change, err
|
||||
}
|
||||
change.SiteID, err = decodeBase64ToIntArray(string(m["SiteID"].(string)))
|
||||
change.SiteID, err = decodeBase64ToByteArray(m["SiteID"].(string))
|
||||
fmt.Println(change.SiteID)
|
||||
if err != nil {
|
||||
return change, err
|
||||
|
@ -118,7 +119,7 @@ func mapToCRSQLChange(m map[string]interface{}) (CRSQLChange, error) {
|
|||
}
|
||||
|
||||
|
||||
func decodeBase64ToIntArray(encodedString string) ([]int, error) {
|
||||
func decodeBase64ToByteArray(encodedString string) ([]uint8, error) {
|
||||
// Decode the base64 string
|
||||
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
|
||||
if err != nil {
|
||||
|
@ -132,13 +133,13 @@ func decodeBase64ToIntArray(encodedString string) ([]int, error) {
|
|||
stringSlice := strings.Split(decodedString, ",")
|
||||
|
||||
// Convert each string to an integer
|
||||
intSlice := make([]int, len(stringSlice))
|
||||
intSlice := make([]uint8, len(stringSlice))
|
||||
for i, s := range stringSlice {
|
||||
num, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting string to int: %w", err)
|
||||
}
|
||||
intSlice[i] = num
|
||||
intSlice[i] = byte(num)
|
||||
}
|
||||
|
||||
return intSlice, nil
|
||||
|
|
Loading…
Reference in a new issue