Documentation
¶
Overview ¶
Package compact implements a compact array-based codec for JSON Patch operations. This codec provides significant space savings compared to standard JSON format while maintaining full compatibility with all operation types.
Package compact implements a compact array-based codec for JSON Patch operations. This codec uses arrays instead of objects to represent operations, significantly reducing the physical space required for encoding while maintaining readability.
Index ¶
- Variables
- func Decode(compactOps []Op, opts ...DecoderOption) ([]internal.Op, error)
- func DecodeJSON(data []byte, opts ...DecoderOption) ([]internal.Op, error)
- func EncodeJSON(ops []internal.Op, opts ...EncoderOption) ([]byte, error)
- type Decoder
- type DecoderOption
- type DecoderOptions
- type Encoder
- type EncoderOption
- type EncoderOptions
- type JSONPatchOptions
- type Op
- type OpCode
- type Operation
Constants ¶
This section is empty.
Variables ¶
var ( // Base operation errors ErrCompactOperationMinLength = errors.New("compact operation must have at least opcode and path") ErrCompactOperationPathNotString = errors.New("compact operation path must be a string") // Operation-specific errors ErrAddOperationRequiresValue = errors.New("add operation requires value") ErrReplaceOperationRequiresValue = errors.New("replace operation requires value") ErrMoveOperationRequiresFrom = errors.New("move operation requires from path") ErrMoveOperationFromNotString = errors.New("move operation from must be a string") ErrCopyOperationRequiresFrom = errors.New("copy operation requires from path") ErrCopyOperationFromNotString = errors.New("copy operation from must be a string") ErrTestOperationRequiresValue = errors.New("test operation requires value") ErrIncOperationRequiresDelta = errors.New("inc operation requires delta") ErrIncOperationDeltaNotNumber = errors.New("inc operation delta must be a number") ErrContainsOperationRequiresValue = errors.New("contains operation requires value") ErrContainsOperationValueNotString = errors.New("contains operation value must be a string") ErrStartsOperationRequiresValue = errors.New("starts operation requires value") ErrStartsOperationValueNotString = errors.New("starts operation value must be a string") ErrEndsOperationRequiresValue = errors.New("ends operation requires value") ErrEndsOperationValueNotString = errors.New("ends operation value must be a string") )
Predefined errors for compact codec operations
var ( ErrUnsupportedOperationType = errors.New("unsupported operation type") ErrUnknownStringOpcode = errors.New("unknown string opcode") ErrInvalidOpcodeType = errors.New("invalid opcode type") ErrUnknownNumericOpcode = errors.New("unknown numeric opcode") )
Base errors for dynamic data
var ( // NewEncoder creates a new compact encoder with the given options NewCompactEncoder = NewEncoder // NewDecoder creates a new compact decoder with the given options NewCompactDecoder = NewDecoder // EncodeCompact encodes operations into compact format using default options EncodeCompact = Encode // DecodeCompact decodes compact format operations using default options DecodeCompact = Decode // EncodeCompactJSON encodes operations into compact format JSON bytes EncodeCompactJSON = EncodeJSON // DecodeCompactJSON decodes compact format JSON bytes into operations DecodeCompactJSON = DecodeJSON )
Re-export main functions for convenience
var ( DefaultEncoderOptions = EncoderOptions{ StringOpcode: false, } DefaultDecoderOptions = DecoderOptions{} )
Default options
Functions ¶
func Decode ¶
func Decode(compactOps []Op, opts ...DecoderOption) ([]internal.Op, error)
Decode decodes compact format operations using default options
func DecodeJSON ¶
func DecodeJSON(data []byte, opts ...DecoderOption) ([]internal.Op, error)
DecodeJSON decodes compact format JSON bytes into operations
func EncodeJSON ¶
func EncodeJSON(ops []internal.Op, opts ...EncoderOption) ([]byte, error)
EncodeJSON encodes operations into compact format JSON bytes
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes compact format operations into operation instances
func NewDecoder ¶
func NewDecoder(opts ...DecoderOption) *Decoder
NewDecoder creates a new compact decoder with the given options
type DecoderOption ¶
type DecoderOption func(*DecoderOptions)
DecoderOption is a functional option for configuring the decoder
type DecoderOptions ¶
type DecoderOptions struct {
}
DecoderOptions configures the compact decoder behavior
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes operations into compact format
func NewEncoder ¶
func NewEncoder(opts ...EncoderOption) *Encoder
NewEncoder creates a new compact encoder with the given options
type EncoderOption ¶
type EncoderOption func(*EncoderOptions)
EncoderOption is a functional option for configuring the encoder
func WithStringOpcode ¶
func WithStringOpcode(useString bool) EncoderOption
WithStringOpcode configures the encoder to use string opcodes
type EncoderOptions ¶
type EncoderOptions struct {
// StringOpcode determines whether to use string opcodes instead of numeric ones
StringOpcode bool
}
EncoderOptions configures the compact encoder behavior
type JSONPatchOptions ¶ added in v0.4.3
JSONPatchOptions contains options for JSON Patch operations.
type Op ¶ added in v0.4.3
type Op []interface{}
Op represents a compact format operation as an array
type OpCode ¶
type OpCode int
OpCode represents operation codes for compact format
const ( // JSON Patch (RFC 6902) operations - match internal/constants.go OpCodeAdd OpCode = 0 OpCodeRemove OpCode = 1 OpCodeReplace OpCode = 2 OpCodeCopy OpCode = 3 OpCodeMove OpCode = 4 OpCodeTest OpCode = 5 // String editing OpCodeStrIns OpCode = 6 OpCodeStrDel OpCode = 7 // Extra OpCodeFlip OpCode = 8 OpCodeInc OpCode = 9 // Slate.js OpCodeSplit OpCode = 10 OpCodeMerge OpCode = 11 OpCodeExtend OpCode = 12 // JSON Predicate operations OpCodeContains OpCode = 30 OpCodeDefined OpCode = 31 OpCodeEnds OpCode = 32 OpCodeIn OpCode = 33 OpCodeLess OpCode = 34 OpCodeMatches OpCode = 35 OpCodeMore OpCode = 36 OpCodeStarts OpCode = 37 OpCodeUndefined OpCode = 38 OpCodeTestType OpCode = 39 OpCodeTestString OpCode = 40 OpCodeTestStringLen OpCode = 41 OpCodeType OpCode = 42 OpCodeAnd OpCode = 43 OpCodeNot OpCode = 44 OpCodeOr OpCode = 45 )
Operation codes for compact format
type Operation ¶
type Operation = internal.CompactOperation
Operation represents a compact format operation.