Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30d914b

Browse files
committed
improved serialize user data bytes
1 parent 9d77774 commit 30d914b

File tree

4 files changed

+94
-32
lines changed

4 files changed

+94
-32
lines changed

‎core/src/main/java/com/arangodb/internal/serde/InternalSerde.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,26 +136,6 @@ default <T> T deserialize(byte[] content, String jsonPointer, Type type) {
136136
*/
137137
<T> T deserializeUserData(byte[] content, Type type);
138138

139-
/**
140-
* Deserializes the parsed json node and binds it to the target data type, using the user serde.
141-
*
142-
* @param node parsed json node
143-
* @param clazz class of target data type
144-
* @return deserialized object
145-
*/
146-
default <T> T deserializeUserData(JsonNode node, Class<T> clazz) {
147-
return deserializeUserData(node, (Type) clazz);
148-
}
149-
150-
/**
151-
* Deserializes the parsed json node and binds it to the target data type, using the user serde.
152-
*
153-
* @param node parsed json node
154-
* @param type target data type
155-
* @return deserialized object
156-
*/
157-
<T> T deserializeUserData(JsonNode node, Type type);
158-
159139
/**
160140
* @return the user serde
161141
*/

‎core/src/main/java/com/arangodb/internal/serde/InternalSerdeImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public byte[] extract(final byte[] content, final String jsonPointer) {
114114
}
115115
}
116116

117+
// TODO: remove
117118
@Override
118119
public JsonNode parse(byte[] content) {
119120
try {
@@ -178,11 +179,6 @@ public <T> T deserializeUserData(byte[] content, Type type) {
178179
}
179180
}
180181

181-
@Override
182-
public <T> T deserializeUserData(JsonNode node, Type type) {
183-
return deserializeUserData(serialize(node), type);
184-
}
185-
186182
@Override
187183
public ArangoSerde getUserSerde() {
188184
return userSerde;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.arangodb.internal.serde;
2+
3+
import com.fasterxml.jackson.core.SerializableString;
4+
5+
import java.io.IOException;
6+
import java.io.OutputStream;
7+
import java.nio.ByteBuffer;
8+
9+
class RawUserDataValue implements SerializableString {
10+
private final byte[] data;
11+
12+
RawUserDataValue(byte[] data) {
13+
this.data = data;
14+
}
15+
16+
@Override
17+
public String getValue() {
18+
throw new UnsupportedOperationException();
19+
}
20+
21+
@Override
22+
public int charLength() {
23+
throw new UnsupportedOperationException();
24+
}
25+
26+
@Override
27+
public char[] asQuotedChars() {
28+
throw new UnsupportedOperationException();
29+
}
30+
31+
@Override
32+
public byte[] asUnquotedUTF8() {
33+
return data;
34+
}
35+
36+
@Override
37+
public byte[] asQuotedUTF8() {
38+
throw new UnsupportedOperationException();
39+
}
40+
41+
@Override
42+
public int appendQuotedUTF8(byte[] buffer, int offset) {
43+
throw new UnsupportedOperationException();
44+
}
45+
46+
@Override
47+
public int appendQuoted(char[] buffer, int offset) {
48+
throw new UnsupportedOperationException();
49+
}
50+
51+
@Override
52+
public int appendUnquotedUTF8(byte[] buffer, int offset) {
53+
final int length = data.length;
54+
if ((offset + length) > buffer.length) {
55+
return -1;
56+
}
57+
System.arraycopy(data, 0, buffer, offset, length);
58+
return length;
59+
}
60+
61+
@Override
62+
public int appendUnquoted(char[] buffer, int offset) {
63+
throw new UnsupportedOperationException();
64+
}
65+
66+
@Override
67+
public int writeQuotedUTF8(OutputStream out) {
68+
throw new UnsupportedOperationException();
69+
}
70+
71+
@Override
72+
public int writeUnquotedUTF8(OutputStream out) throws IOException {
73+
final int length = data.length;
74+
out.write(data, 0, length);
75+
return length;
76+
}
77+
78+
@Override
79+
public int putQuotedUTF8(ByteBuffer buffer) {
80+
throw new UnsupportedOperationException();
81+
}
82+
83+
@Override
84+
public int putUnquotedUTF8(ByteBuffer buffer) {
85+
final int length = data.length;
86+
if (length > buffer.remaining()) {
87+
return -1;
88+
}
89+
buffer.put(data, 0, length);
90+
return length;
91+
}
92+
}

‎core/src/main/java/com/arangodb/internal/serde/UserDataSerializer.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.arangodb.internal.serde;
22

33
import com.fasterxml.jackson.core.JsonGenerator;
4-
import com.fasterxml.jackson.core.JsonParser;
54
import com.fasterxml.jackson.databind.JsonNode;
65
import com.fasterxml.jackson.databind.JsonSerializer;
76
import com.fasterxml.jackson.databind.SerializerProvider;
@@ -20,12 +19,7 @@ public void serialize(Object value, JsonGenerator gen, SerializerProvider serial
2019
if (value != null && JsonNode.class.isAssignableFrom(value.getClass())) {
2120
gen.writeTree((JsonNode) value);
2221
} else {
23-
// TODO: find a way to append raw bytes directly
24-
// see https://github.com/FasterXML/jackson-core/issues/914
25-
// TODO: check gen.getOutputContext()
26-
try (JsonParser parser = gen.getCodec().getFactory().createParser(serde.serializeUserData(value))) {
27-
gen.writeTree(parser.readValueAsTree());
28-
}
22+
gen.writeRawValue(new RawUserDataValue(serde.serializeUserData(value)));
2923
}
3024
}
3125
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /