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

Fix optional argument encoding #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,27 @@ public final void serializeArguments(@NotNull PacketWriter writer, @Nullable Map
@Override
public final void serialize(@NotNull PacketWriter writer, @Nullable Object rawValue, @NotNull CodecContext context) throws OperationNotSupportedException, EdgeDBException {
if(rawValue == null) {
throw new IllegalArgumentException("Serializable object value cannot be null");
}

if(!(rawValue instanceof Map)) {
rawValue = Map.of();
} else if(!(rawValue instanceof Map)) {
throw new EdgeDBException("Expected map type for object serialization");
}

var value = (Map<String, ?>)rawValue;

writer.write(value.size());
writer.write(this.elements.length);

var visitor = context.getTypeVisitor();

for(int i = 0; i != value.size(); i++) {
for(int i = 0; i != this.elements.length; i++) {
var element = this.elements[i];

writer.write(0); // reserved

if(!value.containsKey(element.name)) {
if (element.cardinality != Cardinality.AT_MOST_ONE) {
throw new EdgeDBException(String.format("Missing required argument '%s'", element.name));
}

writer.write(-1);
continue;
}
Expand Down