Skip to content

Commit 0f69d81

Browse files
committed
Make bytes available
1 parent 0f17661 commit 0f69d81

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
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
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)