Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 6 additions & 0 deletions cloud/docker-image/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>validator-protobuf</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>

Expand Down
2 changes: 2 additions & 0 deletions cloud/docker-image/src/main/docker/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<include>com/fasterxml/jackson/**</include>
<include>org/yaml/snakeyaml/**</include>
<include>org/junit/**</include>
<include>com/google/**</include>
<include>org/checkerframework/**</include>
</includes>
</fileSet>
</fileSets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"io.aklivity.zilla:validator-avro",
"io.aklivity.zilla:validator-core",
"io.aklivity.zilla:validator-json",
"io.aklivity.zilla:validator-protobuf",
"io.aklivity.zilla:vault-filesystem",
"org.slf4j:slf4j-simple",
"org.antlr:antlr4-runtime"
Expand Down
6 changes: 6 additions & 0 deletions incubator/command-generate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.aklivity.zilla</groupId>
<artifactId>validator-protobuf</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.aklivity.zilla</groupId>
<artifactId>vault-filesystem</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
requires io.aklivity.zilla.runtime.validator.avro;
requires io.aklivity.zilla.runtime.validator.core;
requires io.aklivity.zilla.runtime.validator.json;
requires io.aklivity.zilla.runtime.validator.protobuf;

requires com.fasterxml.jackson.dataformat.yaml;
requires com.fasterxml.jackson.databind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ bindings:
options:
value:
type: protobuf
format: json
catalog:
catalog0:
- subject: test0
version: latest
record: SimpleMessage
record: example
exit: test
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
{
"const": "protobuf"
},
"format":
{
"type": "string",
"enum":
[
"json"
]
},
"catalog":
{
"type": "object",
Expand Down
6 changes: 6 additions & 0 deletions incubator/validator-protobuf/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ WARRANTIES OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

This project includes:
error-prone annotations under Apache 2.0
FindBugs-jsr305 under The Apache Software License, Version 2.0
Gson under Apache-2.0
Guava: Google Core Libraries for Java under Apache License, Version 2.0
J2ObjC Annotations under Apache License, Version 2.0
Protocol Buffers [Core] under BSD-3-Clause
Protocol Buffers [Util] under BSD-3-Clause


This project also includes code under copyright of the following entities:
Expand Down
7 changes: 6 additions & 1 deletion incubator/validator-protobuf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<jacoco.coverage.ratio>0.88</jacoco.coverage.ratio>
<jacoco.coverage.ratio>0.90</jacoco.coverage.ratio>
<jacoco.missed.count>0</jacoco.missed.count>
</properties>

Expand All @@ -48,6 +48,11 @@
<artifactId>protobuf-java</artifactId>
<version>3.24.4</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.24.4</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Copyright 2021-2023 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.validator.protobuf;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.google.protobuf.Descriptors;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.FileDescriptor;

public class DescriptorTree
{
protected final Map<String, DescriptorTree> children;
protected final List<Integer> indexes;

protected Descriptors.Descriptor descriptor;
protected String name;

private DescriptorTree()
{
this.children = new LinkedHashMap<>();
this.indexes = new LinkedList<>();
}

protected DescriptorTree(
FileDescriptor fileDescriptors)
{
this();
this.name = fileDescriptors.getPackage();
for (Descriptor descriptor : fileDescriptors.getMessageTypes())
{
addDescriptor(descriptor);
addNestedDescriptors(descriptor);
}
}

protected DescriptorTree findByName(
String path)
{
DescriptorTree current = this;
int start = 0;
int end;

while (start < path.length())
{
end = path.indexOf('.', start);
if (end == -1)
{
end = path.length();
}

String part = path.substring(start, end);
current = current.children.get(part);

if (current == null)
{
break;
}
start = end + 1;
}
return current;
}

protected DescriptorTree findByIndexes(
List<Integer> indexes)
{
DescriptorTree current = this;

for (Integer index : indexes)
{
current = current.findChild(index);
if (current == null)
{
return null;
}
}
return current;
}

private DescriptorTree findParent(
String path)
{
int index = path.lastIndexOf('.');
String part = index >= 0 ? path.substring(index + 1) : path;
return this.children.getOrDefault(part, null);
}

private DescriptorTree findChild(
int index)
{
DescriptorTree tree = this;
int currentIndex = 0;
for (Map.Entry<String, DescriptorTree> entry : children.entrySet())
{
if (currentIndex == index)
{
tree = entry.getValue();
break;
}
currentIndex++;
}
return tree;
}

private void addNestedDescriptor(
Descriptor parent,
int index)
{
DescriptorTree parentNode = findParent(parent.getFullName());
if (parentNode != null)
{
Descriptors.Descriptor nestedDescriptor = parent.getNestedTypes().get(index);
parentNode.addDescriptor(nestedDescriptor);
parentNode.addNestedDescriptors(nestedDescriptor);
}
}

private void addDescriptor(
Descriptor descriptor)
{
DescriptorTree node = new DescriptorTree();
node.descriptor = descriptor;
node.name = name;
node.indexes.addAll(this.indexes);
node.indexes.add(this.children.size());
this.children.put(descriptor.getName(), node);
}

private void addNestedDescriptors(Descriptor descriptor)
{
for (int i = 0; i < descriptor.getNestedTypes().size(); i++)
{
addNestedDescriptor(descriptor, i);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ public void enterMessageDef(
builder.setName(name);
messageHierarchy.push(name);

String parentNodes = String.join(".", messageHierarchy);
System.out.println("Message Hierarchy: " + parentNodes);

for (Protobuf3Parser.MessageElementContext element : ctx.messageBody().messageElement())
{
if (element.field() != null)
Expand Down
Loading