pic

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 9 Imported by: 0

README

📺 go-pic

COBOL PIC (Picture) clause parsing library

Go Report Card GoDoc Sourcegraph Release License

🤷🏽‍ What is go-pic

gopic is both a tool and package, it's purpose is to help you process COBOL copybook files with ease

📤 Unmarshaller

gopic can be used to enable simpler 1:1 mapping of PIC definitions to Go structs.

Simply open your data file and pass it to a gopic decoder with the struct that represents the source copybook

Show usage
  1. Import gopic

    import (
        pic "github.com/foundatn-io/go-pic"
    )
    
  2. Tag your structs

    Say your copybook data looks like

    000180      15  PropertyA    PIC X(5).     00000117
    000190      15  PropertyB    PIC X(2).     00000118
    

    You would tag your struct like so

    type yourStruct struct {
        PropertyA string `pic:"5"` 
        PropertyB string `pic:"2"`
    }
    
  3. Prepare a decoder and unmarshal your input

    d := pic.NewDecoder(f) // where f is your io.Reader / data
    typ := yourStruct{} // with pic tags
    if err := d.Decode(typ); err != nil {
            log.Fatal(err)
    }
    
📥 Struct generator

gopic can be used to generate simpler 1:1 mapping of PIC definitions to Go structs.

gopic provides support to generate flattened Go struct representations of your COBOL copybooks, tagged with length statements and assigned the appropriate type for unmarshalling files that match your COBOL copybook definitions, so you need not manually create or tag your structs when using go-pic for unmarshalling.

Show usage
  1. Install gopic!

    Get started using gopic by for struct generation by running:

    git clone github.com/foundatn-io/go-pic
    cd go-pic
    make install
    
  2. Generate structs from a copybook file (long-form flags)

    gopic file --package=shipping --output=shipping --input=cobolstuff/copybook-shipping.txt
    
  3. Generate many structs from a directory containing only copybooks (short-form flags)

    gopic dir -p mystructsdir -o mystructsdir -i cobolstuff
    

When using gopic for struct generation, additional, non-functional values are tagged to the PIC tags, for legibility's sake.

For example, the example copybook clauses:

000180      15  PropertyA    PIC 9(5).     00000117
000190      15  PropertyB    PIC X(2).     00000118

if generated with gopic becomes:

type Copybook struct{
    PropertyA uint      `pic:"9"`  // start:1 end:9
    PropertyB string    `pic:"2"`  // start:10 end:11
}
🚧 Alas, these are not yet supported
  • PIC symbols [ S, V, P ]
  • Level indicator 88 enums are skipped
  • Level indicator 77 items which cannot be sub-divided

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNilPointer = errors.New("decode: unmarshal target object is nil")

ErrNilPointer is returned when the target object is nil.

View Source
var ErrNotAPointer = errors.New("decode: unmarshal target object is not a pointer")

ErrNotAPointer is returned when the target object is not a pointer.

Functions

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal accepts input data, and a destination object it will build a new decoder and decode the input into the target object.

Types

type Decoder

type Decoder interface {
	Decode(interface{}) error
}

Decoder ...

func NewDecoder

func NewDecoder(r io.Reader) Decoder

NewDecoder builds a new decoder using a bufio.Scanner for the given input io.Reader.

type UnmarshalTypeError

type UnmarshalTypeError struct {
	Value  string       // raw value
	Type   reflect.Type // type of Go value it could not be assigned to
	Struct string       // name of the struct type containing the field
	Field  string       // name of the field holding the Go value
	Cause  error        // original error
}

UnmarshalTypeError represents an unmarshal malfunction

func (*UnmarshalTypeError) Error

func (e *UnmarshalTypeError) Error() string

Error converts details of an UnmarshalTypeError into a meaningful string

Directories

Path Synopsis
cmd
nolint
nolint
egdirout
nolint
nolint
pkg
lex

Jump to

Keyboard shortcuts

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