good morning!!!!

Skip to content
Snippets Groups Projects
Commit 9f7d774f authored by a's avatar a
Browse files

Merge branch 'master' of gfx.cafe:open/jsonpatch

parents 2bab7ad8 eb56289f
Branches
Tags v0.0.2
No related merge requests found
......@@ -58,23 +58,22 @@ func diffArrays(a, b []interface{}, p string) ([]*Patchwork, error) {
for j := bIndex; j < maxLen; j++ {
be := b[j]
if reflect.DeepEqual(te.val, be) {
// element is already in b, move on
// both are equal, so just move on
bIndex++
aIndex++
break
} else {
if te.isFixed {
patch = append(patch, NewPatch("add", newPath, be))
addedDelta++
bIndex++
addedDelta = addedDelta + 1
bIndex = bIndex + 1
break
} else {
patch = append(patch, NewPatch("remove", newPath, te.val)) //save value for remove so we can use it later
addedDelta--
aIndex++
addedDelta = addedDelta - 1
aIndex = aIndex + 1
break
}
}
}
}
......
......@@ -48,6 +48,9 @@ func NewPatch(operation OpCode, path string, value any) *Patchwork {
return &Patchwork{Operation: operation, Path: path, Value: value}
}
/// DiffT calls Diff, while marshaling both a and b into json beforehands
/// Note that the JSON is immediately unmarshaled, and so if you already have []byte
/// use of Diff is preferred.
func DiffT[T any](a, b T) ([]*Patchwork, error) {
aj, err := json.Marshal(a)
if err != nil {
......@@ -84,6 +87,7 @@ func Diff(a, b []byte) ([]*Patchwork, error) {
//
// 'a' is original, 'b' is the modified document. Both are to be given as json encoded content.
// The function will return JSON as a byte array
// All this really does is call Diff and then run json.Marshal on the result
func DiffBytes(a, b []byte) ([]byte, error) {
ops, err := Diff(a, b)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment