Compare commits

...

2 commits

Author SHA1 Message Date
Anish Lakhwara b4e554866e technically it syncs!! but it's still not correct 2024-08-06 00:54:50 -07:00
Anish Lakhwara d178a46605 successfully decoding SiteID finally... 2024-08-05 23:19:11 -07:00
2 changed files with 13 additions and 12 deletions

View file

@ -59,7 +59,7 @@
Value: Array.isArray(change[3]) ? btoa(String.fromCharCode.apply(null, change[3])) : btoa(change[3]),
ColVersion: Number(change[4]),
DBVersion: Number(change[5]),
SiteID: Array.isArray(change[6]) ? arrayBufferToBase64(Uint8Array.from(change[6]).buffer) : btoa(change[6]),
SiteID: Array.isArray(change[6]) ? btoa(new TextDecoder('utf8').decode(change[6])) : btoa(change[6]),
CL: Number(change[7]),
Seq: Number(change[8])
}));

View file

@ -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"
)
@ -97,19 +98,19 @@ 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(m["SiteID"].(string))
change.SiteID, err = base64.URLEncoding.DecodeString(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
@ -162,7 +163,7 @@ func applyChanges(changes []interface{}) {
log.Println("Error inserting change:", err)
}
log.Println("We inserted data successfully??")
printChange(change)
fmt.Println(c)
} else {
fmt.Println("Not OK to convert change")
fmt.Println("Change look like:")