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. For many cql types a go string is supported, but not a go custom string #243

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

Comments

@illia-li
Copy link

illia-li commented Aug 27, 2024

Currently the functions for Marshaling and Unmarshaling many cql types support go type string, but not custom types of the go_type string.
Types list: TypeTinyInt, TypeSmallInt, TypeInt, TypeBigInt, TypeCounter, TypeVarint, TypeInet, TypeDate, TypeUUID, TypeTimeUUID, TypeDuration.

Test code:

func TestCustomString(t *testing.T) {
	type cstring string

	types := []TypeInfo{
		NativeType{proto: 2, typ: TypeTinyInt},
		NativeType{proto: 2, typ: TypeSmallInt},
		NativeType{proto: 2, typ: TypeInt},
		NativeType{proto: 2, typ: TypeBigInt},
		NativeType{proto: 2, typ: TypeCounter},
		NativeType{proto: 2, typ: TypeVarint},
		NativeType{proto: 2, typ: TypeInet},
		NativeType{proto: 2, typ: TypeDate},
		NativeType{proto: 2, typ: TypeUUID},
		NativeType{proto: 2, typ: TypeTimeUUID},
		NativeType{proto: 2, typ: TypeDuration},
	}

	errs := make([]string, 0)
	for _, tp := range types {
		var val cstring
		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 {
		var val cstring
		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   TestCustomString
    marshal_0_tmp_test.go:33: 
        Unmarshaling of 11 cases, have 11 errors:
        can not unmarshal tinyint into *gocql.cstring
        can not unmarshal smallint into *gocql.cstring
        can not unmarshal int into *gocql.cstring
        can not unmarshal bigint into *gocql.cstring
        can not unmarshal counter into *gocql.cstring
        can not unmarshal varint into *gocql.cstring
        cannot unmarshal inet into *gocql.cstring
        can not unmarshal date into *gocql.cstring
        can not unmarshal X uuid into *gocql.cstring
        can not unmarshal X timeuuid into *gocql.cstring
        can not unmarshal duration into *gocql.cstring
    marshal_0_tmp_test.go:42: 
        Marshaling of 11 cases, have 11 errors:
        can not marshal gocql.cstring into tinyint
        can not marshal gocql.cstring into smallint
        can not marshal gocql.cstring into int
        can not marshal gocql.cstring into bigint
        can not marshal gocql.cstring into counter
        can not marshal gocql.cstring into varint
        cannot marshal gocql.cstring into inet
        can not marshal gocql.cstring into date
        can not marshal gocql.cstring into uuid
        can not marshal gocql.cstring into timeuuid
        can not marshal gocql.cstring into duration
--- FAIL: TestCustomString (0.00s)
@illia-li illia-li changed the title Marshal, unmarshal problems. A lot of the cql types support string, but not custom string Marshal, unmarshal. A lot of the cql types support string, but not custom string Aug 27, 2024
@illia-li illia-li changed the title Marshal, unmarshal. A lot of the cql types support string, but not custom string Marshal, unmarshal. For a lot of the cql types support string, but not custom string Aug 27, 2024
@illia-li illia-li changed the title Marshal, unmarshal. For a lot of the cql types support string, but not custom string Marshal, unmarshal. For many cql types a go string is supported, but not a go custom string 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