Documentation
¶
Overview ¶
Package fixedwidth provides encoding and decoding for fixed-width formatted Data.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unmarshal ¶
Unmarshal parses the fixed width encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.
Example ¶
// Define some fixed-with data to parse data := []byte("" + "1 Ian Lopshire" + "\n" + "2 John Doe" + "\n" + "3 Jane Doe" + "\n") // Define the format as a struct. // The fixed start and end position are defined via struct tags: `fixed:"{startPos},{endPos}"`. // Positions start at 1, the the interval is inclusive. var people []struct { ID int `fixed:"1,10"` FirstName string `fixed:"11,30"` LastName string `fixed:"31,50"` } err := fixedwidth.Unmarshal(data, &people) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", people[0]) fmt.Printf("%+v\n", people[1]) fmt.Printf("%+v\n", people[2])
Output: {ID:1 FirstName:Ian LastName:Lopshire} {ID:2 FirstName:John LastName:Doe} {ID:3 FirstName:Jane LastName:Doe}
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes fixed width data from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
type InvalidUnmarshalError ¶
An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
type UnmarshalTypeError ¶
type UnmarshalTypeError struct { Value string // the 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 }
An UnmarshalTypeError describes a value that was not appropriate for a value of a specific Go type.
func (*UnmarshalTypeError) Error ¶
func (e *UnmarshalTypeError) Error() string
Click to show internal directories.
Click to hide internal directories.