forked from opensensorhub/osh-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Protobuf Serializer #7
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
Open
apoteau21
wants to merge
16
commits into
master
Choose a base branch
from
protobuf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4677471
adding new and newly edited files
e9ace21
creating datarec, cothelper
68d30d2
fixing comments, endCollection
011e2db
pushing
0903ec0
updating cot serializer
c1606f8
trying to fix null variable errors
225fbea
Merge branch 'opensensorhub:master' into new-cot
apoteau21 bdd7380
reorganizing data into maps, fixing format/response type issues
7a7c89e
cleaning up code
72d8611
adding protofiles on gh
b868e2d
adding protowriter file
ebd46b2
mapping osh <-> protobuf fields
4aa1fc9
serialization logic, dependencies, file structure
5fa79db
got link working, serialization logic done, testing in progress rn
3a894b0
links work, binary file is produced, verifying validity of results
a36c323
cleaning up code, removing protowriter file, seems to work
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
lib-ogc/swe-common-core/src/main/java/org/vast/swe/fast/CotDataReader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /***************************** BEGIN LICENSE BLOCK *************************** | ||
|
|
||
| The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
| If a copy of the MPL was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| Software distributed under the License is distributed on an "AS IS" basis, | ||
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
| for the specific language governing rights and limitations under the License. | ||
|
|
||
| Copyright (C) 2012-2015 Sensia Software LLC. All Rights Reserved. | ||
|
|
||
| ******************************* END LICENSE BLOCK ***************************/ | ||
|
|
||
| package org.vast.swe.fast; | ||
|
|
||
| import com.ctc.wstx.api.WstxOutputProperties; | ||
| import com.google.gson.FormattingStyle; | ||
| import com.google.gson.Strictness; | ||
| import net.opengis.swe.v20.*; | ||
| import net.opengis.swe.v20.Boolean; | ||
| import org.vast.data.AbstractArrayImpl; | ||
| import org.vast.data.XMLEncodingImpl; | ||
| import org.vast.swe.SWEDataTypeUtils; | ||
| import org.vast.util.DateTimeFormat; | ||
| import org.vast.util.WriterException; | ||
|
|
||
| import javax.xml.namespace.NamespaceContext; | ||
| import javax.xml.namespace.QName; | ||
| import javax.xml.stream.*; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.io.Reader; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * <p> | ||
| * New implementation of XML data writer with better efficiency since the | ||
| * write tree is pre-computed during init instead of being re-evaluated | ||
| * while iterating through the component tree. | ||
| * </p> | ||
| * | ||
| * @author Ashley Poteau | ||
| * @since Dec 2, 2025 | ||
| */ | ||
|
|
||
| public class CotDataReader extends XmlDataParser { | ||
| static final String COT_ERROR = "Error writing XML stream for "; | ||
| private final Reader in; | ||
|
|
||
| protected XMLStreamReader xmlReader; | ||
| protected XMLStreamWriter xmlWriter; | ||
| protected String namespace; | ||
| protected String prefix; | ||
| protected Map<String, XmlDataWriter.IntegerWriter> countWriters = new HashMap<>(); | ||
|
|
||
| public CotDataReader(Reader in) { | ||
| this.in = Objects.requireNonNull(in, "in == null"); | ||
| } | ||
|
|
||
|
|
||
| } |
149 changes: 149 additions & 0 deletions
149
lib-ogc/swe-common-core/src/main/java/org/vast/swe/fast/CotDataWriter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /***************************** BEGIN LICENSE BLOCK *************************** | ||
|
|
||
| The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
| If a copy of the MPL was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| Software distributed under the License is distributed on an "AS IS" basis, | ||
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
| for the specific language governing rights and limitations under the License. | ||
|
|
||
| Copyright (C) 2012-2015 Sensia Software LLC. All Rights Reserved. | ||
|
|
||
| ******************************* END LICENSE BLOCK ***************************/ | ||
|
|
||
| package org.vast.swe.fast; | ||
|
|
||
| import com.ctc.wstx.api.WstxOutputProperties; | ||
| import com.google.gson.FormattingStyle; | ||
| import com.google.gson.Strictness; | ||
| import net.opengis.swe.v20.*; | ||
| import net.opengis.swe.v20.Boolean; | ||
| import org.vast.data.AbstractArrayImpl; | ||
| import org.vast.data.XMLEncodingImpl; | ||
| import org.vast.swe.SWEDataTypeUtils; | ||
| import org.vast.util.DateTimeFormat; | ||
| import org.vast.util.WriterException; | ||
|
|
||
| import javax.xml.namespace.NamespaceContext; | ||
| import javax.xml.stream.XMLOutputFactory; | ||
| import javax.xml.stream.XMLStreamException; | ||
| import javax.xml.stream.XMLStreamWriter; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
|
|
||
|
|
||
| /** | ||
| * <p> | ||
| * New implementation of XML data writer with better efficiency since the | ||
| * write tree is pre-computed during init instead of being re-evaluated | ||
| * while iterating through the component tree. | ||
| * </p> | ||
| * | ||
| * @author Ashley Poteau | ||
| * @since Oct 31, 2025 | ||
| */ | ||
| public class CotDataWriter extends XmlDataWriter { | ||
| static final String COT_ERROR = "Error writing XML stream for "; | ||
|
|
||
| protected String namespace; | ||
| protected String prefix; | ||
| protected Map<String, XmlDataWriter.IntegerWriter> countWriters = new HashMap<>(); | ||
| private boolean serializeNulls = true; | ||
| private FormattingStyle formattingStyle; | ||
| // These fields cache data derived from the formatting style, to avoid having to | ||
| // re-evaluate it every time something is written | ||
| private String formattedColon; | ||
| private String formattedComma; | ||
| private boolean usesEmptyNewlineAndIndent; | ||
|
|
||
|
|
||
| public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException { | ||
| xmlWriter.writeStartElement(namespaceURI, localName); | ||
| } | ||
|
|
||
| public void writeCotCharacters(String text) throws XMLStreamException { | ||
| if (xmlWriter == null) { | ||
| throw new IllegalStateException("XMLStreamWriter not initialized. Call setOutput() first."); | ||
| } | ||
| xmlWriter.writeCharacters(text); | ||
| } | ||
|
|
||
| public void writeCotStartElement(String text) throws XMLStreamException { | ||
| if (xmlWriter == null) { | ||
| throw new IllegalStateException("XMLStreamWriter not initialized. Call setOutput() first."); | ||
| } | ||
| xmlWriter.writeStartElement(text); | ||
| } | ||
|
|
||
| public void writeCotAttribute(String var1, String var2) throws XMLStreamException { | ||
| if (xmlWriter == null) { | ||
| throw new IllegalStateException("XMLStreamWriter not initialized. Call setOutput() first."); | ||
| } | ||
| xmlWriter.writeAttribute(var1, var2); | ||
| } | ||
|
|
||
| @Override | ||
| public void startStream(boolean addWrapper) throws IOException | ||
| { | ||
| try | ||
| { | ||
| if (addWrapper) | ||
| xmlWriter.writeStartElement("event"); | ||
| } | ||
| catch (XMLStreamException e) | ||
| { | ||
| throw new IOException(e.getMessage(), e.getCause()); | ||
| } | ||
| } | ||
|
|
||
| public void writeCotEndElement() throws XMLStreamException { | ||
| xmlWriter.writeEndElement(); | ||
| } | ||
|
|
||
| public final void setSerializeNulls(boolean serializeNulls) { | ||
|
|
||
| this.serializeNulls = serializeNulls; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if object members are serialized when their value is null. This has no impact on | ||
| * array elements. The default is true. | ||
| */ | ||
| public final boolean getSerializeNulls() { | ||
| return serializeNulls; | ||
| } | ||
|
|
||
| // public final void setFormattingStyle(FormattingStyle formattingStyle) { | ||
| // this.formattingStyle = Objects.requireNonNull(formattingStyle); | ||
| // | ||
| // this.formattedComma = ","; | ||
| // if (this.formattingStyle.usesSpaceAfterSeparators()) { | ||
| // this.formattedColon = ": "; | ||
| // | ||
| // // Only add space if no newline is written | ||
| // if (this.formattingStyle.getNewline().isEmpty()) { | ||
| // this.formattedComma = ", "; | ||
| // } | ||
| // } else { | ||
| // this.formattedColon = ":"; | ||
| // } | ||
| // | ||
| // this.usesEmptyNewlineAndIndent = | ||
| // this.formattingStyle.getNewline().isEmpty() && this.formattingStyle.getIndent().isEmpty(); | ||
| // } | ||
| // | ||
| // | ||
| // public final void setIndent(String indent) { | ||
| // if (indent.isEmpty()) { | ||
| // setFormattingStyle(FormattingStyle.COMPACT); | ||
| // } else { | ||
| // setFormattingStyle(FormattingStyle.PRETTY.withIndent(indent)); | ||
| // } | ||
| // } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't related to the protobuf serialization