Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

introduced duplicatable V2XMessage functionality #390

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 Fraunhofer FOKUS and others. All rights reserved.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contact: [email protected]
*/

package org.eclipse.mosaic.lib.objects;
schwepmo marked this conversation as resolved.
Show resolved Hide resolved

import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;

/**
* Creates a copy of the message
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
* @param <MessageT>
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
*/
public interface DuplicatableMessage<T extends DuplicatableMessage<T>> {
schwepmo marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a copy of the V2xMessage.
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
* The message gets a new ID and routing (to use current vehicle position).
* Only its contents (e.g. payload, type, ...) are copied.
*
* @param routing contains current vehicle position
* @return cloned message
*/
T duplicate(MessageRouting routing);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.eclipse.mosaic.lib.objects.v2x;

import org.eclipse.mosaic.lib.objects.DuplicatableMessage;
import org.eclipse.mosaic.lib.objects.ToDataOutput;
import org.eclipse.mosaic.lib.util.ClassUtils;

Expand All @@ -23,7 +24,7 @@
/**
* This {@link V2xMessage} implementation can be used for simple message exchange between entities.
*/
public final class GenericV2xMessage extends V2xMessage {
public final class GenericV2xMessage extends V2xMessage implements DuplicatableMessage {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -63,6 +64,12 @@ public GenericV2xMessage(MessageRouting routing, ToDataOutput messagePayload, lo
this.payload = new EncodedPayload(messagePayload, minimalMessageSize);
}

public GenericV2xMessage(GenericV2xMessage message) {
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
super(message.getRouting());
this.messageType = message.getMessageType();
this.payload = message.getPayload();
}


@Override
@Nonnull
Expand All @@ -82,4 +89,8 @@ public String toString() {
+ ", encodedPayload=" + payload + '}';
}

public GenericV2xMessage duplicate(MessageRouting routing) {
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
return new GenericV2xMessage(routing, messageType, payload.getEffectiveLength());
}

}
Loading