edifact

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package edifact reads and writes UN/EDIFACT interchanges (ISO 9735): the UNA service string advice, the UNB/UNZ interchange envelope, optional UNG/UNE functional groups, and UNH/UNT messages, with the release character and, for syntax version 4, the repetition separator. It checks the envelope's counts and references, addresses data elements for filters, splits an interchange into one per message, and builds a CONTRL acknowledgement.

It reads any message type (ORDERS, INVOIC, IFTSTA, MEDRPT ...); it does not hold the directories that say which segments a message type may contain, so it checks structure, not content.

Index

Constants

This section is empty.

Variables

View Source
var Default = Delimiters{Component: ':', Element: '+', Decimal: '.', Release: '?', Repetition: ' ', Segment: '\''}

Default is ISO 9735's default service characters (syntax levels A and B), used when there is no UNA.

Functions

func Describe

func Describe(ic *Interchange) string

Describe names an interchange for logs: its message types and parties, never content.

func ParseFilter

func ParseFilter(src string) (expr.Expr[*Interchange], error)

ParseFilter compiles a filter expression over an interchange.

func Read

func Read(ic *Interchange, p Path) []string

Read returns every value the path addresses in the interchange.

Types

type Action

type Action string

Action is a CONTRL action code (data element 0083).

const (
	// Accepted (7): this level acknowledged, lower levels too unless reported.
	Accepted Action = "7"
	// Rejected (4): this level and everything in it rejected.
	Rejected Action = "4"
)

type Delimiters

type Delimiters struct {
	Component  byte // :
	Element    byte // +
	Decimal    byte // .
	Release    byte // ?
	Repetition byte // * in syntax 4; ' ' (none) before it
	Segment    byte // '
}

Delimiters are the service characters, from UNA or the defaults.

type Element

type Element [][]string

Element is one data element: its repetitions, each a list of components.

type Group

type Group struct {
	Header, Trailer Segment
	Messages        []Message
}

Group is a UNG ... UNE functional group.

type Interchange

type Interchange struct {
	Delims Delimiters
	// HasUNA records whether the interchange began with a service string advice, so it is written back the same way.
	HasUNA bool
	Header Segment // UNB
	// Groups is set when the interchange uses functional groups; Messages otherwise.
	Groups   []Group
	Messages []Message
	Trailer  Segment // UNZ
}

Interchange is one UNB ... UNZ interchange.

func CONTRL

func CONTRL(ic *Interchange, action Action, ourRef string, now time.Time) *Interchange

CONTRL builds the syntax and service report for an interchange: UCI naming it, accepted or rejected, from us (the interchange's recipient) back to its sender. ourRef is our own interchange reference for the CONTRL.

func Parse

func Parse(data []byte) (*Interchange, error)

Parse reads one interchange. Envelope counts are not checked here; see Check.

func Split

func Split(ic *Interchange) []*Interchange

Split returns one interchange per message, each with the original UNB (and group header) and trailers counting one.

func (*Interchange) AllMessages

func (ic *Interchange) AllMessages() []Message

AllMessages lists the messages, whether or not they are in groups.

func (*Interchange) Bytes

func (ic *Interchange) Bytes() []byte

Bytes writes the interchange, with a UNA when it arrived with one or its delimiters are not the defaults.

func (*Interchange) Recipient

func (ic *Interchange) Recipient() (id, qualifier string)

func (*Interchange) Ref

func (ic *Interchange) Ref() string

Ref is the interchange control reference (UNB 0020).

func (*Interchange) Segments

func (ic *Interchange) Segments() []Segment

Segments lists every segment in order, UNB to UNZ.

func (*Interchange) Sender

func (ic *Interchange) Sender() (id, qualifier string)

Sender and Recipient are the interchange's UNB parties (0004 and 0010) with their code qualifiers.

func (*Interchange) Syntax

func (ic *Interchange) Syntax() string

Syntax is the syntax identifier and version (UNB 0001:0002), such as UNOC:3.

type Message

type Message struct {
	// Segments runs from UNH to UNT inclusive.
	Segments []Segment
}

Message is one UNH ... UNT message.

func (Message) Ref

func (m Message) Ref() string

Ref is the message reference number (UNH 0062).

func (Message) Type

func (m Message) Type() string

Type is the message type and version, such as ORDERS:D:96A:UN.

type Path

type Path struct {
	Tag                            string
	Occurrence                     int // 0: every one
	Element, Repetition, Component int // 0: whole / every
}

Path addresses data elements, in the notation the HL7 and X12 paths here use:

BGM            the whole segment, as written
BGM-2          element 2 (every component, joined with the component separator)
BGM-1.1        element 1, component 1
NAD(2)-3.1     the second NAD, element 3, component 1
LIN-3(2).1     element 3, second repetition, component 1
UNB-2.1        the interchange sender

Element and component numbers count from 1 in the order the segment is written, which is how implementation guides number them (BGM's C002 is element 1, 1004 is element 2). A segment without a number means every occurrence.

func ParsePath

func ParsePath(s string) (Path, error)

ParsePath reads a path.

type Problem

type Problem struct {
	Where, What string
}

Problem is one thing wrong with an interchange's envelope.

func Check

func Check(ic *Interchange) []Problem

Check compares the envelope's own counts and references with what it holds: how a truncated or spliced transfer shows.

func (Problem) String

func (p Problem) String() string

type Resolver

type Resolver struct{}

Resolver addresses interchanges for the filter grammar.

func (Resolver) Prepare

func (Resolver) Prepare(raw string) (expr.Prepared[*Interchange], error)

Prepare compiles one path.

func (Resolver) Semantics

func (Resolver) Semantics() expr.Semantics

Semantics keeps ordering numeric and quotes optional, as for X12: quantities and amounts are what gets compared, and EDIFACT dates (CCYYMMDD, YYMMDD) compare correctly either way.

type Segment

type Segment struct {
	Tag      string
	Elements []Element
}

Segment is one segment: its tag and data elements.

func (Segment) Value

func (s Segment) Value(e, r, c int) string

Value returns element e (1-based), repetition r (1-based), component c (1-based), or "".

Jump to

Keyboard shortcuts

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