# File lib/bson/bson_ruby.rb, line 425
    def serialize_binary_element(buf, key, val)
      buf.put(BINARY)
      self.class.serialize_key(buf, key)

      bytes = val.to_a
      num_bytes = bytes.length
      subtype = val.respond_to?(:subtype) ? val.subtype : Binary::SUBTYPE_BYTES
      if subtype == Binary::SUBTYPE_BYTES
        buf.put_int(num_bytes + 4)
        buf.put(subtype)
        buf.put_int(num_bytes)
        buf.put_array(bytes)
      else
        buf.put_int(num_bytes)
        buf.put(subtype)
        buf.put_array(bytes)
      end
    end