Skip to content
Snippets Groups Projects
Commit c6358457 authored by Mick Jordan's avatar Mick Jordan
Browse files

allow connection serialization

parent 9ee07b5e
No related branches found
No related tags found
No related merge requests found
......@@ -727,7 +727,9 @@ public class RSerialize {
/**
* GnuR uses a pairlist to represent attributes, whereas FastR uses the abstract RAttributes
* class. FastR also uses different types to represent data/frame and factor which is
* handled in the setClassAttr
* handled in the setClassAttr. N.B. In theory connections can be unserialized but they are
* unusable, so we don't go to the trouble of converting the {@link RIntVector}
* representation into an {@link RConnection}.
*/
private static Object setAttributes(final Object object, Object attr) {
RAttributable rAttributable = (RAttributable) object;
......@@ -738,7 +740,8 @@ public class RSerialize {
String tag = tagSym.getName().intern();
// this may convert a plain vector to a data.frame or factor
if (result instanceof RVector && tag.equals(RRuntime.CLASS_ATTR_KEY)) {
result = ((RVector) result).setClassAttr((RStringVector) pl.car(), false);
RStringVector classes = (RStringVector) pl.car();
result = ((RVector) result).setClassAttr(classes, false);
} else {
rAttributable.setAttr(tag, pl.car());
}
......@@ -1198,6 +1201,8 @@ public class RSerialize {
case FASTR_DATAFRAME:
case FASTR_FACTOR:
return SEXPTYPE.VECSXP;
case FASTR_CONNECTION:
return SEXPTYPE.INTSXP;
default:
return type;
}
......@@ -1262,10 +1267,6 @@ public class RSerialize {
RFactor factor = (RFactor) obj;
writeItem(factor.getVector());
return;
} else if (type == SEXPTYPE.FASTR_SOCKET_CONN || type == SEXPTYPE.FASTR_FILE_CONN) {
// serializing a socket or file connection is not meaningful
writeItem(RDataFactory.createIntVectorFromScalar(RRuntime.INT_NA));
return;
} else {
// flags
RAttributes attributes = null;
......@@ -1391,6 +1392,14 @@ public class RSerialize {
break;
}
case EXTPTRSXP: {
addReadRef(obj);
RExternalPtr xptr = (RExternalPtr) obj;
writeItem(RNull.instance);
writeItem(RDataFactory.createSymbol(xptr.tag));
break;
}
/*
* FastR scalar, (length 1) "vectors"
*/
......@@ -1428,6 +1437,13 @@ public class RSerialize {
break;
}
case FASTR_CONNECTION: {
RConnection con = (RConnection) obj;
stream.writeInt(1);
stream.writeInt(con.getDescriptor());
break;
}
case LANGSXP: {
RPairList pl = (RPairList) RContext.getRRuntimeASTAccess().serialize(state, obj);
writeItem(pl.car());
......
......@@ -412,6 +412,8 @@ public class ConnectionSupport implements RContext.StateFactory {
classes[0] = conClass.printName;
classes[1] = "connection";
getAttributes().put(RRuntime.CLASS_ATTR_KEY, RDataFactory.createStringVector(classes, RDataFactory.COMPLETE_VECTOR));
// For GnuR compatibility we define the "conn_id" attribute
getAttributes().put("conn_id", RDataFactory.createExternalPtr(0, "connection"));
}
protected void openNonLazyConnection() throws IOException {
......
......@@ -43,7 +43,7 @@ public enum SEXPTYPE {
VECSXP(19, RList.class), /* generic vectors */
EXPRSXP(20, RExpression.class), /* expressions vectors */
BCODESXP(21), /* byte code */
EXTPTRSXP(22), /* external pointer */
EXTPTRSXP(22, RExternalPtr.class), /* external pointer */
WEAKREFSXP(23), /* weak reference */
RAWSXP(24, RRawVector.class), /* raw bytes */
S4SXP(25), /* S4 non-vector */
......@@ -83,10 +83,7 @@ public enum SEXPTYPE {
FASTR_FACTOR(305, RFactor.class),
// very special case
FASTR_SOURCESECTION(306, SourceSection.class),
// Other FastR internals
FASTR_SOCKET_CONN(400, SocketConnections.RSocketConnection.class),
FASTR_FILE_CONN(401, FileConnections.FileRConnection.class),
FASTR_CONNECTION(307, RConnection.class),
EMPTYARG_SXP(500, REmpty.class);
......@@ -133,9 +130,11 @@ public enum SEXPTYPE {
}
}
}
// (only) environments have subtypes
// (only) environments and connections have subtypes
if (REnvironment.class.isAssignableFrom(fastRClass)) {
return ENVSXP;
} else if (RConnection.class.isAssignableFrom(fastRClass)) {
return FASTR_CONNECTION;
}
throw RInternalError.shouldNotReachHere(fastRClass.getName());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment