Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not support bool type? #39

Closed
ma91n opened this issue Jan 31, 2021 · 2 comments
Closed

does not support bool type? #39

ma91n opened this issue Jan 31, 2021 · 2 comments

Comments

@ma91n
Copy link

ma91n commented Jan 31, 2021

go-fixedwidth does not support bool type in Struct?

package main

import (
	"fmt"
	"github.com/ianlopshire/go-fixedwidth"
	"log"
	"strings"
)

func main() {

	type Book struct {
		F1 bool `fixed:"1,5,left, "`
		F2 bool `fixed:"6,10,left, "`
		F3 int  `fixed:"11,12"`
	}

	s := `true true 1
falsefalse2
true false3`

	for _, s := range strings.Split(s, "\n") {
		var b Book
		if err := fixedwidth.Unmarshal([]byte(s), &b); err != nil {
			log.Fatal(err)
		}

		fmt.Printf("%+v\n", b)
	}

}

Then output ix below.

2021/01/31 23:23:16 fixedwidth: cannot unmarshal true true 1 into Go struct field Book.F1 of type bool:fixedwidth: unknown type
exit status 1

I want support for bool types.

@ianlopshire
Copy link
Owner

ianlopshire commented Feb 1, 2021

@ma91n, You are correct. The library doesn't currently have support for the bool type. There aren't any current plans to add support but, a PR would be welcome.

If you are interested, adding support shouldn’t be a major undertaking. Here are the best places to start to add encoding and decoding support respectively:

func newValueEncoder(t reflect.Type) valueEncoder {

func newValueSetter(t reflect.Type) valueSetter {

@ianlopshire
Copy link
Owner

Resolved by #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants