@Override public CodeWithScope decode(final BsonReader bsonReader, final DecoderContext decoderContext) { String code = bsonReader.readJavaScriptWithScope(); Document scope = documentCodec.decode(bsonReader, decoderContext); return new CodeWithScope(code, scope); }
private void pickleCode(final Code code, final OutputStream out, final Pickler pickler) throws IOException { out.write(Opcodes.GLOBAL); out.write("bson.code\nCode\n".getBytes()); pickler.save(code.getCode()); out.write(Opcodes.TUPLE1); out.write(Opcodes.NEWOBJ); // PyMongo's bson.code.Code always has a scope, even it if is empty. out.write(Opcodes.EMPTY_DICT); putBinstring("_Code__scope", out); if (code instanceof CodeWithScope) { pickler.save(((CodeWithScope) code).getScope()); } else if (code instanceof CodeWScope) { pickler.save(((CodeWScope) code).getScope().toMap()); } else { out.write(Opcodes.EMPTY_DICT); } out.write(Opcodes.SETITEM); out.write(Opcodes.BUILD); }
@Override public int hashCode() { return getCode().hashCode() ^ scope.hashCode(); } }