Giter Club home page Giter Club logo

hedi's Introduction

Hedi

Hedi is a library for interacting with Electronic Data Interchange (EDI) messages.

PkgGoDev Tests License: MIT


Installation

go get github.com/pbjer/hedi

Usage

Lexing

msg := "ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>~"
reader := strings.NewReader(msg)
lexer := hedi.NewLexer(reader)
tokens, err := lexer.Tokens()
if err != nil {
  // ...
}

Parsing

msg := "ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>~"
reader := strings.NewReader(msg)
parser := hedi.NewParser(reader)
segments, err := parser.Segments()
if err != nil {
  // ...
}

Serialization

Stringer

Hedi's EDI types implement the String() string stringer interface for simple string serialization.

To override the default delimiters, you can use DString(d hedi.Delimiters) string, which Stringer depends on under the hood.

segments := hedi.Segments{{
  ID: "ST",
  Elements: hedi.Elements{{ Value: "850" }, { Value: "000000010" }},
}}

fmt.Println(segments)
// ST*850*000000010~

delimiters := hedi.Delimeters{
  Segment: '\n',
  Element: '|',
  SubElement: '>',
}
	
fmt.Println(segments.DString(delimiters))
// ST|850|000000010
//

WriterTo

Hedi's Segments EDI type implements the WriterTo interface for efficient string serialization to an io.Writer.

To override the default delimiters, you can use DWriteTo(d hedi.Delimiters, w io.Writer) (int64, error), which WriteTo depends on under the hood.

file, _ := os.Create("850.txt")
if err != nil {
  // ...
}
defer file.Close()

segments := hedi.Segments{{
  ID: "ST",
  Elements: hedi.Elements{{ Value: "850" }, { Value: "000000010" }},
}}

_, err = segments.WriteTo(file)
if err != nil {
  // ...
}

hedi's People

Contributors

pbjer avatar

Stargazers

Michael Chrisco avatar Keith Weaver avatar Adam  avatar Clayton Kehoe avatar Samuel B avatar Noah Jamison avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.