markers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsStandaloneMarker

func IsStandaloneMarker(code byte) bool

IsStandaloneMarker checks if a marker has no length field. Single Responsibility: Only determines marker type.

func MarkerCodeToName

func MarkerCodeToName(code byte) string

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

func NewParser(validator Validator) *Parser

NewParser creates a new marker parser with validation support. Dependency Injection: validator is injected, allowing different validation strategies.

func (*Parser) Parse

func (p *Parser) Parse(data []byte) ([]Marker, error)

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.

Jump to

Keyboard shortcuts

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