@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(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; }