private void write(BufferPacker packer, IRubyObject o) throws IOException {
if (o == null || o instanceof RubyNil) {
packer.writeNil();
} else if (o instanceof RubyBoolean) {
packer.write(((RubyBoolean) o).isTrue());
} else if (o instanceof RubyBignum) {
write(packer, (RubyBignum) o);
} else if (o instanceof RubyInteger) {
write(packer, (RubyInteger) o);
} else if (o instanceof RubyFixnum) {
write(packer, (RubyFixnum) o);
} else if (o instanceof RubyFloat) {
write(packer, (RubyFloat) o);
} else if (o instanceof RubyString) {
write(packer, (RubyString) o);
} else if (o instanceof RubySymbol) {
write(packer, (RubySymbol) o);
} else if (o instanceof RubyArray) {
write(packer, (RubyArray) o);
} else if (o instanceof RubyHash) {
write(packer, (RubyHash) o);
} else if (o instanceof RubyDate) {
write(packer, (RubyDate) o);
}
else {
throw o.getRuntime().newArgumentError(String.format("Cannot pack type: %s", o.getClass().getName()));
}
}