private static boolean[] dumpToStream(Ruby runtime, IRubyObject object, OutputStream rawOutput, int depthLimit) throws IOException { MarshalStream output = new MarshalStream(runtime, rawOutput, depthLimit); output.dumpObject(object); return new boolean[] {output.isTainted(), output.isUntrusted()}; } }
public void dumpDefaultObjectHeader(RubyClass type) throws IOException { dumpDefaultObjectHeader('o',type); }
public void dumpDefaultObjectHeader(char tp, RubyClass type) throws IOException { dumpExtended(type); write(tp); writeAndRegisterSymbol(getPathFromClass(type.getRealClass())); }
public void writeDirectly(IRubyObject value) throws IOException { List<Variable<Object>> variables = getVariables(value); writeObjectData(value); if (variables != null) { dumpVariablesWithEncoding(variables, value); } }
private static boolean dumpToStream(Ruby runtime, IRubyObject object, OutputStream rawOutput, int depthLimit) throws IOException { MarshalStream output = new MarshalStream(runtime, rawOutput, depthLimit); output.dumpObject(object); return output.isTainted(); }
write('['); RubyArray.marshalTo((RubyArray)value, this); return; case FALSE: write('F'); return; case FIXNUM: RubyFixnum fixnum = (RubyFixnum)value; if (isMarshalFixnum(fixnum)) { write('i'); writeInt((int) fixnum.getLongValue()); return; write('l'); RubyBignum.marshalTo((RubyBignum)value, this); return; case CLASS: if (((RubyClass)value).isSingleton()) throw runtime.newTypeError("singleton class can't be dumped"); write('c'); RubyClass.marshalTo((RubyClass)value, this); return; case FLOAT: write('f'); RubyFloat.marshalTo((RubyFloat)value, this); return; write('{'); } else if (hash.hasDefaultProc()) {
private void userCommon(IRubyObject value, DynamicMethod method) throws IOException { RubyFixnum depthLimitFixnum = runtime.newFixnum(depthLimit); IRubyObject dumpResult; if (method != null) { dumpResult = method.call(runtime.getCurrentContext(), value, value.getMetaClass(), "_dump", depthLimitFixnum); } else { dumpResult = value.callMethod(runtime.getCurrentContext(), "_dump", depthLimitFixnum); } if (!(dumpResult instanceof RubyString)) { throw runtime.newTypeError(dumpResult, runtime.getString()); } RubyString marshaled = (RubyString)dumpResult; boolean hasVars; if (hasVars = marshaled.hasVariables()) { write(TYPE_IVAR); } write(TYPE_USERDEF); RubyClass metaclass = value.getMetaClass().getRealClass(); writeAndRegisterSymbol(metaclass.getName()); writeString(marshaled.getByteList()); if (hasVars) { dumpVariables(marshaled.getVariableList()); } registerLinkTarget(value); }
public static void marshalTo(RubyArray array, MarshalStream output) throws IOException { output.registerLinkTarget(array); int length = array.realLength; int begin = array.begin; IRubyObject[] ary = array.values; output.writeInt(length); try { for (int i = 0; i < length; i++) { output.dumpObject(ary[i + begin]); } } catch (ArrayIndexOutOfBoundsException aioob) { concurrentModification(array.getRuntime()); } }
public static void marshalTo(RubyStruct struct, MarshalStream output) throws java.io.IOException { output.registerLinkTarget(struct); output.dumpDefaultObjectHeader('S', struct.getMetaClass()); RubyArray member = __member__(struct.classOf()); output.writeInt(member.size()); for (int i = 0; i < member.size(); i++) { RubySymbol name = (RubySymbol) member.eltInternal(i); output.dumpObject(name); output.dumpObject(struct.values[i]); } }
private void userNewCommon(IRubyObject value, DynamicMethod method) throws IOException { registerLinkTarget(value); write(TYPE_USRMARSHAL); RubyClass metaclass = value.getMetaClass().getRealClass(); writeAndRegisterSymbol(metaclass.getName()); IRubyObject marshaled; if (method != null) { marshaled = method.call(runtime.getCurrentContext(), value, value.getMetaClass(), "marshal_dump"); } else { marshaled = value.callMethod(runtime.getCurrentContext(), "marshal_dump"); } dumpObject(marshaled); }
public static void marshalTo(RubyClass clazz, MarshalStream output) throws java.io.IOException { output.registerLinkTarget(clazz); output.writeString(MarshalStream.getPathFromClass(clazz)); }
@Override public void marshalTo(Ruby runtime, Object obj, RubyClass type, MarshalStream marshalStream) throws IOException { IRubyObject object = (IRubyObject)obj; marshalStream.registerLinkTarget(object); marshalStream.dumpVariables(object.getVariableList()); }
public void dumpVariablesWithEncoding(List<Variable<Object>> vars, IRubyObject obj) throws IOException { if (shouldMarshalEncoding(obj)) { writeInt(vars.size() + 1); // vars preceded by encoding writeEncoding(((MarshalEncoding)obj).getMarshalEncoding()); } else { writeInt(vars.size()); } dumpVariablesShared(vars); }
if (shouldMarshalEncoding(value) || ( !value.isImmediate() && value.hasVariables() if (variables.size() > 0 || shouldMarshalEncoding(value)) { write(TYPE_IVAR); } else { case ARRAY: case HASH: type = dumpExtended(meta); break; nativeClassIndex != ClassIndex.BIGNUM) { writeUserClass(value, type);
public void writeDirectly(IRubyObject value) throws IOException { List<Variable<Object>> variables = getVariables(value); writeObjectData(value); if (variables != null) { if (runtime.is1_9()) { dumpVariablesWithEncoding(variables, value); } else { dumpVariables(variables); } } }
private void dumpVariablesShared(List<Variable<Object>> vars) throws IOException { for (Variable<Object> var : vars) { if (var.getValue() instanceof IRubyObject) { writeAndRegisterSymbol(var.getName()); dumpObject((IRubyObject)var.getValue()); } } }
private void writeAndRegisterSymbol(ByteList sym) throws IOException { if (cache.isSymbolRegistered(sym)) { cache.writeSymbolLink(this, sym); } else { registerSymbol(sym); dumpSymbol(sym); } }
public void dumpVariables(List<Variable<Object>> vars) throws IOException { writeInt(vars.size()); dumpVariablesShared(vars); }
public CachedData encode(Object o) { if (o instanceof IRubyObject) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MarshalStream marshal = new MarshalStream(ruby, baos, Integer.MAX_VALUE); marshal.dumpObject((IRubyObject) o); byte[] bytes = baos.toByteArray(); return new CachedData(getFlags(), bytes, bytes.length); } catch (IOException e) { throw ruby.newIOErrorFromException(e); } } else { return encodeNumber(o); } }
@Override public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, MarshalStream output) { try { output.dumpObject(key); output.dumpObject(value); } catch (IOException e) { throw new VisitorIOException(e); } } };