Closed nOBITa3001 closed 2 years ago
You can implement edifact.Unmarshaller
for the type of a struct field. A basic example is in unmarshal_orders_test.go:58. When leaving out the ?
placeholder completely UnmarshalEdifact
will be called with the entire segment.
Something like this:
type Container struct {
ISO ISO `edifact:"SG2/SG3/EQD+CN"` // tag has no '?'
}
type ISO string
func (iso *ISO) UnmarshalEdifact(data []byte) error {
// parse iso from data
}
Edit:
A *
to return a composite is a good idea. Could be useful together with edifact.Unmarshaller
or on its own.
ISO string `edifact:"SG2/SG3/EQD+CN++*"`
Hello @shogg
I can make it works based on the guidance
Thank you!
@nOBITa3001 I just pushed a new version with '*' placeholder support.
@shogg
pulled the new version and applied a change. It works like a charm!
Thank you very much
Hello @shogg
Is it possible to read values from multiple elements for a composite I saw the matching logic supports 1 element value here - https://github.com/shogg/edifact/blob/1efb937895bd29fa85d2e43e568c3cb31e804b76/build/segmentselector.go#L94
For example, I have this segment
EQD+CN+CSNU1487660+22G1:102:5++2+5'
and would like to get this22G1:102:5
value with 1 field. I could not find a document for edifact mapping definition so I just map 1 field on each elementIs there a way to map all elements to 1 field solution or any document that I can find on how to define the edifact definition for this. Expected something like a wildcard: