Skip to content

Commit 3d204e5

Browse files
committed
Make bytes available
1 parent 0f17661 commit 3d204e5

File tree

11 files changed

+120
-34
lines changed

11 files changed

+120
-34
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public DataSizeToBytesThriftCodec(ThriftCatalog thriftCatalog)
4242
}
4343

4444
@CodecThriftType
45-
public static ThriftType getThriftType()
45+
public static ThriftType getThriftType(ThriftCatalog catalog)
4646
{
4747
return THRIFT_TYPE;
4848
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public DurationToMillisThriftCodec(ThriftCatalog thriftCatalog)
4242
}
4343

4444
@CodecThriftType
45-
public static ThriftType getThriftType()
45+
public static ThriftType getThriftType(ThriftCatalog catalog)
4646
{
4747
return THRIFT_TYPE;
4848
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public JodaDateTimeToEpochMillisThriftCodec(ThriftCatalog thriftCatalog)
4141
}
4242

4343
@CodecThriftType
44-
public static ThriftType getThriftType()
44+
public static ThriftType getThriftType(ThriftCatalog catalog)
4545
{
4646
return THRIFT_TYPE;
4747
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public LocaleToLanguageTagCodec(ThriftCatalog thriftCatalog)
4242
}
4343

4444
@CodecThriftType
45-
public static ThriftType getThriftType()
45+
public static ThriftType getThriftType(ThriftCatalog catalog)
4646
{
4747
return THRIFT_TYPE;
4848
}

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(ThriftCatalog catalog)
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-codec/src/main/java/com/facebook/drift/codec/internal/builtin/OptionalDoubleThriftCodec.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.facebook.drift.codec.CodecThriftType;
1919
import com.facebook.drift.codec.ThriftCodec;
20+
import com.facebook.drift.codec.metadata.ThriftCatalog;
2021
import com.facebook.drift.codec.metadata.ThriftType;
2122
import com.facebook.drift.protocol.TProtocolReader;
2223
import com.facebook.drift.protocol.TProtocolWriter;
@@ -34,7 +35,7 @@ public class OptionalDoubleThriftCodec
3435
private static final ThriftType THRIFT_TYPE = new ThriftType(ThriftType.DOUBLE, OptionalDouble.class, OptionalDouble.empty());
3536

3637
@CodecThriftType
37-
public static ThriftType getThriftType()
38+
public static ThriftType getThriftType(ThriftCatalog catalog)
3839
{
3940
return THRIFT_TYPE;
4041
}

drift-codec/src/main/java/com/facebook/drift/codec/internal/builtin/OptionalIntThriftCodec.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.facebook.drift.codec.CodecThriftType;
1919
import com.facebook.drift.codec.ThriftCodec;
20+
import com.facebook.drift.codec.metadata.ThriftCatalog;
2021
import com.facebook.drift.codec.metadata.ThriftType;
2122
import com.facebook.drift.protocol.TProtocolReader;
2223
import com.facebook.drift.protocol.TProtocolWriter;
@@ -40,7 +41,7 @@ public ThriftType getType()
4041
}
4142

4243
@CodecThriftType
43-
public static ThriftType getThriftType()
44+
public static ThriftType getThriftType(ThriftCatalog catalog)
4445
{
4546
return THRIFT_TYPE;
4647
}

drift-codec/src/main/java/com/facebook/drift/codec/internal/builtin/OptionalLongThriftCodec.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.facebook.drift.codec.CodecThriftType;
1919
import com.facebook.drift.codec.ThriftCodec;
20+
import com.facebook.drift.codec.metadata.ThriftCatalog;
2021
import com.facebook.drift.codec.metadata.ThriftType;
2122
import com.facebook.drift.protocol.TProtocolReader;
2223
import com.facebook.drift.protocol.TProtocolWriter;
@@ -34,7 +35,7 @@ public class OptionalLongThriftCodec
3435
private static final ThriftType THRIFT_TYPE = new ThriftType(ThriftType.I64, OptionalLong.class, OptionalLong.empty());
3536

3637
@CodecThriftType
37-
public static ThriftType getThriftType()
38+
public static ThriftType getThriftType(ThriftCatalog catalog)
3839
{
3940
return THRIFT_TYPE;
4041
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,16 @@ private void loadCustomCodec(String customCodecClassName)
162162
throw new ThriftIdlGeneratorException("Method annotated with @CodecThriftType must be static: " + customCodecClassName + "#" + method.getName());
163163
}
164164

165-
if (method.getParameterCount() != 0) {
166-
throw new ThriftIdlGeneratorException("Method annotated with @CodecThriftType must have no parameters: " + customCodecClassName + "#" + method.getName());
165+
if (method.getParameterCount() != 1 || method.getParameterTypes()[0] != ThriftCatalog.class) {
166+
throw new ThriftIdlGeneratorException("Method annotated with @CodecThriftType must have only 1 parameter of ThriftCatalog type: " + customCodecClassName + "#" + method.getName());
167167
}
168168

169169
if (!ThriftType.class.isAssignableFrom(method.getReturnType())) {
170170
throw new ThriftIdlGeneratorException("Method annotated with @CodecThriftType must return ThriftType: " + customCodecClassName + "#" + method.getName());
171171
}
172172

173173
try {
174-
thriftType = (ThriftType) method.invoke(null);
174+
thriftType = (ThriftType) method.invoke(null, this.catalog);
175175
if (thriftType == null) {
176176
throw new ThriftIdlGeneratorException("Method annotated with @CodecThriftType returns null: " + customCodecClassName + "#" + method.getName());
177177
}
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+
}

0 commit comments

Comments
 (0)