diff

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 6 Imported by: 6

Documentation

Overview

The diff package provides operations for diffing and patching rbxdump structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v0.2.0

type Action struct {
	// Type is the kind of transformation performed by the action.
	Type Type
	// Element is the type of element to which the action applies.
	Element Element
	// Primary is the name of the primary element.
	Primary string
	// Secondary is the name of the secondary element. Applies only to Property,
	// Function, Event, Callback, and EnumItem elements.
	Secondary string `json:",omitempty"`
	// Fields describes fields of the element. If Type is Add, this describes
	// the initial values. If Type is Change, this describes the new values.
	Fields rbxdump.Fields `json:",omitempty"`
}

Action describes a single unit of difference between two dump structures.

func (Action) String added in v0.2.0

func (a Action) String() string

func (Action) ToFielder added in v0.9.0

func (a Action) ToFielder() rbxdump.Fielder

ToFielder returns a new element corresponding to the action's element type, as a Fielder. The Name field is set according to the action's identifiers. Returns nil if the type is invalid.

func (Action) ToMember added in v0.9.0

func (a Action) ToMember() rbxdump.Member

ToMember returns a new member element corresponding to the action's element type, as a Member. The Name field is set according to the action's identifiers. Returns nil if the type is not a member.

func (Action) ToPrimaryFielder added in v0.9.0

func (a Action) ToPrimaryFielder() rbxdump.Fielder

ToPrimaryFielder is similar to ToFielder, but returns a new element corresponding to the action's primary element type.

func (*Action) UnmarshalJSON added in v0.7.0

func (a *Action) UnmarshalJSON(b []byte) error

type Diff

type Diff struct {
	Prev, Next *rbxdump.Root
	// If true, then each change action will have exactly one field. Otherwise,
	// an action will have all changed fields grouped together.
	SeparateFields bool
}

Diff is a Differ that finds differences between two rbxdump.Root values.

func (Diff) Diff

func (d Diff) Diff() (actions []Action)

Diff implements the Differ interface.

type DiffClass

type DiffClass struct {
	Prev, Next *rbxdump.Class
	// ExcludeMembers indicates whether members should be diffed.
	ExcludeMembers bool
	// If true, then each change action will have exactly one field. Otherwise,
	// an action will have all changed fields grouped together.
	SeparateFields bool
}

DiffClass is a Differ that finds differences between two rbxdump.Class values.

func (DiffClass) Diff

func (d DiffClass) Diff() (actions []Action)

Diff implements the Differ interface.

type DiffEnum

type DiffEnum struct {
	Prev, Next *rbxdump.Enum
	// ExcludeEnumItems indicates whether enum items should be diffed.
	ExcludeEnumItems bool
	// If true, then each change action will have exactly one field. Otherwise,
	// an action will have all changed fields grouped together.
	SeparateFields bool
}

DiffEnum is a Differ that finds differences between two rbxdump.Enum values.

func (DiffEnum) Diff

func (d DiffEnum) Diff() (actions []Action)

Diff implements the Differ interface.

type DiffEnumItem

type DiffEnumItem struct {
	// Enum is the name of the outer structure of the Prev value.
	Enum       string
	Prev, Next *rbxdump.EnumItem
	// If true, then each change action will have exactly one field. Otherwise,
	// an action will have all changed fields grouped together.
	SeparateFields bool
}

DiffEnumItem is a Differ that finds differences between two rbxdump.EnumItem values.

func (DiffEnumItem) Diff

func (d DiffEnumItem) Diff() (actions []Action)

Diff implements the Differ interface.

type DiffMember added in v0.2.0

type DiffMember struct {
	// Class is the name of the outer structure of the Prev value.
	Class      string
	Prev, Next rbxdump.Member
	// If true, then each change action will have exactly one field. Otherwise,
	// an action will have all changed fields grouped together.
	SeparateFields bool
}

DiffMember is a Differ that finds differences between two rbxdump.Member values.

func (DiffMember) Diff added in v0.2.0

func (d DiffMember) Diff() (actions []Action)

Diff implements the Differ interface.

type Differ added in v0.2.0

type Differ interface {
	Diff() []Action
}

Differ is implemented by any value that has a Diff method, which returns the differences between two structures as a list of Actions.

type Element added in v0.2.0

type Element int

Element indicates the type of element to which an Action applies.

const (
	Invalid Element
	Class
	Property
	Function
	Event
	Callback
	Enum
	EnumItem
)

func FromElement added in v0.2.0

func FromElement(e any) Element

FromElement returns the Element corresponding to the given rbxdump element type or a pointer to such. Returns Invalid for any other type.

func (Element) IsMember added in v0.2.0

func (e Element) IsMember() bool

IsMember returns whether the element is a class member.

func (Element) IsValid added in v0.2.0

func (e Element) IsValid() bool

IsValid returns whether the value is a valid element.

func (Element) MarshalJSON added in v0.3.2

func (e Element) MarshalJSON() (b []byte, err error)

func (Element) Primary added in v0.10.3

func (e Element) Primary() Element

Primary returns the primary element of this element.

func (Element) String added in v0.2.0

func (e Element) String() string

String returns a string representation of the element type.

func (*Element) UnmarshalJSON added in v0.3.2

func (e *Element) UnmarshalJSON(b []byte) error

type Inverter added in v0.8.0

type Inverter interface {
	Inverse([]Action) []Action
}

Inverter is implemented by any value that has an Inverse method, which receives a list of Actions and produces an inverse list of Actions. That is, for a list of actions P that patches structure A into B, the inverse of P will patch structure B back into A.

type Patch added in v0.2.0

type Patch struct {
	*rbxdump.Root
}

Patch is used to transform the embedded rbxdump.Root by applying a list of Actions.

func (Patch) Inverse added in v0.8.0

func (root Patch) Inverse(actions []Action) []Action

Inverse implements the Inverter interface by producing the inverse of actions according to the root.

func (*Patch) Patch added in v0.2.0

func (root *Patch) Patch(actions []Action)

Patch implements the Patcher interface.

type PatchCallback added in v0.2.0

type PatchCallback struct {
	*rbxdump.Callback
}

PatchCallback is used to transform the embedded rbxdump.Callback by applying a list of Actions.

func (*PatchCallback) Patch added in v0.2.0

func (member *PatchCallback) Patch(actions []Action)

Patch implements the Patcher interface.

type PatchClass added in v0.2.0

type PatchClass struct {
	*rbxdump.Class
}

PatchClass is used to transform the embedded rbxdump.Class by applying a list of Actions.

func (*PatchClass) Patch added in v0.2.0

func (class *PatchClass) Patch(actions []Action)

Patch implements the Patcher interface.

type PatchEnum added in v0.2.0

type PatchEnum struct {
	*rbxdump.Enum
}

PatchEnum is used to transform the embedded rbxdump.Enum by applying a list of Actions.

func (*PatchEnum) Patch added in v0.2.0

func (enum *PatchEnum) Patch(actions []Action)

Patch implements the Patcher interface.

type PatchEnumItem added in v0.2.0

type PatchEnumItem struct {
	*rbxdump.EnumItem
}

PatchEnumItem is used to transform the embedded rbxdump.EnumItem by applying a list of Actions.

func (*PatchEnumItem) Patch added in v0.2.0

func (item *PatchEnumItem) Patch(actions []Action)

Patch implements the Patcher interface.

type PatchEvent added in v0.2.0

type PatchEvent struct {
	*rbxdump.Event
}

PatchEvent is used to transform the embedded rbxdump.Event by applying a list of Actions.

func (*PatchEvent) Patch added in v0.2.0

func (member *PatchEvent) Patch(actions []Action)

Patch implements the Patcher interface.

type PatchFunction added in v0.2.0

type PatchFunction struct {
	*rbxdump.Function
}

PatchFunction is used to transform the embedded rbxdump.Function by applying a list of Actions.

func (*PatchFunction) Patch added in v0.2.0

func (member *PatchFunction) Patch(actions []Action)

Patch implements the Patcher interface.

type PatchProperty added in v0.2.0

type PatchProperty struct {
	*rbxdump.Property
}

PatchProperty is used to transform the embedded rbxdump.Property by applying a list of Actions.

func (*PatchProperty) Patch added in v0.2.0

func (member *PatchProperty) Patch(actions []Action)

Patch implements the Patcher interface.

type Patcher added in v0.2.0

type Patcher interface {
	Patch([]Action)
}

Patcher is implemented by any value that has a Patch method, which applies a given list of Actions to a structure. Actions with information that is irrelevant, incomplete, or invalid can be ignored.

Ideally, when the API's "origin" and "target" are compared with a Differ, and the returned list of Actions are passed to a Patcher, the end result is that origin is transformed to match target exactly.

Implementations must ensure that values contained within action Fields are copied, so that they are not shared between structures.

type Type added in v0.2.0

type Type int

Type indicates the kind of transformation performed by an Action.

const (
	Remove Type = -1 // The action removes data.
	Change Type = 0  // The action changes data.
	Add    Type = 1  // The action adds data.
)

func (Type) String added in v0.2.0

func (t Type) String() string

String returns a string representation of the action type.

Jump to

Keyboard shortcuts

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