8000 Avro Compact Format by alexec · Pull Request #578 · cloudevents/sdk-java · GitHub
[go: up one dir, main page]

Skip to content

Avro Compact Format #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: change to long
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec committed Jun 6, 2023
commit 6c30e27d144b48d040bbbbc67e40af2f6fc5616c
26 changes: 21 additions & 5 deletions formats/avro/src/main/avro/cloudevents.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "1.0",
"doc": "Avro Event Format for CloudEvents",
"fields": [
{
{
"name": "id",
"type": "string"
},
Expand All @@ -19,19 +19,35 @@
},
{
"name": "datacontenttype",
"type": ["null", "string"]
"type": [
"null",
"string"
],
"default": null
},
{
"name": "dataschema",
"type": ["null", "string"]
"type": [
"null",
"string"
],
"default": null
},
{
"name": "subject",
"type": ["null", "string"]
"type": [
"null",
"string"
],
"default": null
},
{
"name": "time",
"type": ["null", "string"]
"type": [
"null",
"long"
],
"default": null
},
{
"name": "attribute",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

import java.net.URI;
import java.nio.ByteBuffer;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -64,7 +66,7 @@ public byte[] serialize(CloudEvent ce) throws EventSerializationException {
.setAttribute(attribute);

if (ce.getTime() != null)
builder.setTime(Time.writeTime(ce.getTime()));
builder.setTime(ce.getTime().toInstant().toEpochMilli());
if (ce.getDataSchema() != null)
builder.setDataschema(ce.getDataSchema().toString());

Expand All @@ -89,7 +91,7 @@ public CloudEvent deserialize(byte[] bytes, CloudEventDataMapper<? extends Cloud
.withDataContentType(avroCe.getDatacontenttype());

if (avroCe.getTime() != null)
builder.withTime(Time.parseTime(avroCe.getTime()));
builder.withTime(Instant.ofEpochMilli(avroCe.getTime()).atOffset(ZoneOffset.UTC));
if (avroCe.getDataschema() != null)
builder.withDataSchema(URI.create(avroCe.getDataschema()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -52,7 +54,7 @@ void format() {
.withSource(URI.create(""))
.withType("")
// optional
.withTime(OffsetDateTime.MIN)
.withTime(Instant.EPOCH.atOffset(ZoneOffset.UTC))
.withSubject("")
.withDataSchema(URI.create(""))
// extension
Expand Down
0