Skip to content

Commit 52f1056

Browse files
committed
Make bytes available
1 parent 0f17661 commit 52f1056

File tree

4 files changed

+111
-5
lines changed

4 files changed

+111
-5
lines changed

drift-codec-utils/src/main/java/com/facebook/drift/codec/utils/UuidToLeachSalzBinaryEncodingThriftCodec.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.facebook.drift.codec.utils;
1717

18+
import com.facebook.drift.codec.CodecThriftType;
1819
import com.facebook.drift.codec.ThriftCodec;
1920
import com.facebook.drift.codec.internal.coercion.FromThrift;
2021
import com.facebook.drift.codec.internal.coercion.ToThrift;
@@ -33,24 +34,32 @@
3334

3435
/**
3536
* This codec will encode UUIDs into the format specified in RFC 4122:
36-
*
37+
* <p>
3738
* https://www.ietf.org/rfc/rfc4122.txt
38-
*
39+
* <p>
3940
* Likewise, it presumes the input is of this format.
4041
*/
4142
public class UuidToLeachSalzBinaryEncodingThriftCodec
4243
implements ThriftCodec<UUID>
4344
{
45+
private static final ThriftType THRIFT_TYPE = new ThriftType(ThriftType.BINARY, UUID.class);
46+
4447
@Inject
4548
public UuidToLeachSalzBinaryEncodingThriftCodec(ThriftCatalog thriftCatalog)
4649
{
4750
thriftCatalog.addDefaultCoercions(getClass());
4851
}
4952

53+
@CodecThriftType
54+
public static ThriftType getThriftType()
55+
{
56+
return THRIFT_TYPE;
57+
}
58+
5059
@Override
5160
public ThriftType getType()
5261
{
53-
return new ThriftType(ThriftType.BINARY, UUID.class);
62+
return THRIFT_TYPE;
5463
}
5564

5665
@Override

drift-idl-generator/src/main/java/com/facebook/drift/idl/generator/ThriftIdlGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private void loadCustomCodec(String customCodecClassName)
152152

153153
// Look for a static method annotated with @CodecThriftType
154154
ThriftType thriftType = null;
155-
for (Method method : codecClass.getDeclaredMethods()) {
155+
for (Method method : codecClass.getMethods()) {
156156
if (method.isAnnotationPresent(CodecThriftType.class)) {
157157
if (!Modifier.isPublic(method.getModifiers())) {
158158
throw new ThriftIdlGeneratorException("Method annotated with @CodecThriftType must be public: " + customCodecClassName + "#" + method.getName());
@@ -163,7 +163,7 @@ private void loadCustomCodec(String customCodecClassName)
163163
}
164164

165165
if (method.getParameterCount() != 0) {
166-
throw new ThriftIdlGeneratorException("Method annotated with @CodecThriftType must have no parameters: " + customCodecClassName + "#" + method.getName());
166+
throw new ThriftIdlGeneratorException("Method annotated with @CodecThriftType must have no parameter: " + customCodecClassName + "#" + method.getName());
167167
}
168168

169169
if (!ThriftType.class.isAssignableFrom(method.getReturnType())) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2017 Facebook, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.facebook.drift.protocol;
17+
18+
import java.io.ByteArrayOutputStream;
19+
import java.nio.charset.Charset;
20+
21+
public class TByteArrayOutputStream
22+
extends ByteArrayOutputStream
23+
{
24+
public TByteArrayOutputStream(int size)
25+
{
26+
super(size);
27+
}
28+
29+
public TByteArrayOutputStream()
30+
{
31+
super();
32+
}
33+
34+
protected byte[] get()
35+
{
36+
return buf;
37+
}
38+
39+
public int len()
40+
{
41+
return count;
42+
}
43+
44+
public String toString(Charset charset)
45+
{
46+
return new String(buf, 0, count, charset);
47+
}
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 2017 Facebook, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.facebook.drift.protocol;
17+
18+
import com.google.common.io.ByteArrayDataOutput;
19+
import com.google.common.io.ByteStreams;
20+
21+
public class TMemoryBufferWriteOnly
22+
implements TTransport
23+
{
24+
private ByteArrayDataOutput data;
25+
26+
public TMemoryBufferWriteOnly(int size)
27+
{
28+
data = ByteStreams.newDataOutput(size);
29+
}
30+
31+
@Override
32+
public void read(byte[] buf, int off, int len)
33+
throws TTransportException
34+
{
35+
throw new UnsupportedOperationException("Read operation is not supported");
36+
}
37+
38+
@Override
39+
public void write(byte[] buf, int off, int len)
40+
throws TTransportException
41+
{
42+
data.write(buf, off, len);
43+
}
44+
45+
public byte[] getBytes()
46+
{
47+
return data.toByteArray();
48+
}
49+
}

0 commit comments

Comments
 (0)