Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Marshaler ¶
type Marshaler struct {
// contains filtered or unexported fields
}
Marshaler is the place fixed-width encoding happen
func NewMarshaler ¶
func NewMarshaler() *Marshaler
NewMarshaler create new Marshaler When creating new Marshaler, you should consider b field
func (*Marshaler) Marshal ¶
Marshal returns the fixed-width encoding of v.
v should be struct or a slice of struct.
Each field in a struct need to be defined a `fixed` tag. The `fixed` tag indicates the maximum width of current field.
If v is slice of struct, Marshal will return multi lines separated by new line character (\n).
Example ¶
p := person{ FirstName: "Alexander", LastName: "Goodword", Age: 40, Job: "Software Engineer", } m := NewMarshaler() b, err := m.Marshal(p) if err != nil { log.Fatal(err) } fmt.Print(string(b))
Output: Alexander Goodword 40 Software
type Unmarshaler ¶
type Unmarshaler struct {
// contains filtered or unexported fields
}
Unmarshaler is the place fixed-width decoding happen
func (Unmarshaler) Unmarshal ¶
func (m Unmarshaler) Unmarshal(data []byte, model interface{}) error
Unmarshal decodes fixed-width encoding data to model, model is required to be a pointer.
Example ¶
var p person m := NewUnmarshaler() err := m.Unmarshal([]byte("Alexander Goodword 40 Software"), &p) if err != nil { log.Fatal(err) } fmt.Printf("%+v", p)
Output: {FirstName:Alexander LastName:Goodword Age:40 Job:Software}
Click to show internal directories.
Click to hide internal directories.