func (v Value) Equal(w Value) bool {
	if v.Type != w.Type {
		return false
	}
	switch v.Type {
	case ValueTypeData:
		return bytes.Equal(v.Inner, w.Inner)
	case ValueTypePrimitive:
		return bytes.Equal(v.RawMessage, w.RawMessage)
	case ValueTypeReference:
		fallthrough
	case ValueTypeSoftReference:
		return v.RID == w.RID
	}
	return true
}
Equal reports whether v and w is equal in type and value
package store
import (
	"bytes"
	"encoding/json"
	"errors"
	res "github.com/jirenius/go-res"
)
type ValueType byte
const (
	ValueTypeNone ValueType = iota
	ValueTypePrimitive
	ValueTypeReference
	ValueTypeSoftReference
	ValueTypeData
	ValueTypeDelete
	ValueTypeResource = ValueTypeReference
)
type valueObject struct {
	RID    *string         `json:"rid"`
	Soft   bool            `json:"soft"`
	Action *string         `json:"action"`
	Data   json.RawMessage `json:"data"`
}
var DeleteValue = Value{
	RawMessage: json.RawMessage(`{"action":"delete"}`),
	Type:       ValueTypeDelete,
}
type Value struct {
	json.RawMessage
	Type  ValueType
	RID   string
	Inner json.RawMessage
}
var errInvalidValue = errors.New("invalid value")
const (
	actionDelete = "delete"
)
func (v *Value) UnmarshalJSON(data []byte) error {
	err := v.RawMessage.UnmarshalJSON(data)
	if err != nil {
		return err
	}
	var c byte
	i := 0
	for {
		c = v.RawMessage[i]
		if c != 0x20 && c != 0x09 && c != 0x0A && c != 0x0D {
			break
		}
		i++
	}
	switch c {
	case '{':
		var mvo valueObject
		err = json.Unmarshal(v.RawMessage, &mvo)
		if err != nil {
			return err
		}
		switch {
		case mvo.RID != nil:
			if mvo.Action != nil || mvo.Data != nil || *mvo.RID == "" {
				return errInvalidValue
			}
			v.RID = *mvo.RID
			if !res.Ref(v.RID).IsValid() {
				return errInvalidValue
			}
			if mvo.Soft {
				v.Type = ValueTypeSoftReference
			} else {
				v.Type = ValueTypeReference
			}
		case mvo.Action != nil:
			if mvo.Data != nil || *mvo.Action != actionDelete {
				return errInvalidValue
			}
			v.Type = ValueTypeDelete
		case mvo.Data != nil:
			v.Inner = mvo.Data
			dc := mvo.Data[0]
			if dc == '{' || dc == '[' {
				v.Type = ValueTypeData
			} else {
				v.RawMessage = mvo.Data
				v.Type = ValueTypePrimitive
			}
		default:
			return errInvalidValue
		}
	case '[':
		return errInvalidValue
	default:
		v.Type = ValueTypePrimitive
	}
	return nil
}
func (v Value) MarshalJSON() ([]byte, error) {
	if v.RawMessage == nil {
		return []byte("null"), nil
	}
	return v.RawMessage, nil
}