Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsStandaloneMarker ¶
IsStandaloneMarker checks if a marker has no length field. Single Responsibility: Only determines marker type.
func MarkerCodeToName ¶
MarkerCodeToName converts JPEG marker code to human-readable name. Single Responsibility: Only maps marker codes to names.
Types ¶
type Marker ¶
type Marker struct {
// Type is the marker type (e.g., "SOI", "DQT", "DHT", "APP0", "SOF0", "SOS", "EOI")
Type string
// Position is the byte position in file where marker starts (0xFF position)
Position int
// Length is the marker segment length (including 2-byte length field, 0 for standalone markers)
Length int
// Data is the marker data payload (empty for standalone markers like SOI, EOI)
Data []byte
}
Marker represents a single JPEG marker with its position and metadata. This structure is used for parsing and analyzing JPEG file structure.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser extracts JPEG markers and their positions.
Follows SOLID principles: - Single Responsibility: Only parses markers. - Open/Closed: Extensible through interfaces. - Dependency Inversion: Depends on abstractions (interfaces).
func NewParser ¶
NewParser creates a new marker parser with validation support. Dependency Injection: validator is injected, allowing different validation strategies.
func (*Parser) Parse ¶
Parse extracts all JPEG markers from the data. Returns array of markers with positions and metadata.
JPEG Marker Structure: - All markers start with 0xFF - Followed by marker code (0x01-0xFE, 0x00 is escape) - Some markers have variable-length segments (2-byte length + data) - Standalone markers (SOI, EOI, RSTn) have no length field.
Returns:
- []Marker: Array of extracted markers.
- error: Any parsing errors.
type Validator ¶
type Validator interface {
// ValidateMarkerLength validates that a marker length is valid for the remaining data.
ValidateMarkerLength(length int, remaining int) error
// ValidatePosition validates that a position is within bounds.
ValidatePosition(pos int, maxPos int) error
// SafeAdd performs addition with overflow checking.
SafeAdd(a, b int) (int, error)
}
Validator defines an interface for input validation. This abstraction allows different validation strategies to be injected.