Changeset 341:b801209d84fc in finroc_core-java


Ignore:
Timestamp:
07.05.2020 15:19:01 (3 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
default
Phase:
public
Message:

Fixes serializing data to network stream: uses serialization of port data type also when buffer with subclass has been published to port

File:
1 edited

Legend:

Unmodified
Added
Removed
  • remote/RemoteType.java

    r335 r341  
    3030import org.rrlib.serialization.Register; 
    3131import org.rrlib.serialization.Serialization; 
     32import org.rrlib.serialization.rtti.Copyable; 
    3233import org.rrlib.serialization.rtti.DataTypeBase; 
    3334import org.rrlib.serialization.rtti.GenericObject; 
     
    416417     * @param object Object containing data to adapt and serialize 
    417418     */ 
     419    @SuppressWarnings({ "rawtypes", "unchecked" }) 
    418420    public void serializeData(BinaryOutputStream stream, GenericObject object) throws Exception { 
    419421        switch (localTypeMatch) { 
     
    430432            break; 
    431433        default: 
    432             object.serialize(stream, getEncodingForDefaultLocalType()); 
     434            if (localDataType != object.getType() && localDataType.getJavaClass() != null && Copyable.class.isAssignableFrom(localDataType.getJavaClass()) && object.getType() != null && localDataType.getJavaClass().isAssignableFrom(object.getType().getJavaClass())) { 
     435                GenericObject tempObject = localDataType.createInstanceGeneric(null); 
     436                ((Copyable)tempObject.getData()).copyFrom(object.getData()); 
     437                tempObject.serialize(stream, getEncodingForDefaultLocalType()); 
     438            } else { 
     439                object.serialize(stream, getEncodingForDefaultLocalType()); 
     440            } 
    433441            break; 
    434442        } 
Note: See TracChangeset for help on using the changeset viewer.