forked from apache/tinkerpop
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create modified wsclient that skips response deserialization
- Loading branch information
Showing
4 changed files
with
117 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...rc/main/java/org/apache/tinkerpop/gremlin/util/ser/binary/ResponseMessageSerializer2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.tinkerpop.gremlin.util.ser.binary; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import org.apache.tinkerpop.gremlin.structure.io.Buffer; | ||
import org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryReader; | ||
import org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryWriter; | ||
import org.apache.tinkerpop.gremlin.util.message.ResponseMessage; | ||
import org.apache.tinkerpop.gremlin.util.message.ResponseResult; | ||
import org.apache.tinkerpop.gremlin.util.message.ResponseStatus; | ||
import org.apache.tinkerpop.gremlin.util.message.ResponseStatusCode; | ||
import org.apache.tinkerpop.gremlin.util.ser.NettyBufferFactory; | ||
import org.apache.tinkerpop.gremlin.util.ser.SerializationException; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.UUID; | ||
|
||
public class ResponseMessageSerializer2 { | ||
private static final NettyBufferFactory bufferFactory = new NettyBufferFactory(); | ||
|
||
public ResponseMessage readValue(final ByteBuf byteBuf, final GraphBinaryReader context) throws SerializationException { | ||
// Wrap netty's buffer | ||
final Buffer buffer = bufferFactory.create(byteBuf); | ||
final int version = buffer.readByte() & 0xff; | ||
|
||
if (version >>> 7 != 1) { | ||
// This is an indication that the response buffer was incorrectly built | ||
// Or the buffer offsets are wrong | ||
throw new SerializationException("The most significant bit should be set according to the format"); | ||
} | ||
LinkedHashMap<String,Object> dummyMap = new LinkedHashMap<>(); | ||
// dummyMap.put("host", "/localhost:8182"); | ||
LinkedHashMap<String,Object> dummyMap2 = new LinkedHashMap<>(); | ||
ArrayList<Long> dummyList = new ArrayList<>(); | ||
// dummyList.add(808L); | ||
try { | ||
return ResponseMessage.build(context.readValue(buffer, UUID.class, true)) // c256d92e-738b-4081-aa45-ccd708311823// read values use register.serializer | ||
.code(ResponseStatusCode.SUCCESS) | ||
.statusMessage("") | ||
.statusAttributes(dummyMap) | ||
.responseMetaData(dummyMap2) | ||
.result(dummyList) | ||
.create(); | ||
} catch (IOException ex) { | ||
throw new SerializationException(ex); | ||
} | ||
} | ||
|
||
public void writeValue(final ResponseMessage value, final ByteBuf byteBuf, final GraphBinaryWriter context) throws SerializationException { | ||
// Wrap netty's buffer | ||
final Buffer buffer = bufferFactory.create(byteBuf); | ||
|
||
final ResponseResult result = value.getResult(); | ||
final ResponseStatus status = value.getStatus(); | ||
|
||
try { | ||
// Version | ||
buffer.writeByte(GraphBinaryWriter.VERSION_BYTE); | ||
// Nullable request id | ||
context.writeValue(value.getRequestId(), buffer, true); | ||
// Status code | ||
context.writeValue(status.getCode().getValue(), buffer, false); | ||
// Nullable status message | ||
context.writeValue(status.getMessage(), buffer, true); | ||
// Status attributes | ||
context.writeValue(status.getAttributes(), buffer, false); | ||
// Result meta | ||
context.writeValue(result.getMeta(), buffer, false); | ||
// Fully-qualified value | ||
context.write(result.getData(), buffer); | ||
} catch (IOException ex) { | ||
throw new SerializationException(ex); | ||
} | ||
} | ||
} |