pic

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: MIT Imports: 8 Imported by: 0

README

go-pic

COBOL PIC (Picture) clause parsing library

Go Report Card GoDoc Sourcegraph Release License

Install

Get started using gopic by installing the struct-generation tool from the root directory by running:

$ make install

Tag-based unmarshalling

gopic's main focus is enabling simpler 1:1 mapping of PIC definitions to Go structs.

For example, if your PIC definitions look like:

000180             15  DUMMY-1      PIC 9(4).               00000117
000190             15  DUMMY-2      PIC X.                  00000118
000340             15  DUMMY-3      PIC 9(4).               00000133
000350             15  DUMMY-4      PIC X(40).              00000134
000360             15  DUMMY-5      PIC X(40).              00000135

You can create a struct with the following tags to unmarshal your data into.

package dummy 

type Copybook struct{
    Dummy1 int      `pic:"4"`
    Dummy2 string   `pic:"1"`
    Dummy3 int      `pic:"4"`
    Dummy4 string   `pic:"40"`
    Dummy5 string   `pic:"40"`
}

Or you can make use of gopics other feature below, so that you don't have to define the struct yourself...

Generating tagged 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.

cmd contains go struct generation tool from textual PIC definitions

Example struct gen usage:

A file:
$ gopic file -o mycopybookstruct -i cobolstuff/copybook.txt

A directory of files:
$ gopic dir -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 struct above, if generated with gopic becomes:

type Copybook struct{
    Dummy1 int      `pic:"4"`  // start:1 end:4
    Dummy2 string   `pic:"1"`  // start:5 end:5
    Dummy3 int      `pic:"4"`  // start:6 end:9
    Dummy4 string   `pic:"40"` // start:10 end:49
    Dummy5 string   `pic:"40"` // start:50 end:89
}

where the values...

Dummy1 int      `pic:"4"` // start:1 end:4

Represent:

  • 4 = length
  • 1 = start index
  • 4 = ending index

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

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

Types

type Decoder

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

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

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
}

func (*UnmarshalTypeError) Error

func (e *UnmarshalTypeError) Error() string

Directories

Path Synopsis
cmd
nolint
nolint

Jump to

Keyboard shortcuts

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