Documentation
¶
Index ¶
- Constants
- Variables
- func ComputeChecksum(initial uint32, data []byte) uint32
- func Decode(source []byte, delta []byte) ([]byte, error)
- func ReadVarint(reader *bytes.Reader) (uint32, error)
- type AddressCache
- type Adler32
- type CodeTable
- type Decoder
- type Header
- type Instruction
- type InstructionEntry
- type InstructionTable
- type InstructionType
- type LegacyInstruction
- type ParsedDelta
- type RuntimeInstruction
- type Window
Constants ¶
const ( SelfMode = 0 HereMode = 1 )
const ( VCDIFFMagic1 = 0xD6 // First magic byte: 'V' with high bit set VCDIFFMagic2 = 0xC3 // Second magic byte: 'C' with high bit set VCDIFFMagic3 = 0xC4 // Third magic byte: 'D' with high bit set VCDIFFVersion = 0x00 // Version 0 as defined in RFC 3284 )
VCDIFF magic bytes and version - RFC 3284 Section 4.1
const ( VCDDecompress = 0x01 // VCD_DECOMPRESS: secondary compression used VCDCodetable = 0x02 // VCD_CODETABLE: custom instruction table used VCDAppHeader = 0x04 // VCD_APPHEADER: application header present )
Header indicator flags - RFC 3284 Section 4.1
const ( VCDSource = 0x01 // VCD_SOURCE: window uses source data VCDTarget = 0x02 // VCD_TARGET: window uses target data VCDAdler32 = 0x04 // VCD_ADLER32: window includes Adler-32 checksum (non-standard extension) )
Window indicator flags - RFC 3284 Section 4.2
const ( VarintContinuationBit = 0x80 // High bit indicates continuation VarintValueMask = 0x7F // Mask for 7-bit value portion VarintMaxShift = 32 // Maximum shift to prevent overflow VarintShiftIncrement = 7 // Bits to shift for each byte )
Variable-length integer encoding constants - RFC 3284 Section 2
const ( RunInstructionMin = 0 // RUN instructions: 0-17 RunInstructionMax = 17 // RUN instructions: 0-17 AddInstructionMin = 18 // ADD instructions: 18-161 AddInstructionMax = 161 // ADD instructions: 18-161 CopyInstructionMin = 162 // COPY instructions: 162-255 CopyInstructionMax = 255 // COPY instructions: 162-255 )
Instruction code ranges - RFC 3284 Section 5
const ( NearCacheSize = 4 // Size of "near" address cache SameCacheSize = 3 * 256 // Size of "same" address cache InstructionTableSize = 256 // Size of instruction code table )
Address cache configuration - RFC 3284 Section 5.3
const ( VCDAdd = iota VCDCopy VCDRun VCDNoop )
const (
MinimumFileSize = 4 // Minimum VCDIFF file size (magic + version)
)
File format validation constants
Variables ¶
var ( ErrInvalidMagic = errors.New("invalid VCDIFF magic bytes") ErrInvalidVersion = errors.New("unsupported VCDIFF version") ErrInvalidFormat = errors.New("invalid VCDIFF format") ErrCorruptedData = errors.New("corrupted VCDIFF data") ErrInvalidChecksum = errors.New("invalid checksum") )
var DefaultCodeTable = BuildDefaultCodeTable()
DefaultCodeTable is the default code table instance
var VCDIFFMagic = [3]byte{VCDIFFMagic1, VCDIFFMagic2, VCDIFFMagic3}
VCDIFFMagic is the expected magic number sequence - RFC 3284 Section 4.1
Functions ¶
func ComputeChecksum ¶
ComputeChecksum computes the Adler32 checksum for the given data
func ReadVarint ¶
ReadVarint reads a variable-length integer as defined in RFC 3284 Section 2 Follows the same algorithm as the C# MiscUtil reference implementation
Types ¶
type AddressCache ¶
type AddressCache struct {
// contains filtered or unexported fields
}
AddressCache manages address encoding/decoding for COPY instructions
func NewAddressCache ¶
func NewAddressCache(nearSize, sameSize int) *AddressCache
NewAddressCache creates a new address cache with the specified sizes
func (*AddressCache) DecodeAddress ¶
func (ac *AddressCache) DecodeAddress(here uint32, mode byte) (uint32, error)
DecodeAddress decodes an address using the specified mode
func (*AddressCache) Reset ¶
func (ac *AddressCache) Reset(addresses []byte)
Reset resets the address cache for a new window
func (*AddressCache) Update ¶
func (ac *AddressCache) Update(address uint32)
Update updates the address cache with a new address
type CodeTable ¶
type CodeTable struct {
// contains filtered or unexported fields
}
CodeTable represents the VCDIFF instruction code table
func BuildDefaultCodeTable ¶
func BuildDefaultCodeTable() *CodeTable
BuildDefaultCodeTable creates the default code table specified in RFC 3284
type Decoder ¶
func NewDecoder ¶
type Instruction ¶
type Instruction struct {
Type InstructionType
Size byte
Mode byte
}
Instruction represents a single VCDIFF instruction from the code table
func NewInstruction ¶
func NewInstruction(instrType InstructionType, size byte, mode byte) Instruction
NewInstruction creates a new instruction
type InstructionEntry ¶
type InstructionTable ¶
type InstructionTable struct {
Entries [InstructionTableSize]InstructionEntry
}
type InstructionType ¶
type InstructionType byte
InstructionType represents the type of VCDIFF instruction
const ( NoOp InstructionType = 0 Add InstructionType = 1 Run InstructionType = 2 Copy InstructionType = 3 )
func (InstructionType) String ¶
func (it InstructionType) String() string
String returns string representation of instruction type
type LegacyInstruction ¶
Legacy instruction type for backwards compatibility
type ParsedDelta ¶
type ParsedDelta struct {
Header Header
Windows []Window
Instructions []RuntimeInstruction
}
func ParseDelta ¶
func ParseDelta(delta []byte) (*ParsedDelta, error)
ParseDelta parses a VCDIFF delta and returns a structured representation
type RuntimeInstruction ¶
type RuntimeInstruction struct {
Type InstructionType
Size uint32
Mode byte
Addr uint32
Data []byte
}
RuntimeInstruction represents an instruction with resolved size during decoding
type Window ¶
type Window struct {
WinIndicator byte // Win_Indicator - RFC 3284 Section 4.2
SourceSegmentSize uint32 // Source segment size - RFC 3284 Section 4.2
SourceSegmentPosition uint32 // Source segment position - RFC 3284 Section 4.2
TargetWindowLength uint32 // Length of the target window - RFC 3284 Section 4.3
DeltaEncodingLength uint32 // Length of the delta encoding - RFC 3284 Section 4.3
DeltaIndicator byte // Delta_Indicator - RFC 3284 Section 4.3
DataSectionLength uint32 // Length of data for ADDs and RUNs - RFC 3284 Section 4.3
InstructionSectionLength uint32 // Length of instructions section - RFC 3284 Section 4.3
AddressSectionLength uint32 // Length of addresses for COPYs - RFC 3284 Section 4.3
DataSection []byte // Data section for ADDs and RUNs - RFC 3284 Section 4.3
InstructionSection []byte // Instructions and sizes section - RFC 3284 Section 4.3
AddressSection []byte // Addresses section for COPYs - RFC 3284 Section 4.3
Checksum uint32 // Adler-32 checksum of target window (VCD_ADLER32 extension)
HasChecksum bool // Whether VCD_ADLER32 bit is set in WinIndicator
}