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 (*CSVParser) GetStats ¶
func (p *CSVParser) GetStats() MemoryStats
type CSVToken ¶
type CSVToken struct {
// contains filtered or unexported fields
}
CSVToken represents a single CSV token (row or field)
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
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 ¶
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) GetStats ¶
func (p *XMLParser) GetStats() MemoryStats