streaming

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

pkg/domain/streaming/csv_parser.go

Package streaming provides token-based stream parsers for JSON, XML, and CSV. Parsers process data incrementally without loading entire documents into memory.

pkg/domain/streaming/json_parser.go

pkg/domain/streaming/stream.go

pkg/domain/streaming/xml_parser.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVParser

type CSVParser struct {
	// contains filtered or unexported fields
}

CSVParser parses CSV from a stream

func NewCSVParser

func NewCSVParser(hasHeaders bool) *CSVParser

func (*CSVParser) Format

func (p *CSVParser) Format() string

func (*CSVParser) GetStats

func (p *CSVParser) GetStats() MemoryStats

func (*CSVParser) Parse

func (p *CSVParser) Parse(ctx context.Context, reader io.Reader, handler TokenHandler) error

Parse reads CSV stream line by line

type CSVToken

type CSVToken struct {
	// contains filtered or unexported fields
}

CSVToken represents a single CSV token (row or field)

func (*CSVToken) Path

func (t *CSVToken) Path() string

func (*CSVToken) Size

func (t *CSVToken) Size() int64

func (*CSVToken) Type

func (t *CSVToken) Type() string

func (*CSVToken) Value

func (t *CSVToken) Value() any

type JSONParser

type JSONParser struct {
	// contains filtered or unexported fields
}

JSONParser parses JSON from a stream using token-based approach

func NewJSONParser

func NewJSONParser() *JSONParser

func (*JSONParser) Format

func (p *JSONParser) Format() string

func (*JSONParser) GetStats

func (p *JSONParser) GetStats() MemoryStats

func (*JSONParser) Parse

func (p *JSONParser) Parse(ctx context.Context, reader io.Reader, handler TokenHandler) error

Parse reads JSON stream and calls handler for each token Uses json.Decoder for streaming to avoid loading entire document

type JSONToken

type JSONToken struct {
	// contains filtered or unexported fields
}

JSONToken represents a single JSON token

func (*JSONToken) Path

func (t *JSONToken) Path() string

func (*JSONToken) Size

func (t *JSONToken) Size() int64

func (*JSONToken) Type

func (t *JSONToken) Type() string

func (*JSONToken) Value

func (t *JSONToken) Value() any

type MemoryStats

type MemoryStats struct {
	BytesRead       int64
	TokensProcessed int64
	PeakMemory      int64
	MaxTokenSize    int64
}

MemoryStats tracks memory usage during streaming

type Parser

type Parser interface {
	// Parse reads from reader and yields tokens through callback
	// Returns error if parsing fails
	Parse(ctx context.Context, reader io.Reader, handler TokenHandler) error

	// Format returns the format name (json, xml, csv)
	Format() string
}

Parser transforms a stream into tokens

type StreamProcessor

type StreamProcessor interface {
	// ProcessStream reads stream and applies transformers to each token
	ProcessStream(ctx context.Context, reader io.Reader, transformers []any) (any, error)

	// GetStats returns memory statistics
	GetStats() MemoryStats
}

StreamProcessor handles high-level stream operations

type Token

type Token interface {
	// Type returns the token type (object, array, string, number, etc)
	Type() string

	// Value returns the token value
	Value() any

	// Path returns the JSON path to this token (e.g., "user.name")
	Path() string

	// Size returns the approximate memory size in bytes
	Size() int64
}

Token represents a single parsed token from a stream

type TokenHandler

type TokenHandler func(token Token) error

TokenHandler is called for each token during parsing

type XMLParser

type XMLParser struct {
	// contains filtered or unexported fields
}

XMLParser parses XML from a stream using token-based approach

func NewXMLParser

func NewXMLParser() *XMLParser

func (*XMLParser) Format

func (p *XMLParser) Format() string

func (*XMLParser) GetStats

func (p *XMLParser) GetStats() MemoryStats

func (*XMLParser) Parse

func (p *XMLParser) Parse(ctx context.Context, reader io.Reader, handler TokenHandler) error

Parse reads XML stream using xml.Decoder for efficient streaming

type XMLToken

type XMLToken struct {
	// contains filtered or unexported fields
}

XMLToken represents a single XML token

func (*XMLToken) Path

func (t *XMLToken) Path() string

func (*XMLToken) Size

func (t *XMLToken) Size() int64

func (*XMLToken) Type

func (t *XMLToken) Type() string

func (*XMLToken) Value

func (t *XMLToken) Value() any

Jump to

Keyboard shortcuts

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