Skip to content

Commit bb42767

Browse files
committed
add avro data wrapper and hides serde classes from public
1 parent 30ca8ad commit bb42767

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2018-Present The CloudEvents Authors
3+
* <p>
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+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
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+
*/
17+
package io.cloudevents.avro;
18+
19+
import java.io.ByteArrayOutputStream;
20+
import java.io.IOException;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import io.cloudevents.AvroCloudEventData;
25+
import io.cloudevents.CloudEventData;
26+
27+
/**
28+
* Encode JSON style cloudevent data into Avro format.
29+
*
30+
*/
31+
public class AvroCloudEventDataWrapper implements CloudEventData {
32+
33+
private AvroCloudEventData avroCloudEventData;
34+
35+
/**
36+
* Wraps a JSON object-like data structure.
37+
*/
38+
public AvroCloudEventDataWrapper(Map<CharSequence, Object> data) {
39+
avroCloudEventData = new AvroCloudEventData();
40+
avroCloudEventData.setValue(data);
41+
}
42+
43+
@Override
44+
public byte[] toBytes() {
45+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
46+
try {
47+
AvroCloudEventData.getEncoder().encode(this.avroCloudEventData, bytes);
48+
} catch (IOException ignore) {
49+
// ignored
50+
}
51+
52+
return bytes.toByteArray();
53+
}
54+
}

formats/avro/src/main/java/io/cloudevents/avro/AvroDeserializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import io.cloudevents.rw.CloudEventWriter;
3333
import io.cloudevents.rw.CloudEventWriterFactory;
3434

35-
public class AvroDeserializer implements CloudEventReader {
35+
class AvroDeserializer implements CloudEventReader {
3636

3737
private final AvroCloudEvent avroCloudEvent;
3838

formats/avro/src/main/java/io/cloudevents/avro/AvroSerializer.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
import io.cloudevents.CloudEventData;
2525
import io.cloudevents.core.v1.CloudEventV1;
2626
import io.cloudevents.AvroCloudEvent;
27-
import io.cloudevents.AvroCloudEventData;
2827

29-
public class AvroSerializer {
28+
class AvroSerializer {
3029

3130
public static final AvroCloudEvent toAvro(CloudEvent e) {
3231
AvroCloudEvent avroCloudEvent = new AvroCloudEvent();

0 commit comments

Comments
 (0)