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

Tuple support in ParseVariant. #388

Open
rewk opened this issue Sep 2, 2024 · 1 comment
Open

Tuple support in ParseVariant. #388

rewk opened this issue Sep 2, 2024 · 1 comment

Comments

@rewk
Copy link

rewk commented Sep 2, 2024

Hi,

There doesn't seem to be tuple support in the ParseVariant function, even if the signature contains it.

For example, my understanding of https://docs.gtk.org/glib/gvariant-text-format.html#tuples is that this should work:

	pair, err := dbus.ParseVariant(`
		(1,2)
	`, dbus.ParseSignatureMust("(ii)"))

However, the tokenization fails with unrecognized type "(1,2)".

There is no case for ( in varLexNormal.

Is this a known limitation ? There doesn't seem to be any occurrence of tuple in the godbus documentation.

https://pkg.go.dev/github.com/godbus/dbus/v5#hdr-Conversion_Rules

Thanks!

@guelfey
Copy link
Member

guelfey commented Sep 21, 2024

To be more precise: D-Bus doesn't have the concept of tuples, the construct is called "STRUCT" in the reference, but effectively they're the same as tuples in GVariant, that is, an ordered collection of fields of different known types. (AFAICT GVariant adopted a type system that is partially based on, but not 100% identical to what the D-Bus standard refers to. But since the string format was the closest part to a "standard" on how to represent D-Bus values as text, I chose to try to replicate it within this library.)

It's true though that the function for parsing / formatting Variants don't support structs properly. For formatting, there is #329 which I'll take another look at; parsing would have to be implemented completely freshly and similar to the struct handling when decoding D-Bus messages, we'd have to live with structs being mapped to []interface{}.

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