jsondiff

package module
v0.0.0-...-32de607 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2014 License: GPL-2.0 Imports: 8 Imported by: 1

README

go-jsondiff

A GO port of https://github.com/Simperium/jsondiff

Documentation

Overview

A pure GO port of https://github.com/Simperium/jsondiff

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Changes

type Changes []DocumentChange

A slice of document changes. Returned by Parse()

func Parse

func Parse(changes string) (Changes, error)

Parses a string list of jsondiff changes into an array of changes. These changes are generated by Simperium as objects in a bucket for a user are modified by other connected clients. The string from Simperium looke like: %d:c:[...] where %d is the channel that You initialized when authorizing against the bucket.

type Diff

type Diff struct {
	Operation string      `json:"o,omitempty"` // +, -, r, I, d, L, dL, O
	Value     interface{} `json:"v,omitempty"`
}

This struct represents an diff for a document. Sometimes this is a single operation and other times more diffs are recursively nested down inside. This only applies to keys inside the main document dict. For top level changes see DocumentChange{}.

type DocumentChange

type DocumentChange struct {
	Document       string          `json:"id,omitempty"`
	SourceRevision int             `json:"sv,omitempty"`
	ClientId       string          `json:"clientid,omitempty"`
	Operation      string          `json:"o,omitempty"` // M, -
	Changes        map[string]Diff `json:"v,omitempty"`
	Resultrevision int             `json:"ev,omitempty"`
	CurrentVersion string          `json:"cv,omitempty"`
	ChangesetIds   []string        `json:"ccids,omitempty"`
	ChangesetId    string          `json:"ccid,omitempty"`
	Error          int             `json:"error,omitempty"`
}

This represents all of the changes to a single document that are occuring at once. This data (excepting Changes which are processed on their own) never deals directly with individual parts of the document but rather the document as a whole.

func (*DocumentChange) String

func (d *DocumentChange) String() (string, error)

type Json

type Json map[string]interface{}

This type is just here to save on placing "map[string] interface{}" all over the codebase.

type JsonDiff

type JsonDiff struct {
	// contains filtered or unexported fields
}

The main entrypoint for changing a document dict via a documentchange. I suspect that I'll reture this and just export the apply function on DocumentChange{}. The main reason this is here is to keep a copy of DiffMatchPatch all to ourselves

func New

func New() *JsonDiff

Get a new JsonDiff

func (*JsonDiff) Apply

func (j *JsonDiff) Apply(document Json, change DocumentChange) (Json, error)

Apply a DocumentChange{} to a document dict

func (*JsonDiff) Diff

func (j *JsonDiff) Diff(from, to Json) (*DocumentChange, error)

Notes

Bugs

  • missing schema support (nested and un-nested type, and otype, for generating diffs.) This bug does not affect the patching of items. L, dL, and I (known schema defined diffing varianes) are fully supported for applying diffs to objects, just not generating diffs for objects. For Simperium This functionality is not necessary since the simperium server will gladly accept the diffs and will then send out schema mandated diffs to connected clients...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL