Merge branch 'release/2.17.0'
This commit is contained in:
commit
f7f512a5f3
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
|
||||
<intAttribute key="M2_COLORS" value="0"/>
|
||||
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
|
||||
<stringAttribute key="M2_GOALS" value="package"/>
|
||||
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
|
||||
|
@ -12,6 +13,9 @@
|
|||
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
|
||||
<stringAttribute key="M2_USER_SETTINGS" value=""/>
|
||||
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:com.minres.scviewer.parent}"/>
|
||||
</launchConfiguration>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
|
||||
<intAttribute key="M2_COLORS" value="0"/>
|
||||
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
|
||||
<stringAttribute key="M2_GOALS" value="tycho-versions:set-version tycho-versions:update-pom"/>
|
||||
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
|
||||
|
@ -15,6 +16,9 @@
|
|||
<stringAttribute key="M2_USER_SETTINGS" value=""/>
|
||||
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
|
||||
<stringAttribute key="bad_container_name" value="/com.minres.scviewer.parent/.launch"/>
|
||||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:com.minres.scviewer.parent}"/>
|
||||
</launchConfiguration>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -70,4 +70,11 @@ http://www.eclipse.org/legal/epl-v10.html
|
|||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="com.minres.scviewer.database.ftr"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
</feature>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,3 @@
|
|||
/bin
|
||||
/target/
|
||||
/.settings/
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.minres.scviewer.database.ftr</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ds.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,18 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: CBOR transaction database
|
||||
Bundle-SymbolicName: com.minres.scviewer.database.ftr
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: MINRES Technologies GmbH
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Import-Package: org.osgi.framework;version="1.3.0",
|
||||
org.slf4j;version="1.7.2"
|
||||
Require-Bundle: com.minres.scviewer.database,
|
||||
org.eclipse.osgi.services;bundle-version="3.4.0",
|
||||
com.google.guava;bundle-version="15.0.0",
|
||||
org.eclipse.collections;bundle-version="10.4.0",
|
||||
org.apache.commons.compress;bundle-version="1.20.0"
|
||||
Service-Component: OSGI-INF/component.xml
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Automatic-Module-Name: com.minres.scviewer.database.ftr
|
||||
Bundle-ClassPath: .
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="FtrDbLoaderFactory">
|
||||
<implementation class="com.minres.scviewer.database.ftr.FtrDbLoaderFactory"/>
|
||||
<service>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbLoaderFactory"/>
|
||||
</service>
|
||||
</scr:component>
|
|
@ -0,0 +1,14 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2014, 2015-2021 MINRES Technologies GmbH and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# MINRES Technologies GmbH - initial API and implementation
|
||||
###############################################################################
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
OSGI-INF/
|
||||
source.. = src/
|
|
@ -0,0 +1,14 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>com.minres.scviewer.database.ftr</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,190 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.minres.scviewer.database.EventEntry;
|
||||
import com.minres.scviewer.database.EventList;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IEvent;
|
||||
import com.minres.scviewer.database.IEventList;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.WaveformType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
|
||||
/**
|
||||
* The Class AbstractTxStream.
|
||||
*/
|
||||
abstract class AbstractTxStream extends HierNode implements IWaveform {
|
||||
|
||||
private final String fullName;
|
||||
|
||||
/** The id. */
|
||||
private Long id;
|
||||
|
||||
/** The loader. */
|
||||
protected FtrDbLoader loader;
|
||||
|
||||
/** The events. */
|
||||
IEventList events = new EventList();
|
||||
|
||||
/** The max concurrency. */
|
||||
private int rowCount = -1;
|
||||
|
||||
/**
|
||||
* Instantiates a new abstract tx stream.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
*/
|
||||
protected AbstractTxStream(FtrDbLoader loader, Long id, String name) {
|
||||
super(name);
|
||||
fullName=name;
|
||||
this.loader = loader;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full hierarchical name.
|
||||
*
|
||||
* @return the full name
|
||||
*/
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
/**
|
||||
* Adds the event.
|
||||
*
|
||||
* @param evt the evt
|
||||
*/
|
||||
public void addEvent(ITxEvent evt) {
|
||||
events.put(evt.getTime(), evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the events.
|
||||
*
|
||||
* @return the events
|
||||
*/
|
||||
@Override
|
||||
public IEventList getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the events at time.
|
||||
*
|
||||
* @param time the time
|
||||
* @return the events at time
|
||||
*/
|
||||
@Override
|
||||
public IEvent[] getEventsAtTime(long time) {
|
||||
return events.get(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the events before time.
|
||||
*
|
||||
* @param time the time
|
||||
* @return the events before time
|
||||
*/
|
||||
@Override
|
||||
public IEvent[] getEventsBeforeTime(long time) {
|
||||
EventEntry e = events.floorEntry(time);
|
||||
if (e == null)
|
||||
return new IEvent[] {};
|
||||
else
|
||||
return events.floorEntry(time).events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@Override
|
||||
public WaveformType getType() {
|
||||
return WaveformType.TRANSACTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width.
|
||||
*
|
||||
* @return the width
|
||||
*/
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
if (rowCount<0)
|
||||
calculateConcurrency();
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate concurrency.
|
||||
*/
|
||||
void calculateConcurrency() {
|
||||
if (rowCount>=0)
|
||||
return;
|
||||
ArrayList<Long> rowEndTime = new ArrayList<>();
|
||||
HashMap<Long, Integer> rowByTxId = new HashMap<>();
|
||||
for(EventEntry entry: events) {
|
||||
for(IEvent evt:entry.events) {
|
||||
TxEvent txEvt = (TxEvent) evt;
|
||||
ITx tx = txEvt.getTransaction();
|
||||
int rowIdx = 0;
|
||||
switch(evt.getKind()) {
|
||||
case END: //TODO: might throw NPE in concurrent execution
|
||||
Long txId = txEvt.getTransaction().getId();
|
||||
txEvt.setConcurrencyIndex(rowByTxId.get(txId));
|
||||
rowByTxId.remove(txId);
|
||||
break;
|
||||
case SINGLE:
|
||||
for (; rowIdx < rowEndTime.size() && rowEndTime.get(rowIdx)>tx.getBeginTime(); rowIdx++);
|
||||
if (rowEndTime.size() <= rowIdx)
|
||||
rowEndTime.add(tx.getEndTime());
|
||||
else
|
||||
rowEndTime.set(rowIdx, tx.getEndTime());
|
||||
((TxEvent) evt).setConcurrencyIndex(rowIdx);
|
||||
break;
|
||||
case BEGIN:
|
||||
for (; rowIdx < rowEndTime.size() && rowEndTime.get(rowIdx)>tx.getBeginTime(); rowIdx++);
|
||||
if (rowEndTime.size() <= rowIdx)
|
||||
rowEndTime.add(tx.getEndTime());
|
||||
else
|
||||
rowEndTime.set(rowIdx, tx.getEndTime());
|
||||
((TxEvent) evt).setConcurrencyIndex(rowIdx);
|
||||
rowByTxId.put(tx.getId(), rowIdx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rowCount=rowEndTime.size()>0?rowEndTime.size():1;
|
||||
//getChildNodes().parallelStream().forEach(c -> ((TxGenerator)c).calculateConcurrency());
|
||||
getChildNodes().stream().forEach(c -> ((TxGenerator)c).calculateConcurrency());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,475 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.EventKind;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.RelationTypeFactory;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
import jacob.CborDecoder;
|
||||
import jacob.CborType;
|
||||
|
||||
/**
|
||||
* The Class TextDbLoader.
|
||||
*/
|
||||
public class FtrDbLoader implements IWaveformDbLoader {
|
||||
|
||||
enum FileType { NONE, PLAIN, GZIP, LZ4};
|
||||
|
||||
/** The max time. */
|
||||
private Long maxTime = 0L;
|
||||
|
||||
ArrayList<String> strDict = new ArrayList<>();
|
||||
|
||||
|
||||
/** The attr values. */
|
||||
final List<String> attrValues = new ArrayList<>();
|
||||
|
||||
/** The relation types. */
|
||||
final Map<String, RelationType> relationTypes = UnifiedMap.newMap();
|
||||
|
||||
/** The tx streams. */
|
||||
final Map<Long, TxStream> txStreams = UnifiedMap.newMap();
|
||||
|
||||
/** The tx generators. */
|
||||
final Map<Long, TxGenerator> txGenerators = UnifiedMap.newMap();
|
||||
|
||||
/** The transactions. */
|
||||
final Map<Long, FtrTx> transactions = UnifiedMap.newMap();
|
||||
|
||||
/** The attribute types. */
|
||||
final Map<String, TxAttributeType> attributeTypes = UnifiedMap.newMap();
|
||||
|
||||
/** The relations in. */
|
||||
final HashMultimap<Long, FtrRelation> relationsIn = HashMultimap.create();
|
||||
|
||||
/** The relations out. */
|
||||
final HashMultimap<Long, FtrRelation> relationsOut = HashMultimap.create();
|
||||
|
||||
/** The tx cache. */
|
||||
final Map<Long, Tx> txCache = UnifiedMap.newMap();
|
||||
|
||||
/** The threads. */
|
||||
List<Thread> threads = new ArrayList<>();
|
||||
|
||||
File file;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FtrDbLoader.class);
|
||||
|
||||
/** The pcs. */
|
||||
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
/** The Constant x. */
|
||||
static final byte[] x = "scv_tr_stream".getBytes();
|
||||
|
||||
/**
|
||||
* Adds the property change listener.
|
||||
*
|
||||
* @param l the l
|
||||
*/
|
||||
@Override
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the property change listener.
|
||||
*
|
||||
* @param l the l
|
||||
*/
|
||||
@Override
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
pcs.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the max time.
|
||||
*
|
||||
* @return the max time
|
||||
*/
|
||||
@Override
|
||||
public long getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transaction.
|
||||
*
|
||||
* @param txId the tx id
|
||||
* @return the transaction
|
||||
*/
|
||||
public ITx getTransaction(long txId) {
|
||||
if (txCache.containsKey(txId))
|
||||
return txCache.get(txId);
|
||||
if(transactions.containsKey(txId)) {
|
||||
Tx tx = new Tx(this, transactions.get(txId));
|
||||
txCache.put(txId, tx);
|
||||
return tx;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public FtrTx getScvTx(long id) {
|
||||
if(transactions.containsKey(id))
|
||||
return transactions.get(id);
|
||||
else
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the all waves.
|
||||
*
|
||||
* @return the all waves
|
||||
*/
|
||||
@Override
|
||||
public Collection<IWaveform> getAllWaves() {
|
||||
ArrayList<IWaveform> ret = new ArrayList<>(txStreams.values());
|
||||
ret.addAll(txGenerators.values());
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the all relation types.
|
||||
*
|
||||
* @return the all relation types
|
||||
*/
|
||||
public Collection<RelationType> getAllRelationTypes() {
|
||||
return relationTypes.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load.
|
||||
*
|
||||
* @param db the db
|
||||
* @param file the file
|
||||
* @return true, if successful
|
||||
* @throws InputFormatException the input format exception
|
||||
*/
|
||||
@Override
|
||||
public void load(IWaveformDb db, File file) throws InputFormatException {
|
||||
dispose();
|
||||
this.file=file;
|
||||
try(FileInputStream fis = new FileInputStream(file)) {
|
||||
new CborDbParser(this, fis);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error parsing file "+file.getName(), e);
|
||||
transactions.clear();
|
||||
throw new InputFormatException(e.toString());
|
||||
}
|
||||
txStreams.values().parallelStream().forEach(TxStream::calculateConcurrency);
|
||||
}
|
||||
|
||||
public List<? extends byte[]> getChunksAtOffsets(ArrayList<Long> fileOffsets) throws InputFormatException {
|
||||
List<byte[]> ret = new ArrayList<>();
|
||||
try(FileInputStream fis = new FileInputStream(file)) {
|
||||
FileChannel fc = fis.getChannel();
|
||||
for (Long offset : fileOffsets) {
|
||||
fc.position(offset);
|
||||
CborDecoder parser = new CborDecoder(fis);
|
||||
ret.add(parser.readByteString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error parsing file "+file.getName(), e);
|
||||
transactions.clear();
|
||||
throw new InputFormatException(e.toString());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<? extends ITxAttribute> parseAtrributes(byte[] chunk, long blockOffset) {
|
||||
List<ITxAttribute> ret = new ArrayList<>();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(chunk);
|
||||
bais.skip(blockOffset);
|
||||
CborDecoder cborDecoder = new CborDecoder(bais);
|
||||
try {
|
||||
long tx_size = cborDecoder.readArrayLength();
|
||||
for(long i = 0; i<tx_size; ++i) {
|
||||
long tag = cborDecoder.readTag();
|
||||
switch((int)tag) {
|
||||
case 6: // id/generator/start/end
|
||||
long len = cborDecoder.readArrayLength();
|
||||
assert(len==4);
|
||||
cborDecoder.readInt();
|
||||
cborDecoder.readInt();
|
||||
cborDecoder.readInt();
|
||||
cborDecoder.readInt();
|
||||
break;
|
||||
default: { // skip over 7:begin attr, 8:record attr, 9:end attr
|
||||
long sz = cborDecoder.readArrayLength();
|
||||
assert(sz==3);
|
||||
long name_id = cborDecoder.readInt();
|
||||
long type_id = cborDecoder.readInt();
|
||||
String attrName = strDict.get((int)name_id);
|
||||
if(!attributeTypes.containsKey(attrName)) {
|
||||
attributeTypes.put(attrName, new TxAttributeType(attrName, DataType.values()[(int)type_id], AssociationType.values()[(int)tag-7]));
|
||||
}
|
||||
TxAttributeType attrType = attributeTypes.get(attrName);
|
||||
switch((int)type_id) {
|
||||
case 0: // BOOLEAN
|
||||
ITxAttribute b = new TxAttribute(attrType, cborDecoder.readInt()>0?"True":"False");
|
||||
ret.add(b);
|
||||
break;
|
||||
case 2: // INTEGER
|
||||
case 3: // UNSIGNED
|
||||
ITxAttribute a = new TxAttribute(attrType, String.valueOf(cborDecoder.readInt()));
|
||||
ret.add(a);
|
||||
break;
|
||||
case 4: // FLOATING_POINT_NUMBER
|
||||
case 7: // FIXED_POINT_INTEGER
|
||||
case 8: // UNSIGNED_FIXED_POINT_INTEGER
|
||||
ITxAttribute v = new TxAttribute(attrType, String.valueOf(cborDecoder.readFloat()));
|
||||
ret.add(v);
|
||||
break;
|
||||
case 1: // ENUMERATION
|
||||
case 5: // BIT_VECTOR
|
||||
case 6: // LOGIC_VECTOR
|
||||
case 12: // STRING
|
||||
ITxAttribute s = new TxAttribute(attrType, strDict.get((int)cborDecoder.readInt()));
|
||||
ret.add(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error parsing file "+file.getName(), e);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispose.
|
||||
*/
|
||||
@Override
|
||||
public void dispose() {
|
||||
attrValues.clear();
|
||||
relationTypes.clear();
|
||||
txStreams.clear();
|
||||
txGenerators.clear();
|
||||
transactions.clear();
|
||||
attributeTypes.clear();
|
||||
relationsIn.clear();
|
||||
relationsOut.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class TextDbParser.
|
||||
*/
|
||||
static class CborDbParser extends CborDecoder {
|
||||
|
||||
static final private CborType break_type = CborType.valueOf(0xff);
|
||||
|
||||
/** The loader. */
|
||||
final FtrDbLoader loader;
|
||||
|
||||
/**
|
||||
* Instantiates a new text db parser.
|
||||
*
|
||||
* @param loader the loader
|
||||
*/
|
||||
public CborDbParser(FtrDbLoader loader, FileInputStream inputStream) {
|
||||
super(inputStream);
|
||||
this.loader = loader;
|
||||
try {
|
||||
long cbor_tag = readTag();
|
||||
assert(cbor_tag == 55799);
|
||||
long array_len = readArrayLength();
|
||||
assert(array_len==-1);
|
||||
CborType next = peekType();
|
||||
while(next != null && !break_type.isEqualType(next)) {
|
||||
long tag = readTag();
|
||||
switch((int)tag) {
|
||||
case 6: // info
|
||||
break;
|
||||
case 8: { // dictionary uncompressed
|
||||
parseDict(new CborDecoder(new ByteArrayInputStream(readByteString())));
|
||||
break;
|
||||
}
|
||||
case 10: { // directory uncompressed
|
||||
parseDir(new CborDecoder(new ByteArrayInputStream(readByteString())));
|
||||
break;
|
||||
}
|
||||
case 12: { //tx chunk uncompressed
|
||||
long len = readArrayLength();
|
||||
assert(len==2);
|
||||
long stream_id = readInt();
|
||||
TxStream txStream = loader.txStreams.get(stream_id);
|
||||
txStream.fileOffsets.add(inputStream.getChannel().position());
|
||||
parseTx(txStream, txStream.fileOffsets.size()-1, readByteString());
|
||||
break;
|
||||
}
|
||||
case 14: { // relations uncompressed
|
||||
parseRel(new CborDecoder(new ByteArrayInputStream(readByteString())));
|
||||
break;
|
||||
}
|
||||
}
|
||||
next = peekType();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
LOG.error("Error parsing file input stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void parseDict(CborDecoder cborDecoder) throws IOException {
|
||||
long size = cborDecoder.readMapLength();
|
||||
ArrayList<String> lst = new ArrayList<>((int)size);
|
||||
for(long i = 0; i<size; ++i) {
|
||||
long idx = cborDecoder.readInt();
|
||||
assert(idx==loader.strDict.size()+1);
|
||||
lst.add(cborDecoder.readTextString());
|
||||
}
|
||||
loader.strDict.addAll(lst);
|
||||
}
|
||||
|
||||
private void parseDir(CborDecoder cborDecoder) throws IOException {
|
||||
long size = cborDecoder.readArrayLength();
|
||||
if(size<0) {
|
||||
CborType next = cborDecoder.peekType();
|
||||
while(next != null && !break_type.isEqualType(next)) {
|
||||
parseDictEntry(cborDecoder);
|
||||
next = cborDecoder.peekType();
|
||||
}
|
||||
} else
|
||||
for(long i = 0; i<size; ++i) {
|
||||
parseDictEntry(cborDecoder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void parseDictEntry(CborDecoder cborDecoder) throws IOException {
|
||||
long id = cborDecoder.readTag();
|
||||
if(id==16) { // a stream
|
||||
long len = cborDecoder.readArrayLength();
|
||||
assert(len==3);
|
||||
long stream_id = cborDecoder.readInt();
|
||||
long name_id = cborDecoder.readInt();
|
||||
long kind_id = cborDecoder.readInt();
|
||||
add(stream_id, new TxStream(loader, stream_id, loader.strDict.get((int)name_id), loader.strDict.get((int)kind_id)));
|
||||
} else if(id==17) { // a generator
|
||||
long len = cborDecoder.readArrayLength();
|
||||
assert(len==3);
|
||||
long gen_id = cborDecoder.readInt();
|
||||
long name_id = cborDecoder.readInt();
|
||||
long stream_id = cborDecoder.readInt();
|
||||
add(gen_id, new TxGenerator(loader, gen_id, loader.strDict.get((int)name_id), loader.txStreams.get(stream_id)));
|
||||
} else {
|
||||
throw new IOException("Illegal tage ncountered: "+id);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseTx(TxStream txStream, long blockId, byte[] chunk) throws IOException {
|
||||
CborDecoder cborDecoder = new CborDecoder(new ByteArrayInputStream(chunk));
|
||||
long size = cborDecoder.readArrayLength();
|
||||
assert(size==-1);
|
||||
CborType next = cborDecoder.peekType();
|
||||
while(next != null && !break_type.isEqualType(next)) {
|
||||
long blockOffset = cborDecoder.getPos();
|
||||
long tx_size = cborDecoder.readArrayLength();
|
||||
for(long i = 0; i<tx_size; ++i) {
|
||||
long tag = cborDecoder.readTag();
|
||||
switch((int)tag) {
|
||||
case 6: // id/generator/start/end
|
||||
long len = cborDecoder.readArrayLength();
|
||||
assert(len==4);
|
||||
long txId = cborDecoder.readInt();
|
||||
long genId = cborDecoder.readInt();
|
||||
long startTime = cborDecoder.readInt()*1000; //TODO: scale based on info
|
||||
long endTime = cborDecoder.readInt()*1000; //TODO: scale based on info
|
||||
TxGenerator gen = loader.txGenerators.get(genId);
|
||||
FtrTx scvTx = new FtrTx(txId, gen.stream.getId(), genId, startTime, endTime, blockId, blockOffset);
|
||||
loader.maxTime = loader.maxTime > scvTx.endTime ? loader.maxTime : scvTx.endTime;
|
||||
loader.transactions.put(txId, scvTx);
|
||||
TxStream stream = loader.txStreams.get(gen.stream.getId());
|
||||
if (scvTx.beginTime == scvTx.endTime) {
|
||||
stream.addEvent(new TxEvent(loader, EventKind.SINGLE, txId, scvTx.beginTime));
|
||||
gen.addEvent(new TxEvent(loader, EventKind.SINGLE, txId, scvTx.beginTime));
|
||||
} else {
|
||||
stream.addEvent(new TxEvent(loader, EventKind.BEGIN, txId, scvTx.beginTime));
|
||||
gen.addEvent(new TxEvent(loader, EventKind.BEGIN, txId, scvTx.beginTime));
|
||||
stream.addEvent(new TxEvent(loader, EventKind.END, txId, scvTx.endTime));
|
||||
gen.addEvent(new TxEvent(loader, EventKind.END, txId, scvTx.endTime));
|
||||
}
|
||||
break;
|
||||
default: { // skip over 7:begin attr, 8:record attr, 9:end attr
|
||||
long sz = cborDecoder.readArrayLength();
|
||||
assert(sz==3);
|
||||
for(long j = 0; j<sz; ++j)
|
||||
cborDecoder.readInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
next = cborDecoder.peekType();
|
||||
}
|
||||
}
|
||||
|
||||
private void parseRel(CborDecoder cborDecoder) throws IOException {
|
||||
long size = cborDecoder.readArrayLength();
|
||||
assert(size==-1);
|
||||
CborType next = cborDecoder.peekType();
|
||||
while(next != null && !break_type.isEqualType(next)) {
|
||||
long sz = cborDecoder.readArrayLength();
|
||||
assert(sz==3);
|
||||
long type_id = cborDecoder.readInt();
|
||||
long from_id = cborDecoder.readInt();
|
||||
long to_id = cborDecoder.readInt();
|
||||
String rel_name = loader.strDict.get((int)type_id);
|
||||
FtrRelation ftrRel = new FtrRelation(loader.relationTypes.getOrDefault(rel_name, RelationTypeFactory.create(rel_name)), from_id, to_id);
|
||||
loader.relationsOut.put(from_id, ftrRel);
|
||||
loader.relationsIn.put(to_id, ftrRel);
|
||||
next = cborDecoder.peekType();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void add(Long id, TxStream stream) {
|
||||
loader.txStreams.put(id, stream);
|
||||
loader.pcs.firePropertyChange(IWaveformDbLoader.STREAM_ADDED, null, stream);
|
||||
}
|
||||
|
||||
private void add(Long id, TxGenerator generator) {
|
||||
loader.txGenerators.put(id, generator);
|
||||
loader.pcs.firePropertyChange(IWaveformDbLoader.GENERATOR_ADDED, null, generator);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.apache.commons.compress.compressors.lz4.FramedLZ4CompressorInputStream;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.IWaveformDbLoaderFactory;
|
||||
import com.minres.scviewer.database.ftr.FtrDbLoader.FileType;
|
||||
|
||||
/**
|
||||
* The Class TextDbLoader.
|
||||
*/
|
||||
public class FtrDbLoaderFactory implements IWaveformDbLoaderFactory {
|
||||
|
||||
public static byte[] hexStringToByteArray(String s) {
|
||||
int len = s.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
|
||||
+ Character.digit(s.charAt(i+1), 16));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/** The Constant x. */
|
||||
static final byte[] x = hexStringToByteArray("d9d9f79f");
|
||||
|
||||
/**
|
||||
* Can load.
|
||||
*
|
||||
* @param inputFile the input file
|
||||
* @return true, if successful
|
||||
*/
|
||||
@Override
|
||||
public boolean canLoad(File inputFile) {
|
||||
try (InputStream is = new FileInputStream(inputFile)) {
|
||||
byte[] buffer = new byte[x.length];
|
||||
int readCnt = is.read(buffer, 0, x.length);
|
||||
if (readCnt == x.length) {
|
||||
for (int i = 0; i < x.length; i++)
|
||||
if (buffer[i] != x[i]) return false;
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDbLoader getLoader() {
|
||||
return new FtrDbLoader();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
/**
|
||||
* The Class ScvRelation.
|
||||
*/
|
||||
class FtrRelation implements Serializable {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = -347668857680574140L;
|
||||
|
||||
/** The source. */
|
||||
final long source;
|
||||
|
||||
/** The target. */
|
||||
final long target;
|
||||
|
||||
/** The relation type. */
|
||||
final RelationType relationType;
|
||||
|
||||
/**
|
||||
* Instantiates a new scv relation.
|
||||
*
|
||||
* @param relationType the relation type
|
||||
* @param source the source
|
||||
* @param target the target
|
||||
*/
|
||||
public FtrRelation(RelationType relationType, long source, long target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.relationType = relationType;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
|
||||
import jacob.CborDecoder;
|
||||
|
||||
/**
|
||||
* The Class ScvTx.
|
||||
*/
|
||||
class FtrTx implements Serializable {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = -855200240003328221L;
|
||||
|
||||
/** The id. */
|
||||
final long id;
|
||||
|
||||
/** The generator id. */
|
||||
final long generatorId;
|
||||
|
||||
/** The stream id. */
|
||||
final long streamId;
|
||||
|
||||
/** The begin time. */
|
||||
long beginTime;
|
||||
|
||||
/** The end time. */
|
||||
long endTime;
|
||||
|
||||
/** The attributes. */
|
||||
final List<ITxAttribute> attributes = new ArrayList<>();
|
||||
|
||||
final long blockId;
|
||||
|
||||
final long blockOffset;
|
||||
|
||||
/**
|
||||
* Instantiates a new scv tx.
|
||||
*
|
||||
* @param id the id
|
||||
* @param streamId the stream id
|
||||
* @param generatorId the generator id
|
||||
* @param begin the begin
|
||||
*/
|
||||
FtrTx(long id, long streamId, long generatorId, long begin, long end, long blockId, long blockOffset) {
|
||||
this.id = id;
|
||||
this.streamId = streamId;
|
||||
this.generatorId = generatorId;
|
||||
this.beginTime = begin;
|
||||
this.endTime = end;
|
||||
this.blockId=blockId;
|
||||
this.blockOffset=blockOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<ITxAttribute> getAttributes(FtrDbLoader loader) {
|
||||
if(attributes.size()==0)
|
||||
try {
|
||||
TxStream stream = loader.txStreams.get(streamId);
|
||||
byte[] chunk = stream.getChunks().get((int)blockId);
|
||||
attributes.addAll(loader.parseAtrributes(chunk, blockOffset));
|
||||
} catch (InputFormatException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
import com.minres.scviewer.database.tx.ITxRelation;
|
||||
|
||||
/**
|
||||
* The Class Tx.
|
||||
*/
|
||||
class Tx implements ITx {
|
||||
|
||||
/** The loader. */
|
||||
private final FtrDbLoader loader;
|
||||
|
||||
private FtrTx scvTx =null;
|
||||
|
||||
/** The id. */
|
||||
private final long id;
|
||||
|
||||
private final long generatorId;
|
||||
|
||||
private final long streamId;
|
||||
|
||||
/** The begin time. */
|
||||
long beginTime = -1;
|
||||
|
||||
/** The end time. */
|
||||
long endTime = -1;
|
||||
|
||||
/**
|
||||
* Instantiates a new tx.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param scvTx the scv tx
|
||||
*/
|
||||
public Tx(FtrDbLoader loader, FtrTx scvTx) {
|
||||
this.loader = loader;
|
||||
id = scvTx.id;
|
||||
this.scvTx=scvTx;
|
||||
generatorId=scvTx.generatorId;
|
||||
streamId=scvTx.streamId;
|
||||
beginTime=scvTx.beginTime;
|
||||
endTime=scvTx.endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new tx.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param txId the tx id
|
||||
*/
|
||||
public Tx(FtrDbLoader loader, long id, long generatorId, long streamId) {
|
||||
this.loader = loader;
|
||||
this.id = id;
|
||||
this.generatorId=generatorId;
|
||||
this.streamId = streamId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the incoming relations.
|
||||
*
|
||||
* @return the incoming relations
|
||||
*/
|
||||
@Override
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
Set<FtrRelation> rels = loader.relationsIn.get(id);
|
||||
return rels.stream().map(rel -> new TxRelation(loader, rel)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the outgoing relations.
|
||||
*
|
||||
* @return the outgoing relations
|
||||
*/
|
||||
@Override
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
Set<FtrRelation> rels = loader.relationsOut.get(id);
|
||||
return rels.stream().map(rel -> new TxRelation(loader, rel)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare to.
|
||||
*
|
||||
* @param o the o
|
||||
* @return the int
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(ITx o) {
|
||||
int res = Long.compare(getBeginTime(), o.getBeginTime());
|
||||
if (res != 0)
|
||||
return res;
|
||||
else
|
||||
return Long.compare(getId(), o.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals.
|
||||
*
|
||||
* @param obj the obj
|
||||
* @return true, if successful
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || getClass() != obj.getClass())
|
||||
return false;
|
||||
return this.getScvTx().equals(((Tx) obj).getScvTx());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash code.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getScvTx().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tx#" + getId() + "[" + getBeginTime() / 1000000 + "ns - " + getEndTime() / 1000000 + "ns]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
@Override
|
||||
public long getId() {
|
||||
return getScvTx().id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stream.
|
||||
*
|
||||
* @return the stream
|
||||
*/
|
||||
@Override
|
||||
public IWaveform getStream() {
|
||||
return loader.txStreams.get(streamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the generator.
|
||||
*
|
||||
* @return the generator
|
||||
*/
|
||||
@Override
|
||||
public IWaveform getGenerator() {
|
||||
return loader.txGenerators.get(generatorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the begin time.
|
||||
*
|
||||
* @return the begin time
|
||||
*/
|
||||
@Override
|
||||
public long getBeginTime() {
|
||||
if (beginTime < 0) {
|
||||
FtrTx tx = scvTx==null?loader.getScvTx(id):getScvTx();
|
||||
beginTime = tx.beginTime;
|
||||
endTime = tx.endTime;
|
||||
}
|
||||
return beginTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the end time.
|
||||
*
|
||||
* @return the end time
|
||||
*/
|
||||
@Override
|
||||
public long getEndTime() {
|
||||
if (endTime < 0) {
|
||||
FtrTx tx = scvTx==null?loader.getScvTx(id):getScvTx();
|
||||
beginTime = tx.beginTime;
|
||||
endTime = tx.endTime;
|
||||
}
|
||||
return endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the end time.
|
||||
*
|
||||
* @param time the new end time
|
||||
*/
|
||||
void setEndTime(Long time) {
|
||||
getScvTx().endTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attributes.
|
||||
*
|
||||
* @return the attributes
|
||||
*/
|
||||
@Override
|
||||
public List<ITxAttribute> getAttributes() {
|
||||
return getScvTx().getAttributes(loader);
|
||||
}
|
||||
|
||||
private FtrTx getScvTx() {
|
||||
if(scvTx==null)
|
||||
scvTx=loader.getScvTx(id);
|
||||
return scvTx;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
|
||||
/**
|
||||
* The Class TxAttribute.
|
||||
*/
|
||||
public class TxAttribute implements ITxAttribute, Serializable {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = 4767726016651807152L;
|
||||
|
||||
/** The attribute type. */
|
||||
private final TxAttributeType attributeType;
|
||||
|
||||
/** The value. */
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* Instantiates a new tx attribute.
|
||||
*
|
||||
* @param type the type
|
||||
* @param value the value
|
||||
*/
|
||||
TxAttribute(TxAttributeType type, String value) {
|
||||
this.attributeType = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return attributeType.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@Override
|
||||
public AssociationType getType() {
|
||||
return attributeType.getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data type.
|
||||
*
|
||||
* @return the data type
|
||||
*/
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
return attributeType.getDataType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType;
|
||||
|
||||
/**
|
||||
* The Class TxAttributeType.
|
||||
*/
|
||||
class TxAttributeType implements ITxAttributeType, Serializable {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = 7159721937208946828L;
|
||||
|
||||
/** The name. */
|
||||
private String name;
|
||||
|
||||
/** The data type. */
|
||||
private DataType dataType;
|
||||
|
||||
/** The type. */
|
||||
private AssociationType type;
|
||||
|
||||
/**
|
||||
* Instantiates a new tx attribute type.
|
||||
*
|
||||
* @param name the name
|
||||
* @param dataType the data type
|
||||
* @param type the type
|
||||
*/
|
||||
TxAttributeType(String name, DataType dataType, AssociationType type) {
|
||||
this.name = name;
|
||||
this.dataType = dataType;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data type.
|
||||
*
|
||||
* @return the data type
|
||||
*/
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@Override
|
||||
public AssociationType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + ":" + dataType.name() + "@" + type.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import com.minres.scviewer.database.EventKind;
|
||||
import com.minres.scviewer.database.WaveformType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
|
||||
/**
|
||||
* The Class TxEvent.
|
||||
*/
|
||||
class TxEvent implements ITxEvent {
|
||||
|
||||
/** The loader. */
|
||||
final FtrDbLoader loader;
|
||||
|
||||
/** The kind. */
|
||||
final EventKind kind;
|
||||
|
||||
/** The transaction. */
|
||||
final long transaction;
|
||||
|
||||
/** The time. */
|
||||
final long time;
|
||||
|
||||
private int concurrencyIdx=-1;
|
||||
/**
|
||||
* Instantiates a new tx event.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param kind the kind
|
||||
* @param transaction the transaction
|
||||
* @param time the time
|
||||
*/
|
||||
TxEvent(FtrDbLoader loader, EventKind kind, Long transaction, Long time) {
|
||||
this.loader = loader;
|
||||
this.kind = kind;
|
||||
this.transaction = transaction;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate.
|
||||
*
|
||||
* @return the i tx event
|
||||
* @throws CloneNotSupportedException the clone not supported exception
|
||||
*/
|
||||
@Override
|
||||
public ITxEvent duplicate() throws CloneNotSupportedException {
|
||||
return new TxEvent(loader, kind, transaction, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return kind.toString() + "@" + time + " of tx #" + transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@Override
|
||||
public WaveformType getType() {
|
||||
return WaveformType.TRANSACTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the kind.
|
||||
*
|
||||
* @return the kind
|
||||
*/
|
||||
@Override
|
||||
public EventKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time.
|
||||
*
|
||||
* @return the time
|
||||
*/
|
||||
@Override
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transaction.
|
||||
*
|
||||
* @return the transaction
|
||||
*/
|
||||
@Override
|
||||
public ITx getTransaction() {
|
||||
return loader.getTransaction(transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowIndex() {
|
||||
return concurrencyIdx;
|
||||
}
|
||||
|
||||
public void setConcurrencyIndex(int idx) {
|
||||
concurrencyIdx=idx;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
|
||||
/**
|
||||
* The Class TxGenerator.
|
||||
*/
|
||||
class TxGenerator extends AbstractTxStream {
|
||||
|
||||
/** The stream. */
|
||||
TxStream stream;
|
||||
|
||||
/** The begin attrs. */
|
||||
List<TxAttributeType> beginAttrs = new ArrayList<>();
|
||||
|
||||
/** The end attrs. */
|
||||
List<TxAttributeType> endAttrs = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new tx generator.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
* @param stream the stream
|
||||
*/
|
||||
TxGenerator(FtrDbLoader loader, Long id, String name, TxStream stream) {
|
||||
super(loader, id, name);
|
||||
this.stream = stream;
|
||||
stream.addChild(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is same.
|
||||
*
|
||||
* @param other the other
|
||||
* @return true, if is same
|
||||
*/
|
||||
@Override
|
||||
public boolean isSame(IWaveform other) {
|
||||
return (other instanceof TxGenerator && this.getId()==other.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the begin attrs.
|
||||
*
|
||||
* @return the begin attrs
|
||||
*/
|
||||
public List<TxAttributeType> getBeginAttrs() {
|
||||
return beginAttrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the end attrs.
|
||||
*
|
||||
* @return the end attrs
|
||||
*/
|
||||
public List<TxAttributeType> getEndAttrs() {
|
||||
return endAttrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the kind.
|
||||
*
|
||||
* @return the kind
|
||||
*/
|
||||
@Override
|
||||
public String getKind() {
|
||||
return stream.getKind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full hierarchical name.
|
||||
*
|
||||
* @return the full name
|
||||
*/
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return ((AbstractTxStream)parent).getFullName()+"."+name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxRelation;
|
||||
|
||||
/**
|
||||
* The Class TxRelation.
|
||||
*/
|
||||
class TxRelation implements ITxRelation {
|
||||
|
||||
/** The loader. */
|
||||
final FtrDbLoader loader;
|
||||
|
||||
/** The scv relation. */
|
||||
final FtrRelation scvRelation;
|
||||
|
||||
/**
|
||||
* Instantiates a new tx relation.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param scvRelation the scv relation
|
||||
*/
|
||||
public TxRelation(FtrDbLoader loader, FtrRelation scvRelation) {
|
||||
this.loader = loader;
|
||||
this.scvRelation = scvRelation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relation type.
|
||||
*
|
||||
* @return the relation type
|
||||
*/
|
||||
@Override
|
||||
public RelationType getRelationType() {
|
||||
return scvRelation.relationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source.
|
||||
*
|
||||
* @return the source
|
||||
*/
|
||||
@Override
|
||||
public ITx getSource() {
|
||||
return loader.getTransaction(scvRelation.source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the target.
|
||||
*
|
||||
* @return the target
|
||||
*/
|
||||
@Override
|
||||
public ITx getTarget() {
|
||||
return loader.getTransaction(scvRelation.target);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
|
||||
/**
|
||||
* The Class TxStream.
|
||||
*/
|
||||
class TxStream extends AbstractTxStream {
|
||||
|
||||
/** The kind. */
|
||||
final String kind;
|
||||
|
||||
final ArrayList<Long> fileOffsets = new ArrayList<>();
|
||||
|
||||
final ArrayList<byte[]> chunks = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new tx stream.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
* @param kind the kind
|
||||
*/
|
||||
TxStream(FtrDbLoader loader, Long id, String name, String kind) {
|
||||
super(loader, id, name);
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is same.
|
||||
*
|
||||
* @param other the other
|
||||
* @return true, if is same
|
||||
*/
|
||||
@Override
|
||||
public boolean isSame(IWaveform other) {
|
||||
return (other instanceof TxStream && this.getId() == other.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the kind.
|
||||
*
|
||||
* @return the kind
|
||||
*/
|
||||
@Override
|
||||
public String getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public List<byte[]> getChunks() throws InputFormatException {
|
||||
if(chunks.size()==0) {
|
||||
chunks.addAll(loader.getChunksAtOffsets(fileOffsets));
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* JACOB - CBOR implementation in Java.
|
||||
*
|
||||
* (C) Copyright - 2013 - J.W. Janssen <j.w.janssen@lxtreme.nl>
|
||||
*
|
||||
* Licensed under Apache License v2.0.
|
||||
*/
|
||||
package jacob;
|
||||
|
||||
/**
|
||||
* Constant values used by the CBOR format.
|
||||
*/
|
||||
public interface CborConstants {
|
||||
/** Major type 0: unsigned integers. */
|
||||
int TYPE_UNSIGNED_INTEGER = 0x00;
|
||||
/** Major type 1: negative integers. */
|
||||
int TYPE_NEGATIVE_INTEGER = 0x01;
|
||||
/** Major type 2: byte string. */
|
||||
int TYPE_BYTE_STRING = 0x02;
|
||||
/** Major type 3: text/UTF8 string. */
|
||||
int TYPE_TEXT_STRING = 0x03;
|
||||
/** Major type 4: array of items. */
|
||||
int TYPE_ARRAY = 0x04;
|
||||
/** Major type 5: map of pairs. */
|
||||
int TYPE_MAP = 0x05;
|
||||
/** Major type 6: semantic tags. */
|
||||
int TYPE_TAG = 0x06;
|
||||
/** Major type 7: floating point, simple data types. */
|
||||
int TYPE_FLOAT_SIMPLE = 0x07;
|
||||
|
||||
/** Denotes a one-byte value (uint8). */
|
||||
int ONE_BYTE = 0x18;
|
||||
/** Denotes a two-byte value (uint16). */
|
||||
int TWO_BYTES = 0x19;
|
||||
/** Denotes a four-byte value (uint32). */
|
||||
int FOUR_BYTES = 0x1a;
|
||||
/** Denotes a eight-byte value (uint64). */
|
||||
int EIGHT_BYTES = 0x1b;
|
||||
|
||||
/** The CBOR-encoded boolean <code>false</code> value (encoded as "simple value": {@link #MT_SIMPLE}). */
|
||||
int FALSE = 0x14;
|
||||
/** The CBOR-encoded boolean <code>true</code> value (encoded as "simple value": {@link #MT_SIMPLE}). */
|
||||
int TRUE = 0x15;
|
||||
/** The CBOR-encoded <code>null</code> value (encoded as "simple value": {@link #MT_SIMPLE}). */
|
||||
int NULL = 0x16;
|
||||
/** The CBOR-encoded "undefined" value (encoded as "simple value": {@link #MT_SIMPLE}). */
|
||||
int UNDEFINED = 0x17;
|
||||
/** Denotes a half-precision float (two-byte IEEE 754, see {@link #MT_FLOAT}). */
|
||||
int HALF_PRECISION_FLOAT = 0x19;
|
||||
/** Denotes a single-precision float (four-byte IEEE 754, see {@link #MT_FLOAT}). */
|
||||
int SINGLE_PRECISION_FLOAT = 0x1a;
|
||||
/** Denotes a double-precision float (eight-byte IEEE 754, see {@link #MT_FLOAT}). */
|
||||
int DOUBLE_PRECISION_FLOAT = 0x1b;
|
||||
/** The CBOR-encoded "break" stop code for unlimited arrays/maps. */
|
||||
int BREAK = 0x1f;
|
||||
|
||||
/** Semantic tag value describing date/time values in the standard format (UTF8 string, RFC3339). */
|
||||
int TAG_STANDARD_DATE_TIME = 0;
|
||||
/** Semantic tag value describing date/time values as Epoch timestamp (numeric, RFC3339). */
|
||||
int TAG_EPOCH_DATE_TIME = 1;
|
||||
/** Semantic tag value describing a positive big integer value (byte string). */
|
||||
int TAG_POSITIVE_BIGINT = 2;
|
||||
/** Semantic tag value describing a negative big integer value (byte string). */
|
||||
int TAG_NEGATIVE_BIGINT = 3;
|
||||
/** Semantic tag value describing a decimal fraction value (two-element array, base 10). */
|
||||
int TAG_DECIMAL_FRACTION = 4;
|
||||
/** Semantic tag value describing a big decimal value (two-element array, base 2). */
|
||||
int TAG_BIGDECIMAL = 5;
|
||||
/** Semantic tag value describing an expected conversion to base64url encoding. */
|
||||
int TAG_EXPECTED_BASE64_URL_ENCODED = 21;
|
||||
/** Semantic tag value describing an expected conversion to base64 encoding. */
|
||||
int TAG_EXPECTED_BASE64_ENCODED = 22;
|
||||
/** Semantic tag value describing an expected conversion to base16 encoding. */
|
||||
int TAG_EXPECTED_BASE16_ENCODED = 23;
|
||||
/** Semantic tag value describing an encoded CBOR data item (byte string). */
|
||||
int TAG_CBOR_ENCODED = 24;
|
||||
/** Semantic tag value describing an URL (UTF8 string). */
|
||||
int TAG_URI = 32;
|
||||
/** Semantic tag value describing a base64url encoded string (UTF8 string). */
|
||||
int TAG_BASE64_URL_ENCODED = 33;
|
||||
/** Semantic tag value describing a base64 encoded string (UTF8 string). */
|
||||
int TAG_BASE64_ENCODED = 34;
|
||||
/** Semantic tag value describing a regular expression string (UTF8 string, PCRE). */
|
||||
int TAG_REGEXP = 35;
|
||||
/** Semantic tag value describing a MIME message (UTF8 string, RFC2045). */
|
||||
int TAG_MIME_MESSAGE = 36;
|
||||
/** Semantic tag value describing CBOR content. */
|
||||
int TAG_CBOR_MARKER = 55799;
|
||||
}
|
|
@ -0,0 +1,515 @@
|
|||
/*
|
||||
* JACOB - CBOR implementation in Java.
|
||||
*
|
||||
* (C) Copyright - 2013 - J.W. Janssen <j.w.janssen@lxtreme.nl>
|
||||
*/
|
||||
package jacob;
|
||||
|
||||
import static jacob.CborConstants.*;
|
||||
import static jacob.CborType.*;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
|
||||
/**
|
||||
* Provides a decoder capable of handling CBOR encoded data from a {@link InputStream}.
|
||||
*/
|
||||
public class CborDecoder {
|
||||
protected final PushbackInputStream m_is;
|
||||
|
||||
protected final int total_avail;
|
||||
|
||||
static int getAvailableBytes(PushbackInputStream is) {
|
||||
try {
|
||||
return is.available();
|
||||
} catch (IOException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new {@link CborDecoder} instance.
|
||||
*
|
||||
* @param is the actual input stream to read the CBOR-encoded data from, cannot be <code>null</code>.
|
||||
*/
|
||||
public CborDecoder(InputStream is) {
|
||||
if (is == null) {
|
||||
throw new IllegalArgumentException("InputStream cannot be null!");
|
||||
}
|
||||
m_is = (is instanceof PushbackInputStream) ? (PushbackInputStream) is : new PushbackInputStream(is);
|
||||
total_avail = getAvailableBytes(m_is);
|
||||
}
|
||||
|
||||
private static void fail(String msg, Object... args) throws IOException {
|
||||
throw new IOException(String.format(msg, args));
|
||||
}
|
||||
|
||||
private static String lengthToString(int len) {
|
||||
return (len < 0) ? "no payload" : (len == ONE_BYTE) ? "one byte" : (len == TWO_BYTES) ? "two bytes"
|
||||
: (len == FOUR_BYTES) ? "four bytes" : (len == EIGHT_BYTES) ? "eight bytes" : "(unknown)";
|
||||
}
|
||||
|
||||
public long getPos() {
|
||||
try {
|
||||
return total_avail-m_is.available();
|
||||
} catch (IOException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Peeks in the input stream for the upcoming type.
|
||||
*
|
||||
* @return the upcoming type in the stream, or <code>null</code> in case of an end-of-stream.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-type from the underlying input stream.
|
||||
*/
|
||||
public CborType peekType() throws IOException {
|
||||
int p = m_is.read();
|
||||
if (p < 0) {
|
||||
// EOF, nothing to peek at...
|
||||
return null;
|
||||
}
|
||||
m_is.unread(p);
|
||||
return valueOf(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prolog to reading an array value in CBOR format.
|
||||
*
|
||||
* @return the number of elements in the array to read, or <tt>-1</tt> in case of infinite-length arrays.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public long readArrayLength() throws IOException {
|
||||
return readMajorTypeWithSize(TYPE_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean value in CBOR format.
|
||||
*
|
||||
* @return the read boolean.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public boolean readBoolean() throws IOException {
|
||||
int b = readMajorType(TYPE_FLOAT_SIMPLE);
|
||||
if (b != FALSE && b != TRUE) {
|
||||
fail("Unexpected boolean value: %d!", b);
|
||||
}
|
||||
return b == TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a "break"/stop value in CBOR format.
|
||||
*
|
||||
* @return always <code>null</code>.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public Object readBreak() throws IOException {
|
||||
readMajorTypeExact(TYPE_FLOAT_SIMPLE, BREAK);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a byte string value in CBOR format.
|
||||
*
|
||||
* @return the read byte string, never <code>null</code>. In case the encoded string has a length of <tt>0</tt>, an empty string is returned.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public byte[] readByteString() throws IOException {
|
||||
long len = readMajorTypeWithSize(TYPE_BYTE_STRING);
|
||||
if (len < 0) {
|
||||
fail("Infinite-length byte strings not supported!");
|
||||
}
|
||||
if (len > Integer.MAX_VALUE) {
|
||||
fail("String length too long!");
|
||||
}
|
||||
return readFully(new byte[(int) len]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prolog to reading a byte string value in CBOR format.
|
||||
*
|
||||
* @return the number of bytes in the string to read, or <tt>-1</tt> in case of infinite-length strings.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public long readByteStringLength() throws IOException {
|
||||
return readMajorTypeWithSize(TYPE_BYTE_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a double-precision float value in CBOR format.
|
||||
*
|
||||
* @return the read double value, values from {@link Float#MIN_VALUE} to {@link Float#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public double readDouble() throws IOException {
|
||||
readMajorTypeExact(TYPE_FLOAT_SIMPLE, DOUBLE_PRECISION_FLOAT);
|
||||
|
||||
return Double.longBitsToDouble(readUInt64());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a single-precision float value in CBOR format.
|
||||
*
|
||||
* @return the read float value, values from {@link Float#MIN_VALUE} to {@link Float#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public float readFloat() throws IOException {
|
||||
readMajorTypeExact(TYPE_FLOAT_SIMPLE, SINGLE_PRECISION_FLOAT);
|
||||
|
||||
return Float.intBitsToFloat((int) readUInt32());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a half-precision float value in CBOR format.
|
||||
*
|
||||
* @return the read half-precision float value, values from {@link Float#MIN_VALUE} to {@link Float#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public double readHalfPrecisionFloat() throws IOException {
|
||||
readMajorTypeExact(TYPE_FLOAT_SIMPLE, HALF_PRECISION_FLOAT);
|
||||
|
||||
int half = readUInt16();
|
||||
int exp = (half >> 10) & 0x1f;
|
||||
int mant = half & 0x3ff;
|
||||
|
||||
double val;
|
||||
if (exp == 0) {
|
||||
val = mant * Math.pow(2, -24);
|
||||
} else if (exp != 31) {
|
||||
val = (mant + 1024) * Math.pow(2, exp - 25);
|
||||
} else if (mant != 0) {
|
||||
val = Double.NaN;
|
||||
} else {
|
||||
val = Double.POSITIVE_INFINITY;
|
||||
}
|
||||
|
||||
return ((half & 0x8000) == 0) ? val : -val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed or unsigned integer value in CBOR format.
|
||||
*
|
||||
* @return the read integer value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public long readInt() throws IOException {
|
||||
int ib = m_is.read();
|
||||
|
||||
// in case of negative integers, extends the sign to all bits; otherwise zero...
|
||||
long ui = expectIntegerType(ib);
|
||||
// in case of negative integers does a ones complement
|
||||
return ui ^ readUInt(ib & 0x1f, false /* breakAllowed */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed or unsigned 16-bit integer value in CBOR format.
|
||||
*
|
||||
* @read the small integer value, values from <tt>[-65536..65535]</tt> are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
|
||||
*/
|
||||
public int readInt16() throws IOException {
|
||||
int ib = m_is.read();
|
||||
|
||||
// in case of negative integers, extends the sign to all bits; otherwise zero...
|
||||
long ui = expectIntegerType(ib);
|
||||
// in case of negative integers does a ones complement
|
||||
return (int) (ui ^ readUIntExact(TWO_BYTES, ib & 0x1f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed or unsigned 32-bit integer value in CBOR format.
|
||||
*
|
||||
* @read the small integer value, values in the range <tt>[-4294967296..4294967295]</tt> are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
|
||||
*/
|
||||
public long readInt32() throws IOException {
|
||||
int ib = m_is.read();
|
||||
|
||||
// in case of negative integers, extends the sign to all bits; otherwise zero...
|
||||
long ui = expectIntegerType(ib);
|
||||
// in case of negative integers does a ones complement
|
||||
return ui ^ readUIntExact(FOUR_BYTES, ib & 0x1f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed or unsigned 64-bit integer value in CBOR format.
|
||||
*
|
||||
* @read the small integer value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
|
||||
*/
|
||||
public long readInt64() throws IOException {
|
||||
int ib = m_is.read();
|
||||
|
||||
// in case of negative integers, extends the sign to all bits; otherwise zero...
|
||||
long ui = expectIntegerType(ib);
|
||||
// in case of negative integers does a ones complement
|
||||
return ui ^ readUIntExact(EIGHT_BYTES, ib & 0x1f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed or unsigned 8-bit integer value in CBOR format.
|
||||
*
|
||||
* @read the small integer value, values in the range <tt>[-256..255]</tt> are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
|
||||
*/
|
||||
public int readInt8() throws IOException {
|
||||
int ib = m_is.read();
|
||||
|
||||
// in case of negative integers, extends the sign to all bits; otherwise zero...
|
||||
long ui = expectIntegerType(ib);
|
||||
// in case of negative integers does a ones complement
|
||||
return (int) (ui ^ readUIntExact(ONE_BYTE, ib & 0x1f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prolog to reading a map of key-value pairs in CBOR format.
|
||||
*
|
||||
* @return the number of entries in the map, >= 0.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public long readMapLength() throws IOException {
|
||||
return readMajorTypeWithSize(TYPE_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a <code>null</code>-value in CBOR format.
|
||||
*
|
||||
* @return always <code>null</code>.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public Object readNull() throws IOException {
|
||||
readMajorTypeExact(TYPE_FLOAT_SIMPLE, NULL);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a single byte value in CBOR format.
|
||||
*
|
||||
* @return the read byte value.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public byte readSimpleValue() throws IOException {
|
||||
readMajorTypeExact(TYPE_FLOAT_SIMPLE, ONE_BYTE);
|
||||
return (byte) readUInt8();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed or unsigned small (<= 23) integer value in CBOR format.
|
||||
*
|
||||
* @read the small integer value, values in the range <tt>[-24..23]</tt> are supported.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
|
||||
*/
|
||||
public int readSmallInt() throws IOException {
|
||||
int ib = m_is.read();
|
||||
|
||||
// in case of negative integers, extends the sign to all bits; otherwise zero...
|
||||
long ui = expectIntegerType(ib);
|
||||
// in case of negative integers does a ones complement
|
||||
return (int) (ui ^ readUIntExact(-1, ib & 0x1f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a semantic tag value in CBOR format.
|
||||
*
|
||||
* @return the read tag value.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public long readTag() throws IOException {
|
||||
return readUInt(readMajorType(TYPE_TAG), false /* breakAllowed */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an UTF-8 encoded string value in CBOR format.
|
||||
*
|
||||
* @return the read UTF-8 encoded string, never <code>null</code>. In case the encoded string has a length of <tt>0</tt>, an empty string is returned.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public String readTextString() throws IOException {
|
||||
long len = readMajorTypeWithSize(TYPE_TEXT_STRING);
|
||||
if (len < 0) {
|
||||
fail("Infinite-length text strings not supported!");
|
||||
}
|
||||
if (len > Integer.MAX_VALUE) {
|
||||
fail("String length too long!");
|
||||
}
|
||||
return new String(readFully(new byte[(int) len]), "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Prolog to reading an UTF-8 encoded string value in CBOR format.
|
||||
*
|
||||
* @return the length of the string to read, or <tt>-1</tt> in case of infinite-length strings.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public long readTextStringLength() throws IOException {
|
||||
return readMajorTypeWithSize(TYPE_TEXT_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an undefined value in CBOR format.
|
||||
*
|
||||
* @return always <code>null</code>.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
public Object readUndefined() throws IOException {
|
||||
readMajorTypeExact(TYPE_FLOAT_SIMPLE, UNDEFINED);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.
|
||||
*
|
||||
* @param majorType the expected major type, cannot be <code>null</code> (unchecked).
|
||||
* @return either <tt>-1</tt> if the major type was an signed integer, or <tt>0</tt> otherwise.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
protected long expectIntegerType(int ib) throws IOException {
|
||||
int majorType = ((ib & 0xFF) >>> 5);
|
||||
if ((majorType != TYPE_UNSIGNED_INTEGER) && (majorType != TYPE_NEGATIVE_INTEGER)) {
|
||||
fail("Unexpected type: %s, expected type %s or %s!", getName(majorType), getName(TYPE_UNSIGNED_INTEGER),
|
||||
getName(TYPE_NEGATIVE_INTEGER));
|
||||
}
|
||||
return -majorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.
|
||||
*
|
||||
* @param majorType the expected major type, cannot be <code>null</code> (unchecked).
|
||||
* @return the read subtype, or payload, of the read major type.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
protected int readMajorType(int majorType) throws IOException {
|
||||
int ib = m_is.read();
|
||||
if (majorType != ((ib >>> 5) & 0x07)) {
|
||||
fail("Unexpected type: %s, expected: %s!", getName(ib), getName(majorType));
|
||||
}
|
||||
return ib & 0x1F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next major type from the underlying input stream, and verifies whether it matches the given expectations.
|
||||
*
|
||||
* @param majorType the expected major type, cannot be <code>null</code> (unchecked);
|
||||
* @param subtype the expected subtype.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
protected void readMajorTypeExact(int majorType, int subtype) throws IOException {
|
||||
int st = readMajorType(majorType);
|
||||
if ((st ^ subtype) != 0) {
|
||||
fail("Unexpected subtype: %d, expected: %d!", st, subtype);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next major type from the underlying input stream, verifies whether it matches the given expectation, and decodes the payload into a size.
|
||||
*
|
||||
* @param majorType the expected major type, cannot be <code>null</code> (unchecked).
|
||||
* @return the number of succeeding bytes, >= 0, or <tt>-1</tt> if an infinite-length type is read.
|
||||
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
|
||||
*/
|
||||
protected long readMajorTypeWithSize(int majorType) throws IOException {
|
||||
return readUInt(readMajorType(majorType), true /* breakAllowed */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned integer with a given length-indicator.
|
||||
*
|
||||
* @param length the length indicator to use;
|
||||
* @return the read unsigned integer, as long value.
|
||||
* @throws IOException in case of I/O problems reading the unsigned integer from the underlying input stream.
|
||||
*/
|
||||
protected long readUInt(int length, boolean breakAllowed) throws IOException {
|
||||
long result = -1;
|
||||
if (length < ONE_BYTE) {
|
||||
result = length;
|
||||
} else if (length == ONE_BYTE) {
|
||||
result = readUInt8();
|
||||
} else if (length == TWO_BYTES) {
|
||||
result = readUInt16();
|
||||
} else if (length == FOUR_BYTES) {
|
||||
result = readUInt32();
|
||||
} else if (length == EIGHT_BYTES) {
|
||||
result = readUInt64();
|
||||
} else if (breakAllowed && length == BREAK) {
|
||||
return -1;
|
||||
}
|
||||
if (result < 0) {
|
||||
fail("Not well-formed CBOR integer found, invalid length: %d!", result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned 16-bit integer value
|
||||
*
|
||||
* @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected int readUInt16() throws IOException {
|
||||
byte[] buf = readFully(new byte[2]);
|
||||
return (buf[0] & 0xFF) << 8 | (buf[1] & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned 32-bit integer value
|
||||
*
|
||||
* @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected long readUInt32() throws IOException {
|
||||
byte[] buf = readFully(new byte[4]);
|
||||
return ((buf[0] & 0xFF) << 24 | (buf[1] & 0xFF) << 16 | (buf[2] & 0xFF) << 8 | (buf[3] & 0xFF)) & 0xffffffffL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned 64-bit integer value
|
||||
*
|
||||
* @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected long readUInt64() throws IOException {
|
||||
byte[] buf = readFully(new byte[8]);
|
||||
return (buf[0] & 0xFFL) << 56 | (buf[1] & 0xFFL) << 48 | (buf[2] & 0xFFL) << 40 | (buf[3] & 0xFFL) << 32 | //
|
||||
(buf[4] & 0xFFL) << 24 | (buf[5] & 0xFFL) << 16 | (buf[6] & 0xFFL) << 8 | (buf[7] & 0xFFL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned 8-bit integer value
|
||||
*
|
||||
* @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected int readUInt8() throws IOException {
|
||||
return m_is.read() & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned integer with a given length-indicator.
|
||||
*
|
||||
* @param length the length indicator to use;
|
||||
* @return the read unsigned integer, as long value.
|
||||
* @throws IOException in case of I/O problems reading the unsigned integer from the underlying input stream.
|
||||
*/
|
||||
protected long readUIntExact(int expectedLength, int length) throws IOException {
|
||||
if (((expectedLength == -1) && (length >= ONE_BYTE)) || ((expectedLength >= 0) && (length != expectedLength))) {
|
||||
fail("Unexpected payload/length! Expected %s, but got %s.", lengthToString(expectedLength),
|
||||
lengthToString(length));
|
||||
}
|
||||
return readUInt(length, false /* breakAllowed */);
|
||||
}
|
||||
|
||||
private byte[] readFully(byte[] buf) throws IOException {
|
||||
int len = buf.length;
|
||||
int n = 0, off = 0;
|
||||
while (n < len) {
|
||||
int count = m_is.read(buf, off + n, len - n);
|
||||
if (count < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
n += count;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,488 @@
|
|||
/*
|
||||
* JACOB - CBOR implementation in Java.
|
||||
*
|
||||
* (C) Copyright - 2013 - J.W. Janssen <j.w.janssen@lxtreme.nl>
|
||||
*
|
||||
* Licensed under Apache License v2.0.
|
||||
*/
|
||||
package jacob;
|
||||
|
||||
import static jacob.CborConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Provides an encoder capable of encoding data into CBOR format to a given {@link OutputStream}.
|
||||
*/
|
||||
public class CborEncoder {
|
||||
private static final int NEG_INT_MASK = TYPE_NEGATIVE_INTEGER << 5;
|
||||
|
||||
private final OutputStream m_os;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CborEncoder} instance.
|
||||
*
|
||||
* @param os the actual output stream to write the CBOR-encoded data to, cannot be <code>null</code>.
|
||||
*/
|
||||
public CborEncoder(OutputStream os) {
|
||||
if (os == null) {
|
||||
throw new IllegalArgumentException("OutputStream cannot be null!");
|
||||
}
|
||||
m_os = os;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interprets a given float-value as a half-precision float value and
|
||||
* converts it to its raw integer form, as defined in IEEE 754.
|
||||
* <p>
|
||||
* Taken from: <a href="http://stackoverflow.com/a/6162687/229140">this Stack Overflow answer</a>.
|
||||
* </p>
|
||||
*
|
||||
* @param fval the value to convert.
|
||||
* @return the raw integer representation of the given float value.
|
||||
*/
|
||||
static int halfPrecisionToRawIntBits(float fval) {
|
||||
int fbits = Float.floatToIntBits(fval);
|
||||
int sign = (fbits >>> 16) & 0x8000;
|
||||
int val = (fbits & 0x7fffffff) + 0x1000;
|
||||
|
||||
// might be or become NaN/Inf
|
||||
if (val >= 0x47800000) {
|
||||
if ((fbits & 0x7fffffff) >= 0x47800000) { // is or must become NaN/Inf
|
||||
if (val < 0x7f800000) {
|
||||
// was value but too large, make it +/-Inf
|
||||
return sign | 0x7c00;
|
||||
}
|
||||
return sign | 0x7c00 | (fbits & 0x007fffff) >>> 13; // keep NaN (and Inf) bits
|
||||
}
|
||||
return sign | 0x7bff; // unrounded not quite Inf
|
||||
}
|
||||
if (val >= 0x38800000) {
|
||||
// remains normalized value
|
||||
return sign | val - 0x38000000 >>> 13; // exp - 127 + 15
|
||||
}
|
||||
if (val < 0x33000000) {
|
||||
// too small for subnormal
|
||||
return sign; // becomes +/-0
|
||||
}
|
||||
|
||||
val = (fbits & 0x7fffffff) >>> 23;
|
||||
// add subnormal bit, round depending on cut off and div by 2^(1-(exp-127+15)) and >> 13 | exp=0
|
||||
return sign | ((fbits & 0x7fffff | 0x800000) + (0x800000 >>> val - 102) >>> 126 - val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the start of an indefinite-length array.
|
||||
* <p>
|
||||
* After calling this method, one is expected to write the given number of array elements, which can be of any type. No length checks are performed.<br/>
|
||||
* After all array elements are written, one should write a single break value to end the array, see {@link #writeBreak()}.
|
||||
* </p>
|
||||
*
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeArrayStart() throws IOException {
|
||||
writeSimpleType(TYPE_ARRAY, BREAK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the start of a definite-length array.
|
||||
* <p>
|
||||
* After calling this method, one is expected to write the given number of array elements, which can be of any type. No length checks are performed.
|
||||
* </p>
|
||||
*
|
||||
* @param length the number of array elements to write, should >= 0.
|
||||
* @throws IllegalArgumentException in case the given length was negative;
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeArrayStart(int length) throws IOException {
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("Invalid array-length!");
|
||||
}
|
||||
writeType(TYPE_ARRAY, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a boolean value in canonical CBOR format.
|
||||
*
|
||||
* @param value the boolean to write.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeBoolean(boolean value) throws IOException {
|
||||
writeSimpleType(TYPE_FLOAT_SIMPLE, value ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a "break" stop-value in canonical CBOR format.
|
||||
*
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeBreak() throws IOException {
|
||||
writeSimpleType(TYPE_FLOAT_SIMPLE, BREAK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a byte string in canonical CBOR-format.
|
||||
*
|
||||
* @param value the byte string to write, can be <code>null</code> in which case a byte-string of length <tt>0</tt> is written.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeByteString(byte[] bytes) throws IOException {
|
||||
writeString(TYPE_BYTE_STRING, bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the start of an indefinite-length byte string.
|
||||
* <p>
|
||||
* After calling this method, one is expected to write the given number of string parts. No length checks are performed.<br/>
|
||||
* After all string parts are written, one should write a single break value to end the string, see {@link #writeBreak()}.
|
||||
* </p>
|
||||
*
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeByteStringStart() throws IOException {
|
||||
writeSimpleType(TYPE_BYTE_STRING, BREAK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a double-precision float value in canonical CBOR format.
|
||||
*
|
||||
* @param value the value to write, values from {@link Double#MIN_VALUE} to {@link Double#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeDouble(double value) throws IOException {
|
||||
writeUInt64(TYPE_FLOAT_SIMPLE << 5, Double.doubleToRawLongBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a single-precision float value in canonical CBOR format.
|
||||
*
|
||||
* @param value the value to write, values from {@link Float#MIN_VALUE} to {@link Float#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeFloat(float value) throws IOException {
|
||||
writeUInt32(TYPE_FLOAT_SIMPLE << 5, Float.floatToRawIntBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a half-precision float value in canonical CBOR format.
|
||||
*
|
||||
* @param value the value to write, values from {@link Float#MIN_VALUE} to {@link Float#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeHalfPrecisionFloat(float value) throws IOException {
|
||||
writeUInt16(TYPE_FLOAT_SIMPLE << 5, halfPrecisionToRawIntBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a signed or unsigned integer value in canonical CBOR format, that is, tries to encode it in a little bytes as possible..
|
||||
*
|
||||
* @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeInt(long value) throws IOException {
|
||||
// extends the sign over all bits...
|
||||
long sign = value >> 63;
|
||||
// in case value is negative, this bit should be set...
|
||||
int mt = (int) (sign & NEG_INT_MASK);
|
||||
// complement negative value...
|
||||
value = (sign ^ value);
|
||||
|
||||
writeUInt(mt, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a signed or unsigned 16-bit integer value in CBOR format.
|
||||
*
|
||||
* @param value the value to write, values from <tt>[-65536..65535]</tt> are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeInt16(int value) throws IOException {
|
||||
// extends the sign over all bits...
|
||||
int sign = value >> 31;
|
||||
// in case value is negative, this bit should be set...
|
||||
int mt = (int) (sign & NEG_INT_MASK);
|
||||
// complement negative value...
|
||||
writeUInt16(mt, (sign ^ value) & 0xffff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a signed or unsigned 32-bit integer value in CBOR format.
|
||||
*
|
||||
* @param value the value to write, values in the range <tt>[-4294967296..4294967295]</tt> are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeInt32(long value) throws IOException {
|
||||
// extends the sign over all bits...
|
||||
long sign = value >> 63;
|
||||
// in case value is negative, this bit should be set...
|
||||
int mt = (int) (sign & NEG_INT_MASK);
|
||||
// complement negative value...
|
||||
writeUInt32(mt, (int) ((sign ^ value) & 0xffffffffL));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a signed or unsigned 64-bit integer value in CBOR format.
|
||||
*
|
||||
* @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeInt64(long value) throws IOException {
|
||||
// extends the sign over all bits...
|
||||
long sign = value >> 63;
|
||||
// in case value is negative, this bit should be set...
|
||||
int mt = (int) (sign & NEG_INT_MASK);
|
||||
// complement negative value...
|
||||
writeUInt64(mt, sign ^ value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a signed or unsigned 8-bit integer value in CBOR format.
|
||||
*
|
||||
* @param value the value to write, values in the range <tt>[-256..255]</tt> are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeInt8(int value) throws IOException {
|
||||
// extends the sign over all bits...
|
||||
int sign = value >> 31;
|
||||
// in case value is negative, this bit should be set...
|
||||
int mt = (int) (sign & NEG_INT_MASK);
|
||||
// complement negative value...
|
||||
writeUInt8(mt, (sign ^ value) & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the start of an indefinite-length map.
|
||||
* <p>
|
||||
* After calling this method, one is expected to write any number of map entries, as separate key and value. Keys and values can both be of any type. No length checks are performed.<br/>
|
||||
* After all map entries are written, one should write a single break value to end the map, see {@link #writeBreak()}.
|
||||
* </p>
|
||||
*
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeMapStart() throws IOException {
|
||||
writeSimpleType(TYPE_MAP, BREAK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the start of a finite-length map.
|
||||
* <p>
|
||||
* After calling this method, one is expected to write any number of map entries, as separate key and value. Keys and values can both be of any type. No length checks are performed.
|
||||
* </p>
|
||||
*
|
||||
* @param length the number of map entries to write, should >= 0.
|
||||
* @throws IllegalArgumentException in case the given length was negative;
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeMapStart(int length) throws IOException {
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("Invalid length of map!");
|
||||
}
|
||||
writeType(TYPE_MAP, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a <code>null</code> value in canonical CBOR format.
|
||||
*
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeNull() throws IOException {
|
||||
writeSimpleType(TYPE_FLOAT_SIMPLE, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a simple value, i.e., an "atom" or "constant" value in canonical CBOR format.
|
||||
*
|
||||
* @param value the (unsigned byte) value to write, values from <tt>32</tt> to <tt>255</tt> are supported (though not enforced).
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeSimpleValue(byte simpleValue) throws IOException {
|
||||
// convert to unsigned value...
|
||||
int value = (simpleValue & 0xff);
|
||||
writeType(TYPE_FLOAT_SIMPLE, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a signed or unsigned small (<= 23) integer value in CBOR format.
|
||||
*
|
||||
* @param value the value to write, values in the range <tt>[-24..23]</tt> are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeSmallInt(int value) throws IOException {
|
||||
// extends the sign over all bits...
|
||||
int sign = value >> 31;
|
||||
// in case value is negative, this bit should be set...
|
||||
int mt = (int) (sign & NEG_INT_MASK);
|
||||
// complement negative value...
|
||||
value = Math.min(0x17, (sign ^ value));
|
||||
|
||||
m_os.write((int) (mt | value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a semantic tag in canonical CBOR format.
|
||||
*
|
||||
* @param tag the tag to write, should >= 0.
|
||||
* @throws IllegalArgumentException in case the given tag was negative;
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeTag(long tag) throws IOException {
|
||||
if (tag < 0) {
|
||||
throw new IllegalArgumentException("Invalid tag specification, cannot be negative!");
|
||||
}
|
||||
writeType(TYPE_TAG, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an UTF-8 string in canonical CBOR-format.
|
||||
* <p>
|
||||
* Note that this method is <em>platform</em> specific, as the given string value will be encoded in a byte array
|
||||
* using the <em>platform</em> encoding! This means that the encoding must be standardized and known.
|
||||
* </p>
|
||||
*
|
||||
* @param value the UTF-8 string to write, can be <code>null</code> in which case an UTF-8 string of length <tt>0</tt> is written.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeTextString(String value) throws IOException {
|
||||
writeString(TYPE_TEXT_STRING, value == null ? null : value.getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the start of an indefinite-length UTF-8 string.
|
||||
* <p>
|
||||
* After calling this method, one is expected to write the given number of string parts. No length checks are performed.<br/>
|
||||
* After all string parts are written, one should write a single break value to end the string, see {@link #writeBreak()}.
|
||||
* </p>
|
||||
*
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeTextStringStart() throws IOException {
|
||||
writeSimpleType(TYPE_TEXT_STRING, BREAK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an "undefined" value in canonical CBOR format.
|
||||
*
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
public void writeUndefined() throws IOException {
|
||||
writeSimpleType(TYPE_FLOAT_SIMPLE, UNDEFINED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and writes the major type and value as a simple type.
|
||||
*
|
||||
* @param majorType the major type of the value to write, denotes what semantics the written value has;
|
||||
* @param value the value to write, values from [0..31] are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected void writeSimpleType(int majorType, int value) throws IOException {
|
||||
m_os.write((majorType << 5) | (value & 0x1f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a byte string in canonical CBOR-format.
|
||||
*
|
||||
* @param majorType the major type of the string, should be either 0x40 or 0x60;
|
||||
* @param value the byte string to write, can be <code>null</code> in which case a byte-string of length <tt>0</tt> is written.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected void writeString(int majorType, byte[] bytes) throws IOException {
|
||||
int len = (bytes == null) ? 0 : bytes.length;
|
||||
writeType(majorType, len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
m_os.write(bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and writes the major type indicator with a given payload (length).
|
||||
*
|
||||
* @param majorType the major type of the value to write, denotes what semantics the written value has;
|
||||
* @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected void writeType(int majorType, long value) throws IOException {
|
||||
writeUInt((majorType << 5), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and writes an unsigned integer value, that is, tries to encode it in a little bytes as possible.
|
||||
*
|
||||
* @param mt the major type of the value to write, denotes what semantics the written value has;
|
||||
* @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected void writeUInt(int mt, long value) throws IOException {
|
||||
if (value < 0x18L) {
|
||||
m_os.write((int) (mt | value));
|
||||
} else if (value < 0x100L) {
|
||||
writeUInt8(mt, (int) value);
|
||||
} else if (value < 0x10000L) {
|
||||
writeUInt16(mt, (int) value);
|
||||
} else if (value < 0x100000000L) {
|
||||
writeUInt32(mt, (int) value);
|
||||
} else {
|
||||
writeUInt64(mt, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and writes an unsigned 16-bit integer value
|
||||
*
|
||||
* @param mt the major type of the value to write, denotes what semantics the written value has;
|
||||
* @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected void writeUInt16(int mt, int value) throws IOException {
|
||||
m_os.write(mt | TWO_BYTES);
|
||||
m_os.write(value >> 8);
|
||||
m_os.write(value & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and writes an unsigned 32-bit integer value
|
||||
*
|
||||
* @param mt the major type of the value to write, denotes what semantics the written value has;
|
||||
* @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected void writeUInt32(int mt, int value) throws IOException {
|
||||
m_os.write(mt | FOUR_BYTES);
|
||||
m_os.write(value >> 24);
|
||||
m_os.write(value >> 16);
|
||||
m_os.write(value >> 8);
|
||||
m_os.write(value & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and writes an unsigned 64-bit integer value
|
||||
*
|
||||
* @param mt the major type of the value to write, denotes what semantics the written value has;
|
||||
* @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected void writeUInt64(int mt, long value) throws IOException {
|
||||
m_os.write(mt | EIGHT_BYTES);
|
||||
m_os.write((int) (value >> 56));
|
||||
m_os.write((int) (value >> 48));
|
||||
m_os.write((int) (value >> 40));
|
||||
m_os.write((int) (value >> 32));
|
||||
m_os.write((int) (value >> 24));
|
||||
m_os.write((int) (value >> 16));
|
||||
m_os.write((int) (value >> 8));
|
||||
m_os.write((int) (value & 0xFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and writes an unsigned 8-bit integer value
|
||||
*
|
||||
* @param mt the major type of the value to write, denotes what semantics the written value has;
|
||||
* @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
|
||||
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
|
||||
*/
|
||||
protected void writeUInt8(int mt, int value) throws IOException {
|
||||
m_os.write(mt | ONE_BYTE);
|
||||
m_os.write(value & 0xFF);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* JACOB - CBOR implementation in Java.
|
||||
*
|
||||
* (C) Copyright - 2013 - J.W. Janssen <j.w.janssen@lxtreme.nl>
|
||||
*
|
||||
* Licensed under Apache License v2.0.
|
||||
*/
|
||||
package jacob;
|
||||
|
||||
import static jacob.CborConstants.*;
|
||||
|
||||
/**
|
||||
* Represents the various major types in CBOR, along with their .
|
||||
* <p>
|
||||
* The major type is encoded in the upper three bits of each initial byte. The lower 5 bytes represent any additional information.
|
||||
* </p>
|
||||
*/
|
||||
public class CborType {
|
||||
private final int m_major;
|
||||
private final int m_additional;
|
||||
|
||||
private CborType(int major, int additional) {
|
||||
m_major = major;
|
||||
m_additional = additional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a descriptive string for the given major type.
|
||||
*
|
||||
* @param mt the major type to return as string, values from [0..7] are supported.
|
||||
* @return the name of the given major type, as String, never <code>null</code>.
|
||||
* @throws IllegalArgumentException in case the given major type is not supported.
|
||||
*/
|
||||
public static String getName(int mt) {
|
||||
switch (mt) {
|
||||
case TYPE_ARRAY:
|
||||
return "array";
|
||||
case TYPE_BYTE_STRING:
|
||||
return "byte string";
|
||||
case TYPE_FLOAT_SIMPLE:
|
||||
return "float/simple value";
|
||||
case TYPE_MAP:
|
||||
return "map";
|
||||
case TYPE_NEGATIVE_INTEGER:
|
||||
return "negative integer";
|
||||
case TYPE_TAG:
|
||||
return "tag";
|
||||
case TYPE_TEXT_STRING:
|
||||
return "text string";
|
||||
case TYPE_UNSIGNED_INTEGER:
|
||||
return "unsigned integer";
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid major type: " + mt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a given byte value to a {@link CborType} value.
|
||||
*
|
||||
* @param i the input byte (8-bit) to decode into a {@link CborType} instance.
|
||||
* @return a {@link CborType} instance, never <code>null</code>.
|
||||
*/
|
||||
public static CborType valueOf(int i) {
|
||||
return new CborType((i & 0xff) >>> 5, i & 0x1f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CborType other = (CborType) obj;
|
||||
return (m_major == other.m_major) && (m_additional == other.m_additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the additional information of this type, as integer value from [0..31].
|
||||
*/
|
||||
public int getAdditionalInfo() {
|
||||
return m_additional;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the major type, as integer value from [0..7].
|
||||
*/
|
||||
public int getMajorType() {
|
||||
return m_major;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + m_additional;
|
||||
result = prime * result + m_major;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if this type allows for an infinite-length payload,
|
||||
* <code>false</code> if only definite-length payloads are allowed.
|
||||
*/
|
||||
public boolean isBreakAllowed() {
|
||||
return m_major == TYPE_ARRAY || m_major == TYPE_BYTE_STRING || m_major == TYPE_MAP
|
||||
|| m_major == TYPE_TEXT_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the major type of a given {@link CborType} equals the major type of this {@link CborType}.
|
||||
*
|
||||
* @param other the {@link CborType} to compare against, cannot be <code>null</code>.
|
||||
* @return <code>true</code> if the given {@link CborType} is of the same major type as this {@link CborType}, <code>false</code> otherwise.
|
||||
* @throws IllegalArgumentException in case the given argument was <code>null</code>.
|
||||
*/
|
||||
public boolean isEqualType(CborType other) {
|
||||
if (other == null) {
|
||||
throw new IllegalArgumentException("Parameter cannot be null!");
|
||||
}
|
||||
return m_major == other.m_major;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the major type of a given byte value (representing an encoded {@link CborType}) equals the major type of this {@link CborType}.
|
||||
*
|
||||
* @param encoded the encoded CBOR type to compare.
|
||||
* @return <code>true</code> if the given byte value represents the same major type as this {@link CborType}, <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean isEqualType(int encoded) {
|
||||
return m_major == ((encoded & 0xff) >>> 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getName(m_major)).append('(').append(m_additional).append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
version 1.0
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
|
|
@ -183,7 +183,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
|
|||
}
|
||||
}
|
||||
rowCount=rowEndTime.size()>0?rowEndTime.size():1;
|
||||
getChildNodes().parallelStream().forEach(c -> ((TxGenerator)c).calculateConcurrency());
|
||||
//getChildNodes().parallelStream().forEach(c -> ((TxGenerator)c).calculateConcurrency());
|
||||
getChildNodes().stream().forEach(c -> ((TxGenerator)c).calculateConcurrency());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
|
|
|
@ -585,6 +585,7 @@ public class WaveformView implements IWaveformView {
|
|||
if (trackVerticalOffset.isEmpty()) {
|
||||
waveformCanvas.setOrigin(0, 0);
|
||||
}
|
||||
tl.dispose();
|
||||
}
|
||||
|
||||
private int calculateValueWidth() {
|
||||
|
@ -595,6 +596,7 @@ public class WaveformView implements IWaveformView {
|
|||
tl.setText(v.currentValue);
|
||||
valueMaxWidth = Math.max(valueMaxWidth, tl.getBounds().width);
|
||||
}
|
||||
tl.dispose();
|
||||
return valueMaxWidth + 15;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
|
|
@ -7,6 +7,8 @@ Bundle-Vendor: MINRES Technologies GmbH
|
|||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Export-Package: com.minres.scviewer.database,
|
||||
com.minres.scviewer.database.tx
|
||||
Import-Package: org.slf4j
|
||||
Require-Bundle: javax.inject;bundle-version="1.0.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Service-Component: OSGI-INF/component.xml,OSGI-INF/component2.xml
|
||||
Automatic-Module-Name: com.minres.scviewer.database
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
|
|
@ -51,6 +51,9 @@ public enum DataType {
|
|||
// T*
|
||||
ARRAY,
|
||||
/** The string. */
|
||||
// T[N]
|
||||
STRING // string, std::string
|
||||
// string, std::string
|
||||
STRING,
|
||||
/** The time. */
|
||||
// sc_time
|
||||
TIME
|
||||
}
|
||||
|
|
|
@ -20,6 +20,11 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
|
@ -47,7 +52,9 @@ public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeL
|
|||
|
||||
/** The max time. */
|
||||
private long maxTime = -1;
|
||||
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WaveformDb.class);
|
||||
|
||||
/**
|
||||
* Bind.
|
||||
*
|
||||
|
@ -132,6 +139,7 @@ public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeL
|
|||
try {
|
||||
loader.load(this, inp);
|
||||
} catch (Exception e) {
|
||||
LOG.error("error loading file "+inp.getName(), e);
|
||||
retval=false;
|
||||
}
|
||||
loader.removePropertyChangeListener(this);
|
||||
|
|
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: SCViewer Help
|
||||
Bundle-SymbolicName: com.minres.scviewer.e4.application.help;singleton:=true
|
||||
Bundle-Version: 2.16.1
|
||||
Bundle-Version: 2.17.0
|
||||
Bundle-Vendor: MINRES Technologies GmbH
|
||||
Automatic-Module-Name: com.minres.scviewer.e4.application.help
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
<children xsi:type="menu:HandledMenuItem" xmi:id="_JTXBgYl_EeWxJ_wPkM6yGQ" elementId="" label="Preferences" command="_AxH6sIl_EeWxJ_wPkM6yGQ"/>
|
||||
</children>
|
||||
<children xsi:type="menu:Menu" xmi:id="_95QGxHNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.menu.help" label="Help">
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_UQRi0B07EeuiP60JNw0iiA" elementId="com.minres.scviewer.e4.application.handledmenuitem.checkforupdate" visible="false" label="Check for Update" enabled="false" command="_-9ED4B06EeuiP60JNw0iiA"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_UQRi0B07EeuiP60JNw0iiA" elementId="com.minres.scviewer.e4.application.handledmenuitem.checkforupdate" label="Check for Update" enabled="false" command="_-9ED4B06EeuiP60JNw0iiA"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_qJS-MHCOEeyub8CfGE1sGA" label="Help Content" command="_RdUMoHCOEeyub8CfGE1sGA"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_95QGxXNmEeWBq8z1Dv39LA" label="Web Help" command="_lqjIYEYEEeyPM8G0E2EYww"/>
|
||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_4xtmgEYEEeyPM8G0E2EYww" label="About" command="_95PfxnNmEeWBq8z1Dv39LA"/>
|
||||
|
|
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %Bundle-Name
|
||||
Bundle-SymbolicName: com.minres.scviewer.e4.application;singleton:=true
|
||||
Bundle-Version: 2.16.1
|
||||
Bundle-Version: 2.17.0
|
||||
Bundle-Vendor: %Bundle-Vendor
|
||||
Require-Bundle: javax.inject;bundle-version="1.0.0",
|
||||
org.eclipse.core.runtime;bundle-version="3.11.1",
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
|
|
@ -95,6 +95,17 @@ public class Messages extends NLS {
|
|||
public static String marker_text;
|
||||
public static String rel_arrow;
|
||||
public static String rel_arrow_highlite;
|
||||
public static String UpdateHandler_URI;
|
||||
public static String UpdateHandler_10;
|
||||
public static String UpdateHandler_11;
|
||||
public static String UpdateHandler_2;
|
||||
public static String UpdateHandler_3;
|
||||
public static String UpdateHandler_4;
|
||||
public static String UpdateHandler_5;
|
||||
public static String UpdateHandler_6;
|
||||
public static String UpdateHandler_7;
|
||||
public static String UpdateHandler_8;
|
||||
public static String UpdateHandler_9;
|
||||
|
||||
static {
|
||||
// initialize resource bundle
|
||||
|
|
|
@ -32,7 +32,7 @@ public class NavigateEvent {
|
|||
@CanExecute
|
||||
public Boolean canExecute(EPartService partService){
|
||||
MPart part = partService.getActivePart();
|
||||
if(part.getObject() instanceof WaveformViewer){
|
||||
if(part!=null && part.getObject() instanceof WaveformViewer){
|
||||
Object sel = ((WaveformViewer)part.getObject()).getSelection();
|
||||
if( sel instanceof IStructuredSelection) {
|
||||
if(((IStructuredSelection)sel).isEmpty()) return false;
|
||||
|
|
|
@ -1,24 +1,120 @@
|
|||
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
|
||||
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.di.UISynchronize;
|
||||
import org.eclipse.e4.ui.workbench.IWorkbench;
|
||||
import org.eclipse.equinox.p2.core.IProvisioningAgent;
|
||||
import org.eclipse.equinox.p2.operations.ProvisioningJob;
|
||||
import org.eclipse.equinox.p2.operations.ProvisioningSession;
|
||||
import org.eclipse.equinox.p2.operations.UpdateOperation;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
|
||||
import com.minres.scviewer.e4.application.Messages;
|
||||
|
||||
public class UpdateHandler {
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
@Execute
|
||||
public void execute(IProvisioningAgent agent, UISynchronize synchronize, IWorkbench workbench) {
|
||||
ProvisioningSession session = new ProvisioningSession(agent);
|
||||
UpdateOperation operation = new UpdateOperation(session);
|
||||
IStatus status = operation.resolveModal(null);
|
||||
if(status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
|
||||
MessageDialog.openInformation(null, "Information", "Nothing to update");
|
||||
public void execute(IProvisioningAgent agent, UISynchronize sync, IWorkbench workbench) {
|
||||
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
||||
@Override
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
update(agent, monitor, sync, workbench);
|
||||
}
|
||||
};
|
||||
try {
|
||||
new ProgressMonitorDialog(null).run(true, true, runnable);
|
||||
} catch (InvocationTargetException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private IStatus update(IProvisioningAgent agent, IProgressMonitor monitor, UISynchronize sync,
|
||||
IWorkbench workbench) {
|
||||
ProvisioningSession session = new ProvisioningSession(agent);
|
||||
UpdateOperation operation = new UpdateOperation(session);
|
||||
try {
|
||||
operation.getProvisioningContext().setArtifactRepositories(new URI(Messages.UpdateHandler_URI));
|
||||
operation.getProvisioningContext().setMetadataRepositories(new URI(Messages.UpdateHandler_URI));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
SubMonitor sub = SubMonitor.convert(monitor, Messages.UpdateHandler_2, 200);
|
||||
IStatus status = operation.resolveModal(sub.newChild(100));
|
||||
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
|
||||
sync.syncExec(() -> {
|
||||
MessageDialog.openInformation(null, Messages.UpdateHandler_10, Messages.UpdateHandler_3);
|
||||
});
|
||||
return Status.CANCEL_STATUS;
|
||||
} else {
|
||||
ProvisioningJob provisioningJob = operation.getProvisioningJob(sub.newChild(100));
|
||||
if (provisioningJob != null) {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean performUpdate = MessageDialog.openQuestion(null, Messages.UpdateHandler_4,
|
||||
Messages.UpdateHandler_5);
|
||||
if (performUpdate) {
|
||||
provisioningJob.addJobChangeListener(new JobChangeAdapter() {
|
||||
@Override
|
||||
public void done(IJobChangeEvent event) {
|
||||
if (event.getResult().isOK()) {
|
||||
sync.syncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
boolean restart = MessageDialog.openQuestion(null,
|
||||
Messages.UpdateHandler_6, Messages.UpdateHandler_7);
|
||||
if (restart) {
|
||||
workbench.restart();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sync.syncExec(() -> {
|
||||
MessageDialog.openInformation(null, Messages.UpdateHandler_11,
|
||||
event.getResult().getMessage());
|
||||
});
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
provisioningJob.schedule();
|
||||
} else {
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (operation.hasResolved()) {
|
||||
sync.syncExec(() -> {
|
||||
MessageDialog.openInformation(null, Messages.UpdateHandler_11,
|
||||
Messages.UpdateHandler_8 + operation.getResolutionResult());
|
||||
});
|
||||
} else {
|
||||
sync.syncExec(() -> {
|
||||
MessageDialog.openInformation(null, Messages.UpdateHandler_11, Messages.UpdateHandler_9);
|
||||
});
|
||||
}
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
if (cancelled) {
|
||||
cancelled = false;
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ DesignBrowser_8=Insert before
|
|||
LoadingWaveformDb_0=Database loading...
|
||||
LoadStoreSettingsHandler_2=*.scview
|
||||
LoadStoreSettingsHandler_3=SCViewer.scview
|
||||
OpenHandler_0=*.vcd;*.vcd.gz;*.txlog;*.txlog.gz;*.txdb;*.fbrdb
|
||||
OpenHandler_0=*.vcd;*.vcd.gz;*.txlog;*.txlog.gz;*.txdb;*.fbrdb;*.ftr
|
||||
QuitHandler_0=Confirmation
|
||||
QuitHandler_1=Do you want to exit?
|
||||
RelationTypeToolControl_0=------------
|
||||
|
@ -89,4 +89,14 @@ marker=Marker
|
|||
marker_text=Marker TExt
|
||||
rel_arrow=Relation arrow
|
||||
rel_arrow_highlite=highlighted Relation arrorw
|
||||
|
||||
UpdateHandler_URI=http://https://minres.github.io/SCViewer/repository
|
||||
UpdateHandler_10=Information
|
||||
UpdateHandler_11=Error
|
||||
UpdateHandler_2=Checking for application updates...
|
||||
UpdateHandler_3=Nothing to update
|
||||
UpdateHandler_4=Updates available
|
||||
UpdateHandler_5=There are updates available. Do you want to install them now?
|
||||
UpdateHandler_6=Updates installed, restart?
|
||||
UpdateHandler_7=Updates have been installed successfully, do you want to restart?
|
||||
UpdateHandler_8=Couldn't get provisioning job:
|
||||
UpdateHandler_9=Couldn't resolve provisioning job
|
||||
|
|
|
@ -316,30 +316,25 @@
|
|||
id="com.minres.scviewer.ui.oneWaveSeleted">
|
||||
<with
|
||||
variable="selection">
|
||||
<and>
|
||||
<count
|
||||
value="1">
|
||||
</count>
|
||||
<iterate
|
||||
operator="or">
|
||||
<instanceof value="com.minres.scviewer.database.IWaveform"/>
|
||||
</iterate>
|
||||
</and>
|
||||
<iterate
|
||||
ifEmpty="false"
|
||||
operator="or">
|
||||
<instanceof
|
||||
value="com.minres.scviewer.database.ui.TrackEntry">
|
||||
</instanceof>
|
||||
</iterate>
|
||||
</with>
|
||||
</definition>
|
||||
<definition
|
||||
id="com.minres.scviewer.ui.oneTxSeleted">
|
||||
<with
|
||||
variable="selection">
|
||||
<and>
|
||||
<count
|
||||
value="1">
|
||||
</count>
|
||||
<iterate
|
||||
operator="or">
|
||||
<instanceof value="com.minres.scviewer.database.tx.ITx"/>
|
||||
</iterate>
|
||||
</and>
|
||||
<iterate
|
||||
operator="or">
|
||||
<instanceof
|
||||
value="com.minres.scviewer.database.tx.ITx">
|
||||
</instanceof>
|
||||
</iterate>
|
||||
</with>
|
||||
</definition>
|
||||
<definition
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
|
|
@ -333,6 +333,10 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
|
|||
addStreamToList(stream);
|
||||
}
|
||||
|
||||
public void removeStreamFromList(TrackEntry entry){
|
||||
waveformView.getStreamList().remove(entry);
|
||||
}
|
||||
|
||||
public void removeStreamFromList(IWaveform waveform){
|
||||
if(getEditorInput() instanceof TxEditorInput && ((TxEditorInput) getEditorInput()).getStreamNames().contains(waveform.getFullName())){
|
||||
((TxEditorInput) getEditorInput()).getStreamNames().remove(waveform.getFullName());
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.eclipse.jface.viewers.StructuredSelection;
|
|||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.ui.TrackEntry;
|
||||
import com.minres.scviewer.ui.TxEditorPart;
|
||||
|
||||
public class RemoveHandler extends AbstractHandler {
|
||||
|
@ -29,8 +29,12 @@ public class RemoveHandler extends AbstractHandler {
|
|||
if(editor instanceof TxEditorPart){
|
||||
TxEditorPart editorPart = (TxEditorPart) editor;
|
||||
ISelection selection =editorPart.getSelection();
|
||||
if(selection instanceof StructuredSelection && ((StructuredSelection)selection).getFirstElement() instanceof IWaveform){
|
||||
editorPart.removeStreamFromList((IWaveform) ((StructuredSelection)selection).getFirstElement());
|
||||
if(selection instanceof StructuredSelection) {
|
||||
for(Object elem:((StructuredSelection) selection).toList()) {
|
||||
if(elem instanceof TrackEntry){
|
||||
editorPart.removeStreamFromList((TrackEntry) elem);
|
||||
}
|
||||
}
|
||||
editorPart.setSelection(new StructuredSelection());
|
||||
}
|
||||
}
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -4,13 +4,14 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>releng/com.minres.scviewer.target</module>
|
||||
<module>doc/com.minres.scviewer.doc</module>
|
||||
<module>plugins/com.minres.scviewer.database</module>
|
||||
<module>plugins/com.minres.scviewer.database.sqlite</module>
|
||||
<module>plugins/com.minres.scviewer.database.ftr</module>
|
||||
<module>plugins/com.minres.scviewer.database.text</module>
|
||||
<module>plugins/com.minres.scviewer.database.vcd</module>
|
||||
<module>tests/com.minres.scviewer.database.test</module>
|
||||
|
@ -69,7 +70,7 @@
|
|||
<artifact>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.target</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
</artifact>
|
||||
</target>
|
||||
<executionEnvironment>org.eclipse.justj.openjdk.hotspot.jre.minimal-15</executionEnvironment>
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>com.minres.scviewer.e4.product</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<packaging>eclipse-repository</packaging>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<build>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?pde version="3.5"?>
|
||||
|
||||
<product name="SCViewer" uid="scviewer" id="com.minres.scviewer.e4.application.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.16.1" useFeatures="true" includeLaunchers="true">
|
||||
<product name="SCViewer" uid="scviewer" id="com.minres.scviewer.e4.application.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.17.0" useFeatures="true" includeLaunchers="true" autoIncludeRequirements="true">
|
||||
|
||||
<configIni use="default">
|
||||
</configIni>
|
||||
|
@ -63,11 +63,12 @@
|
|||
<feature id="org.eclipse.e4.rcp" installMode="root"/>
|
||||
<feature id="com.opcoach.e4.preferences.feature" installMode="root"/>
|
||||
<feature id="com.minres.scviewer.e4.help.feature" installMode="root"/>
|
||||
<feature id="org.eclipse.justj.openjdk.hotspot.jre.minimal.stripped" installMode="root"/>
|
||||
<feature id="org.eclipse.justj.openjdk.hotspot.jre.minimal.stripped" installMode="root"/>
|
||||
</features>
|
||||
|
||||
<configurations>
|
||||
<plugin id="com.minres.scviewer.database.text" autoStart="true" startLevel="2" />
|
||||
<plugin id="com.minres.scviewer.database.ftr" autoStart="true" startLevel="2" />
|
||||
<plugin id="com.minres.scviewer.database.vcd" autoStart="true" startLevel="2" />
|
||||
<plugin id="org.apache.felix.scr" autoStart="true" startLevel="1" />
|
||||
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" />
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
<unit id="org.eclipse.rcptt.core.feature.group" version="0.0.0"/><!-- com.google.guave-->
|
||||
<unit id="org.eclipse.pde.feature.group" version="0.0.0"/> <!-- org.junit for testing -->
|
||||
<unit id="javax.servlet" version="0.0.0"/>
|
||||
<unit id="org.eclipse.equinox.core.feature.feature.group" version="0.0.0"/>
|
||||
<unit id="org.eclipse.equinox.p2.core.feature.feature.group" version="0.0.0"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<repository location="https://www.opcoach.com/repository/2021-12/"/>
|
||||
|
@ -26,7 +28,7 @@
|
|||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<repository location="http://download.eclipse.org/nebula/releases/latest"/>
|
||||
<unit id="org.eclipse.nebula.widgets.xviewer.feature.feature.group" version="1.1.0.202011020719"/>
|
||||
<unit id="org.eclipse.nebula.widgets.xviewer.feature.feature.group" version="1.1.0.202208171809"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<repository location="http://download.eclipse.org/collections/10.4.0/repository"/>
|
||||
|
@ -39,8 +41,12 @@
|
|||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<repository location="https://download.eclipse.org/tools/orbit/downloads/2021-12"/>
|
||||
<unit id="org.apache.commons.compress" version="0.0.0"/>
|
||||
<unit id="org.apache.commons.compress.source" version="0.0.0"/>
|
||||
<unit id="org.apache.commons.compress" version="1.21.0.v20211103-2100"/>
|
||||
<unit id="org.apache.commons.compress.source" version="1.21.0.v20211103-2100"/>
|
||||
<unit id="ch.qos.logback.slf4j" version="1.0.7.v201505121915"/>
|
||||
<unit id="ch.qos.logback.slf4j.source" version="1.0.7.v201505121915"/>
|
||||
<unit id="org.slf4j.api" version="1.7.2.v20121108-1250"/>
|
||||
<unit id="org.slf4j.api.source" version="1.7.2.v20121108-1250"/>
|
||||
</location>
|
||||
</locations>
|
||||
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15"/>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -18,6 +18,15 @@
|
|||
<feature id="com.minres.scviewer.database.feature.source" version="0.0.0">
|
||||
<category name="devel_components.source"/>
|
||||
</feature>
|
||||
<feature id="com.minres.scviewer.e4.feature">
|
||||
<category name="ide_components_standalone"/>
|
||||
</feature>
|
||||
<feature id="com.minres.scviewer.e4.help.feature">
|
||||
<category name="ide_components_standalone"/>
|
||||
</feature>
|
||||
<feature id="com.minres.scviewer.e4.platform.feature">
|
||||
<category name="ide_components_standalone"/>
|
||||
</feature>
|
||||
<category-def name="ide_components" label="SCViewer">
|
||||
<description>
|
||||
Viewer for transaction recording outputs of the SystemC Verification (SCV) library
|
||||
|
@ -29,4 +38,7 @@
|
|||
</description>
|
||||
</category-def>
|
||||
<category-def name="devel_components.source" label="Developer Resources (Source)"/>
|
||||
<category-def name="ide_components_standalone" label="Standalone">
|
||||
<category name="ide_components"/>
|
||||
</category-def>
|
||||
</site>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<build>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
</setAttribute>
|
||||
<booleanAttribute key="includeOptional" value="true"/>
|
||||
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
|
||||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/com.minres.scviewer.database.test/src/com/minres/scviewer/database/test/DatabaseServicesTest.java"/>
|
||||
</listAttribute>
|
||||
|
@ -28,6 +29,8 @@
|
|||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.minres.scviewer.database.test.DatabaseServicesTest"/>
|
||||
|
|
Binary file not shown.
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<version>2.17.0</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-test-plugin</packaging>
|
||||
|
|
|
@ -15,15 +15,23 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.minres.scviewer.database.EventEntry;
|
||||
import com.minres.scviewer.database.IEvent;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
|
||||
public class DatabaseServicesTest {
|
||||
|
||||
|
@ -50,7 +58,7 @@ public class DatabaseServicesTest {
|
|||
assertEquals(2, waveformDb.getChildNodes().size());
|
||||
IWaveform bus_data_wave = waves.get(0);
|
||||
EventEntry bus_data_entry = bus_data_wave.getEvents().floorEntry(1400000000L);
|
||||
assertEquals("01111000", bus_data_entry.events[0].toString());
|
||||
assertEquals("00001011", bus_data_entry.events[0].toString());
|
||||
IWaveform rw_wave = waves.get(2);
|
||||
EventEntry rw_entry = rw_wave.getEvents().floorEntry(2360000000L);
|
||||
assertEquals("1", rw_entry.events[0].toString());
|
||||
|
@ -62,8 +70,8 @@ public class DatabaseServicesTest {
|
|||
assertTrue(f.exists());
|
||||
waveformDb.load(f);
|
||||
assertNotNull(waveformDb);
|
||||
assertEquals(3, waveformDb.getAllWaves().size());
|
||||
assertEquals(1, waveformDb.getChildNodes().size());
|
||||
assertEquals(0, waveformDb.getAllWaves().size());
|
||||
assertEquals(0, waveformDb.getChildNodes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,7 +81,7 @@ public class DatabaseServicesTest {
|
|||
waveformDb.load(f);
|
||||
assertNotNull(waveformDb);
|
||||
List<IWaveform> waveforms = waveformDb.getAllWaves();
|
||||
assertEquals(3, waveforms.size());
|
||||
assertEquals(8, waveforms.size());
|
||||
assertEquals(1, waveformDb.getChildNodes().size());
|
||||
for(IWaveform w:waveforms) {
|
||||
if(w.getId()==1) {
|
||||
|
@ -92,7 +100,7 @@ public class DatabaseServicesTest {
|
|||
assertTrue(f.exists());
|
||||
waveformDb.load(f);
|
||||
assertNotNull(waveformDb);
|
||||
assertEquals(3, waveformDb.getAllWaves().size());
|
||||
assertEquals(8, waveformDb.getAllWaves().size());
|
||||
assertEquals(1, waveformDb.getChildNodes().size());
|
||||
}
|
||||
|
||||
|
@ -106,4 +114,38 @@ public class DatabaseServicesTest {
|
|||
assertEquals(1, waveformDb.getChildNodes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFtr() throws Exception {
|
||||
File f = new File("inputs/my_db.ftr").getAbsoluteFile();
|
||||
assertTrue(f.exists());
|
||||
waveformDb.load(f);
|
||||
assertNotNull(waveformDb);
|
||||
List<IWaveform> waveforms = waveformDb.getAllWaves();
|
||||
assertEquals(8, waveforms.size());
|
||||
assertEquals(1, waveformDb.getChildNodes().size());
|
||||
for(IWaveform w:waveforms) {
|
||||
if(w.getId()==1) {
|
||||
assertEquals(2, w.getRowCount());
|
||||
} else if(w.getId()==2l) {
|
||||
assertEquals(1, w.getRowCount());
|
||||
} else if(w.getId()==3l) {
|
||||
assertEquals(1, w.getRowCount());
|
||||
}
|
||||
}
|
||||
//waveforms.stream().filter(s -> s.getId()==1).collect(Collectors.toList());
|
||||
waveforms.stream().filter(s -> s.getId()==1).forEach(s -> {
|
||||
assertEquals(27, s.getEvents().size());
|
||||
});
|
||||
waveforms.stream().filter(s -> s.getId()==1).map(s -> s.getEventsAtTime(0)).forEach(el -> {
|
||||
assertEquals(1, el.length);
|
||||
IEvent evt = el[0];
|
||||
assertTrue(evt instanceof ITxEvent);
|
||||
ITx tx = ((ITxEvent)evt).getTransaction();
|
||||
assertNotNull(tx);
|
||||
assertEquals(0, tx.getBeginTime());
|
||||
assertEquals(280000000, tx.getEndTime());
|
||||
List<ITxAttribute> attr = tx.getAttributes();
|
||||
assertEquals(3, attr.size());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue