@Override public Void visit(BsonArray value, ByteBuf arg) { final int docStart = arg.writerIndex(); arg.writeInt(0); // reserve space for doc size int i = 0; for (BsonValue<?> child : value) { try { arg.writeByte(ParsingTools.getByte(child.getType())); } catch (NettyBsonReaderException ex) { throw new AssertionError(ex); } writeCString(arg, Integer.toString(i)); child.accept(this, arg); i++; } arg.writeByte(0x00); int docEnd = arg.writerIndex(); arg.writerIndex(docStart).writeInt(docEnd - docStart).writerIndex(docEnd); return null; }
@Override public Void visit(BsonJavaScriptWithScope value, ByteBuf arg) { final int codeWsStart = arg.writerIndex(); arg.writeInt(0); // reserve space for code_w_s size writeString(arg, value.getJavaScript()); value.getScope().accept(VISITOR, arg); final int codeWsEnds = arg.writerIndex(); arg.writerIndex(codeWsStart).writeInt(codeWsEnds - codeWsStart).writerIndex(codeWsEnds); return null; }
@Override public Void visit(BsonDocument value, ByteBuf arg) { final int docStart = arg.writerIndex(); arg.writeInt(0); // reserve space for doc size for (Entry<?> entry : value) { BsonValue<?> child = entry.getValue(); try { arg.writeByte(ParsingTools.getByte(child.getType())); } catch (NettyBsonReaderException ex) { throw new AssertionError(ex); } writeCString(arg, entry.getKey()); child.accept(this, arg); } arg.writeByte(0x00); int docEnd = arg.writerIndex(); arg.writerIndex(docStart).writeInt(docEnd - docStart).writerIndex(docEnd); return null; }
@Override public Void visit(BsonRegex value, ByteBuf arg) { writeCString(arg, value.getPattern()); writeCString(arg, value.getOptionsAsText()); return null; }
@Override public Void visit(BsonJavaScript value, ByteBuf arg) { writeString(arg, value.getValue()); return null; }
@Override public Void visit(BsonDeprecated value, ByteBuf arg) { writeString(arg, value.getValue()); return null; }
@Override public Void visit(BsonString value, ByteBuf arg) { writeString(arg, value.getValue()); return null; }
@Override public Void visit(BsonDbPointer value, ByteBuf arg) { writeString(arg, value.getNamespace()); value.getId().accept(this, arg); return null; }