Compare commits

..

No commits in common. "b4e554866ee22e025933c6cdae3cad46ebce25be" and "072e87c05fa99235d6df104d378bd9dbd1054646" have entirely different histories.

2 changed files with 12 additions and 13 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]) ? btoa(new TextDecoder('utf8').decode(change[6])) : btoa(change[6]),
SiteID: Array.isArray(change[6]) ? arrayBufferToBase64(Uint8Array.from(change[6]).buffer) : btoa(change[6]),
CL: Number(change[7]),
Seq: Number(change[8])
}));

View file

@ -2,16 +2,15 @@ package main
import (
"database/sql"
"encoding/base64"
"strconv"
"strings"
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
"strings"
"encoding/base64"
"mast/db"
"github.com/gorilla/websocket"
sqlite3 "github.com/mattn/go-sqlite3"
)
@ -98,19 +97,19 @@ func mapToCRSQLChange(m map[string]interface{}) (CRSQLChange, error) {
change.Seq = int64(m["Seq"].(float64))
// Handle []byte fields
change.PK, err = decodeBase64ToByteArray(m["PK"].(string))
change.PK, err = base64.URLEncoding.DecodeString(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 = decodeBase64ToByteArray(m["Value"].(string))
change.Value, err = base64.URLEncoding.DecodeString(m["Value"].(string))
if err != nil {
return change, err
}
change.SiteID, err = decodeBase64ToByteArray(m["SiteID"].(string))
fmt.Println(change.SiteID)
//change.SiteID, err = decodeBase64ToIntArray(m["SiteID"].(string))
change.SiteID, err = base64.URLEncoding.DecodeString(m["SiteID"].(string))
if err != nil {
return change, err
}
@ -119,7 +118,7 @@ func mapToCRSQLChange(m map[string]interface{}) (CRSQLChange, error) {
}
func decodeBase64ToByteArray(encodedString string) ([]uint8, error) {
func decodeBase64ToIntArray(encodedString string) ([]int, error) {
// Decode the base64 string
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
if err != nil {
@ -133,13 +132,13 @@ func decodeBase64ToByteArray(encodedString string) ([]uint8, error) {
stringSlice := strings.Split(decodedString, ",")
// Convert each string to an integer
intSlice := make([]uint8, len(stringSlice))
intSlice := make([]int, 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] = byte(num)
intSlice[i] = num
}
return intSlice, nil
@ -163,7 +162,7 @@ func applyChanges(changes []interface{}) {
log.Println("Error inserting change:", err)
}
log.Println("We inserted data successfully??")
fmt.Println(c)
printChange(change)
} else {
fmt.Println("Not OK to convert change")
fmt.Println("Change look like:")