model

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EDIFACTConfig

type EDIFACTConfig struct {
	SegmentTerminator  string
	ElementSeparator   string
	ComponentSeparator string
	ReleaseCharacter   string
}

EDIFACTConfig holds configuration for EDIFACT parsing

func DefaultConfig

func DefaultConfig() EDIFACTConfig

DefaultConfig returns the default EDIFACT configuration

type Element

type Element struct {
	Value       string
	Components  []string // For composite elements
	IsComposite bool
}

Element represents an EDIFACT element (simple or composite)

func (*Element) String

func (e *Element) String() string

String returns the string representation of an element

type GenericElement

type GenericElement struct {
	Position       int      `json:"position"`
	Value          string   `json:"value"`
	Components     []string `json:"components"`
	IsComposite    bool     `json:"is_composite"`
	ComponentCount int      `json:"component_count"`
}

GenericElement represents a generic EDIFACT element

type GenericMessage

type GenericMessage struct {
	MessageType    string           `json:"message_type"`
	MessageRef     string           `json:"message_ref"`
	Segments       []GenericSegment `json:"segments"`
	RawContent     string           `json:"raw_content"`
	SegmentCount   int              `json:"segment_count"`
	ElementCount   int              `json:"element_count"`
	ComponentCount int              `json:"component_count"`
}

GenericMessage represents a generic EDIFACT message that can handle any message type

func (*GenericMessage) Flatten

func (m *GenericMessage) Flatten() map[string]interface{}

Flatten returns a flattened representation of all elements

func (*GenericMessage) GetSegmentByTag

func (m *GenericMessage) GetSegmentByTag(tag string) *GenericSegment

GetSegmentByTag returns the first segment with the given tag

func (*GenericMessage) GetSegmentsByTag

func (m *GenericMessage) GetSegmentsByTag(tag string) []*GenericSegment

GetSegmentsByTag returns all segments with the given tag

func (*GenericMessage) String

func (m *GenericMessage) String() string

String returns a string representation of the generic message

func (*GenericMessage) ToJSON

func (m *GenericMessage) ToJSON() ([]byte, error)

ToJSON converts the generic message to JSON

func (*GenericMessage) ToJSONString

func (m *GenericMessage) ToJSONString() (string, error)

ToJSONString converts the generic message to a JSON string

type GenericMessageBuilder

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

GenericMessageBuilder helps build generic messages

func NewGenericMessageBuilder

func NewGenericMessageBuilder() *GenericMessageBuilder

NewGenericMessageBuilder creates a new generic message builder

func (*GenericMessageBuilder) AddSegment

func (b *GenericMessageBuilder) AddSegment(tag string, elements []GenericElement, rawString string) *GenericMessageBuilder

AddSegment adds a segment to the message

func (*GenericMessageBuilder) Build

Build returns the built generic message

func (*GenericMessageBuilder) SetMessageRef

func (b *GenericMessageBuilder) SetMessageRef(msgRef string) *GenericMessageBuilder

SetMessageRef sets the message reference

func (*GenericMessageBuilder) SetMessageType

func (b *GenericMessageBuilder) SetMessageType(msgType string) *GenericMessageBuilder

SetMessageType sets the message type

func (*GenericMessageBuilder) SetRawContent

func (b *GenericMessageBuilder) SetRawContent(content string) *GenericMessageBuilder

SetRawContent sets the raw EDIFACT content

type GenericSegment

type GenericSegment struct {
	Tag          string           `json:"tag"`
	Elements     []GenericElement `json:"elements"`
	ElementCount int              `json:"element_count"`
	Position     int              `json:"position"`
	RawString    string           `json:"raw_string"`
}

GenericSegment represents a generic EDIFACT segment

func (*GenericSegment) GetComponentValue

func (s *GenericSegment) GetComponentValue(elementPosition, componentPosition int) string

GetComponentValue returns the value of a specific component in an element

func (*GenericSegment) GetElement

func (s *GenericSegment) GetElement(position int) *GenericElement

GetElement returns the element at the specified position (1-based)

func (*GenericSegment) GetElementComponents

func (s *GenericSegment) GetElementComponents(position int) []string

GetElementComponents returns the components of an element at the specified position

func (*GenericSegment) GetElementValue

func (s *GenericSegment) GetElementValue(position int) string

GetElementValue returns the value of an element at the specified position

type Message

type Message struct {
	Type       string
	Segments   []Segment
	RawContent string
}

Message represents a complete EDIFACT message

func (*Message) GetSegmentByTag

func (m *Message) GetSegmentByTag(tag string) *Segment

GetSegmentByTag returns the first segment with the given tag

func (*Message) GetSegmentsByTag

func (m *Message) GetSegmentsByTag(tag string) []*Segment

GetSegmentsByTag returns all segments with the given tag

type MessageHandler

type MessageHandler interface {
	Handle(message *Message) (interface{}, error)
	CanHandle(messageType string) bool
}

MessageHandler defines the interface for message-specific handlers

type ParseError

type ParseError struct {
	Message string
	Line    int
	Column  int
	Token   *Token
}

ParseError represents a parsing error

func (*ParseError) Error

func (e *ParseError) Error() string

type Segment

type Segment struct {
	Tag      string
	Elements []Element
}

Segment represents an EDIFACT segment

func (*Segment) GetElement

func (s *Segment) GetElement(position int) *Element

GetElement returns the element at the specified position (1-based)

func (*Segment) String

func (s *Segment) String() string

String returns the string representation of a segment

type Token

type Token struct {
	Type   TokenType
	Value  string
	Line   int
	Column int
}

Token represents a tokenized piece of EDIFACT data

type TokenType

type TokenType int

TokenType represents the type of token

const (
	TokenSegment TokenType = iota
	TokenElement
	TokenComponent
	TokenRelease
	TokenTerminator
)

func (TokenType) String

func (t TokenType) String() string

String returns the string representation of the token type

Jump to

Keyboard shortcuts

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