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

Update Graph Binary serializer to 4.0.0 spec for Go #3034

Open
wants to merge 3 commits into
base: gremlin-go-http
Choose a base branch
from

Conversation

xiazcy
Copy link
Contributor

@xiazcy xiazcy commented Feb 12, 2025

First set of changes for type serializers in Go. Updated element serializers, datetime, list and map serializers, and removed old types no longer in 4.0 specs.

For ordered map, Go doesn't have native support for ordered map, so an open source library was used. Alternative option is to not support ordered map in Go and just return regular map if it's a concern to users, and note in documentation.

case reflect.Map:
mapData.Set(&k, v)
default:
mapData.Set(fmt.Sprint(k), v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a slice key be set as a string key here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, slices themselves cannot be set as keys (non-comparable type) in go, this turns it into a string to be used as the key.

@@ -1028,7 +877,8 @@ func readMapUnqualified(data *[]byte, i *int) (interface{}, error) {
}

func readSet(data *[]byte, i *int) (interface{}, error) {
list, err := readList(data, i)
// TODO placeholder flag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this left as TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to update set as well. Will do that.

@@ -1351,9 +1073,17 @@ func readFullyQualifiedNullable(data *[]byte, i *int, nullable bool) (interface{
}
return nil, nil
} else if nullable {
if readByteSafe(data, i) == valueFlagNull {
flag := readByteSafe(data, i)
fmt.Println(flag)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed?

convKey := k.Convert(v.Type().Key())
// serialize k
_, err := typeSerializer.write(k.Interface(), buffer)
if val, ok := value.(*orderedmap.OrderedMap[interface{}, interface{}]); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to find where the {value_flag} equal to 0x02 for an ordered map is set, can you point me to it?

return nil, err
}
bulk := readIntSafe(data, i)
for k := int32(0); k < bulk; k++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to find where bulk list value flag and value are written. Can you point me to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So both ordered dict and bulk list are result formats that's sent by the server, nothing (that I'm aware of, I could be wrong) the GLV sends is bulked or ordered.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find any usage of readFullyQualifiedNullable where nullable isn't hardcoded to true. Can that function param just be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll double check, but I think that'll be a separate set of changes from this PR

return getDefaultValue(dataTyp), nil
}
if dataTyp == listType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell the readList and readMap functions are treated differently here because they accept the flag as a param. Since the flag value is always read before calling the deserializer can the deserializer's reader function be changed to accept a flag param and the implementations can either use it or ignore it depending on the type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, to do that we'll have to update implementations for all and I wanted the change to be relatively isolated to these 2 types, but I'll take a closer look.

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

Successfully merging this pull request may close these issues.

2 participants