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

Marshal, unmarshal. cql types: tinyint, smallint, int can not be marshaled into go big.Int #244

Open
illia-li opened this issue Aug 27, 2024 · 0 comments
Assignees
Labels

Comments

@illia-li
Copy link

Currently Unmarshaling functions for the gocql types: TypeTinyInt,TypeSmallInt,TypeInt support go big.Int, but Marshaling functions is not.

Test code

func TestBigInt(t *testing.T) {
	types := []TypeInfo{
		NativeType{proto: 2, typ: TypeTinyInt},
		NativeType{proto: 2, typ: TypeSmallInt},
		NativeType{proto: 2, typ: TypeInt},
	}

	errs := make([]string, 0)
	for _, tp := range types {
		var val big.Int
		data := make([]byte, 0)
		if err := Unmarshal(tp, data, &val); err != nil {
			errs = append(errs, err.Error())
		}
	}
	t.Errorf("\nUnmarshaling of %d cases, have %d errors:\n%s", len(types), len(errs), strings.Join(errs, "\n"))

	errs = make([]string, 0)
	for _, tp := range types {
		val := big.NewInt(0)
		if _, err := Marshal(tp, val); err != nil {
			errs = append(errs, err.Error())
		}
	}
	t.Errorf("\nMarshaling of %d cases, have %d errors:\n%s", len(types), len(errs), strings.Join(errs, "\n"))
}

Output:

=== RUN   TestBigInt
    marshal_0_tmp_test.go:61: 
        Unmarshaling of 3 cases, have 0 errors:
    marshal_0_tmp_test.go:70: 
        Marshaling of 3 cases, have 3 errors:
        can not marshal big.Int into tinyint
        can not marshal big.Int into smallint
        can not marshal big.Int into int
--- FAIL: TestBigInt (0.00s)
@illia-li illia-li changed the title Marshal, unmarshal. cql types: tinyint, smallint, int cant be marshaled into go big.Int` Marshal, unmarshal. cql types: tinyint, smallint, int can not be marshaled into go big.Int Aug 27, 2024
@dkropachev dkropachev self-assigned this Aug 27, 2024
@dkropachev dkropachev added the bug label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants